summaryrefslogtreecommitdiff
path: root/libc/nptl
diff options
context:
space:
mode:
authorgcc <gcc@7b3dc134-2b1b-0410-93df-9e9f96275f8d>2006-08-17 01:18:26 +0000
committergcc <gcc@7b3dc134-2b1b-0410-93df-9e9f96275f8d>2006-08-17 01:18:26 +0000
commit15f34685e7a9b5caf761af2ebf6afa20438d440b (patch)
treedc04ce3cdf040f198743c15b64557824de174680 /libc/nptl
parent1e848e0e775a36f6359161f5deb890942ef42ff3 (diff)
downloadeglibc2-15f34685e7a9b5caf761af2ebf6afa20438d440b.tar.gz
Import glibc-mainline for 2006-08-16
git-svn-id: svn://svn.eglibc.org/fsf/trunk@4 7b3dc134-2b1b-0410-93df-9e9f96275f8d
Diffstat (limited to 'libc/nptl')
-rw-r--r--libc/nptl/ANNOUNCE92
-rw-r--r--libc/nptl/Banner1
-rw-r--r--libc/nptl/ChangeLog8284
-rw-r--r--libc/nptl/DESIGN-barrier.txt44
-rw-r--r--libc/nptl/DESIGN-condvar.txt134
-rw-r--r--libc/nptl/DESIGN-rwlock.txt113
-rw-r--r--libc/nptl/DESIGN-sem.txt46
-rw-r--r--libc/nptl/Makeconfig30
-rw-r--r--libc/nptl/Makefile620
-rw-r--r--libc/nptl/TODO16
-rw-r--r--libc/nptl/TODO-kernel20
-rw-r--r--libc/nptl/TODO-testing20
-rw-r--r--libc/nptl/Versions248
-rw-r--r--libc/nptl/alloca_cutoff.c36
-rw-r--r--libc/nptl/allocatestack.c970
-rw-r--r--libc/nptl/cancellation.c90
-rw-r--r--libc/nptl/cleanup.c49
-rw-r--r--libc/nptl/cleanup_compat.c55
-rw-r--r--libc/nptl/cleanup_defer.c92
-rw-r--r--libc/nptl/cleanup_defer_compat.c98
-rw-r--r--libc/nptl/cleanup_routine.c28
-rw-r--r--libc/nptl/cond-perf.c103
-rw-r--r--libc/nptl/configure13
-rw-r--r--libc/nptl/descr.h368
-rw-r--r--libc/nptl/eintr.c89
-rw-r--r--libc/nptl/errno-loc.c1
-rw-r--r--libc/nptl/events.c34
-rw-r--r--libc/nptl/forward.c203
-rw-r--r--libc/nptl/herrno.c35
-rw-r--r--libc/nptl/init.c398
-rw-r--r--libc/nptl/libc-cancellation.c116
-rw-r--r--libc/nptl/lowlevellock.h90
-rw-r--r--libc/nptl/old_pthread_atfork.c27
-rw-r--r--libc/nptl/old_pthread_cond_broadcast.c58
-rw-r--r--libc/nptl/old_pthread_cond_destroy.c37
-rw-r--r--libc/nptl/old_pthread_cond_init.c47
-rw-r--r--libc/nptl/old_pthread_cond_signal.c58
-rw-r--r--libc/nptl/old_pthread_cond_timedwait.c60
-rw-r--r--libc/nptl/old_pthread_cond_wait.c59
-rw-r--r--libc/nptl/perf.c760
-rw-r--r--libc/nptl/pt-allocrtsig.c51
-rw-r--r--libc/nptl/pt-cleanup.c63
-rw-r--r--libc/nptl/pt-raise.c31
-rw-r--r--libc/nptl/pt-system.c33
-rw-r--r--libc/nptl/pthread-errnos.sym12
-rw-r--r--libc/nptl/pthreadP.h563
-rw-r--r--libc/nptl/pthread_atfork.c64
-rw-r--r--libc/nptl/pthread_attr_destroy.c46
-rw-r--r--libc/nptl/pthread_attr_getdetachstate.c39
-rw-r--r--libc/nptl/pthread_attr_getguardsize.c37
-rw-r--r--libc/nptl/pthread_attr_getinheritsched.c40
-rw-r--r--libc/nptl/pthread_attr_getschedparam.c40
-rw-r--r--libc/nptl/pthread_attr_getschedpolicy.c39
-rw-r--r--libc/nptl/pthread_attr_getscope.c40
-rw-r--r--libc/nptl/pthread_attr_getstack.c41
-rw-r--r--libc/nptl/pthread_attr_getstackaddr.c45
-rw-r--r--libc/nptl/pthread_attr_getstacksize.c40
-rw-r--r--libc/nptl/pthread_attr_init.c88
-rw-r--r--libc/nptl/pthread_attr_setdetachstate.c48
-rw-r--r--libc/nptl/pthread_attr_setguardsize.c40
-rw-r--r--libc/nptl/pthread_attr_setinheritsched.c47
-rw-r--r--libc/nptl/pthread_attr_setschedparam.c42
-rw-r--r--libc/nptl/pthread_attr_setschedpolicy.c47
-rw-r--r--libc/nptl/pthread_attr_setscope.c51
-rw-r--r--libc/nptl/pthread_attr_setstack.c89
-rw-r--r--libc/nptl/pthread_attr_setstackaddr.c47
-rw-r--r--libc/nptl/pthread_attr_setstacksize.c75
-rw-r--r--libc/nptl/pthread_barrier_destroy.c44
-rw-r--r--libc/nptl/pthread_barrier_init.c57
-rw-r--r--libc/nptl/pthread_barrierattr_destroy.c30
-rw-r--r--libc/nptl/pthread_barrierattr_getpshared.c31
-rw-r--r--libc/nptl/pthread_barrierattr_init.c30
-rw-r--r--libc/nptl/pthread_barrierattr_setpshared.c40
-rw-r--r--libc/nptl/pthread_cancel.c104
-rw-r--r--libc/nptl/pthread_clock_gettime.c69
-rw-r--r--libc/nptl/pthread_clock_settime.c56
-rw-r--r--libc/nptl/pthread_cond_destroy.c81
-rw-r--r--libc/nptl/pthread_cond_init.c46
-rw-r--r--libc/nptl/pthread_condattr_destroy.c30
-rw-r--r--libc/nptl/pthread_condattr_getclock.c31
-rw-r--r--libc/nptl/pthread_condattr_getpshared.c31
-rw-r--r--libc/nptl/pthread_condattr_init.c32
-rw-r--r--libc/nptl/pthread_condattr_setclock.c72
-rw-r--r--libc/nptl/pthread_condattr_setpshared.c37
-rw-r--r--libc/nptl/pthread_create.c594
-rw-r--r--libc/nptl/pthread_detach.c57
-rw-r--r--libc/nptl/pthread_equal.c30
-rw-r--r--libc/nptl/pthread_exit.c32
-rw-r--r--libc/nptl/pthread_getattr_np.c181
-rw-r--r--libc/nptl/pthread_getconcurrency.c27
-rw-r--r--libc/nptl/pthread_getschedparam.c81
-rw-r--r--libc/nptl/pthread_getspecific.c69
-rw-r--r--libc/nptl/pthread_join.c114
-rw-r--r--libc/nptl/pthread_key_create.c54
-rw-r--r--libc/nptl/pthread_key_delete.c43
-rw-r--r--libc/nptl/pthread_kill_other_threads.c37
-rw-r--r--libc/nptl/pthread_mutex_consistent.c36
-rw-r--r--libc/nptl/pthread_mutex_destroy.c38
-rw-r--r--libc/nptl/pthread_mutex_getprioceiling.c38
-rw-r--r--libc/nptl/pthread_mutex_init.c133
-rw-r--r--libc/nptl/pthread_mutex_lock.c438
-rw-r--r--libc/nptl/pthread_mutex_setprioceiling.c116
-rw-r--r--libc/nptl/pthread_mutex_timedlock.c470
-rw-r--r--libc/nptl/pthread_mutex_trylock.c380
-rw-r--r--libc/nptl/pthread_mutex_unlock.c264
-rw-r--r--libc/nptl/pthread_mutexattr_destroy.c29
-rw-r--r--libc/nptl/pthread_mutexattr_getprioceiling.c48
-rw-r--r--libc/nptl/pthread_mutexattr_getprotocol.c37
-rw-r--r--libc/nptl/pthread_mutexattr_getpshared.c36
-rw-r--r--libc/nptl/pthread_mutexattr_getrobust.c36
-rw-r--r--libc/nptl/pthread_mutexattr_gettype.c36
-rw-r--r--libc/nptl/pthread_mutexattr_init.c38
-rw-r--r--libc/nptl/pthread_mutexattr_setprioceiling.c47
-rw-r--r--libc/nptl/pthread_mutexattr_setprotocol.c41
-rw-r--r--libc/nptl/pthread_mutexattr_setpshared.c43
-rw-r--r--libc/nptl/pthread_mutexattr_setrobust.c43
-rw-r--r--libc/nptl/pthread_mutexattr_settype.c41
-rw-r--r--libc/nptl/pthread_rwlock_destroy.c30
-rw-r--r--libc/nptl/pthread_rwlock_init.c51
-rw-r--r--libc/nptl/pthread_rwlock_tryrdlock.c50
-rw-r--r--libc/nptl/pthread_rwlock_trywrlock.c43
-rw-r--r--libc/nptl/pthread_rwlockattr_destroy.c30
-rw-r--r--libc/nptl/pthread_rwlockattr_getkind_np.c31
-rw-r--r--libc/nptl/pthread_rwlockattr_getpshared.c31
-rw-r--r--libc/nptl/pthread_rwlockattr_init.c35
-rw-r--r--libc/nptl/pthread_rwlockattr_setkind_np.c41
-rw-r--r--libc/nptl/pthread_rwlockattr_setpshared.c40
-rw-r--r--libc/nptl/pthread_self.c29
-rw-r--r--libc/nptl/pthread_setcancelstate.c73
-rw-r--r--libc/nptl/pthread_setcanceltype.c76
-rw-r--r--libc/nptl/pthread_setconcurrency.c41
-rw-r--r--libc/nptl/pthread_setegid.c3
-rw-r--r--libc/nptl/pthread_seteuid.c3
-rw-r--r--libc/nptl/pthread_setgid.c3
-rw-r--r--libc/nptl/pthread_setregid.c3
-rw-r--r--libc/nptl/pthread_setresgid.c3
-rw-r--r--libc/nptl/pthread_setresuid.c3
-rw-r--r--libc/nptl/pthread_setreuid.c3
-rw-r--r--libc/nptl/pthread_setschedparam.c80
-rw-r--r--libc/nptl/pthread_setschedprio.c72
-rw-r--r--libc/nptl/pthread_setspecific.c96
-rw-r--r--libc/nptl/pthread_setuid.c3
-rw-r--r--libc/nptl/pthread_testcancel.c28
-rw-r--r--libc/nptl/pthread_timedjoin.c107
-rw-r--r--libc/nptl/pthread_tryjoin.c75
-rw-r--r--libc/nptl/res.c27
-rw-r--r--libc/nptl/sem_close.c81
-rw-r--r--libc/nptl/sem_destroy.c38
-rw-r--r--libc/nptl/sem_getvalue.c42
-rw-r--r--libc/nptl/sem_init.c55
-rw-r--r--libc/nptl/sem_open.c404
-rw-r--r--libc/nptl/sem_unlink.c67
-rw-r--r--libc/nptl/semaphore.h79
-rw-r--r--libc/nptl/semaphoreP.h67
-rw-r--r--libc/nptl/shlib-versions10
-rw-r--r--libc/nptl/sigaction.c47
-rw-r--r--libc/nptl/sockperf.c594
-rw-r--r--libc/nptl/sysdeps/alpha/Makefile21
-rw-r--r--libc/nptl/sysdeps/alpha/elf/pt-initfini.c89
-rw-r--r--libc/nptl/sysdeps/alpha/pthread_spin_lock.S45
-rw-r--r--libc/nptl/sysdeps/alpha/pthread_spin_trylock.S46
-rw-r--r--libc/nptl/sysdeps/alpha/pthreaddef.h38
-rw-r--r--libc/nptl/sysdeps/alpha/tcb-offsets.sym14
-rw-r--r--libc/nptl/sysdeps/alpha/tls.h129
-rw-r--r--libc/nptl/sysdeps/i386/Makefile27
-rw-r--r--libc/nptl/sysdeps/i386/i486/pthread_spin_trylock.S47
-rw-r--r--libc/nptl/sysdeps/i386/i586/pthread_spin_trylock.S20
-rw-r--r--libc/nptl/sysdeps/i386/i686/Makefile32
-rw-r--r--libc/nptl/sysdeps/i386/i686/pthread_spin_trylock.S21
-rw-r--r--libc/nptl/sysdeps/i386/i686/tls.h36
-rw-r--r--libc/nptl/sysdeps/i386/pthread_spin_init.c20
-rw-r--r--libc/nptl/sysdeps/i386/pthread_spin_lock.c49
-rw-r--r--libc/nptl/sysdeps/i386/pthread_spin_unlock.S32
-rw-r--r--libc/nptl/sysdeps/i386/pthreaddef.h48
-rw-r--r--libc/nptl/sysdeps/i386/tcb-offsets.sym14
-rw-r--r--libc/nptl/sysdeps/i386/tls.h439
-rw-r--r--libc/nptl/sysdeps/ia64/Makefile25
-rw-r--r--libc/nptl/sysdeps/ia64/pthread_spin_lock.c36
-rw-r--r--libc/nptl/sysdeps/ia64/pthread_spin_trylock.c28
-rw-r--r--libc/nptl/sysdeps/ia64/pthread_spin_unlock.c28
-rw-r--r--libc/nptl/sysdeps/ia64/pthreaddef.h43
-rw-r--r--libc/nptl/sysdeps/ia64/tcb-offsets.sym7
-rw-r--r--libc/nptl/sysdeps/ia64/tls.h171
-rw-r--r--libc/nptl/sysdeps/powerpc/Makefile21
-rw-r--r--libc/nptl/sysdeps/powerpc/pthread_spin_lock.c45
-rw-r--r--libc/nptl/sysdeps/powerpc/pthread_spin_trylock.c43
-rw-r--r--libc/nptl/sysdeps/powerpc/pthreaddef.h41
-rw-r--r--libc/nptl/sysdeps/powerpc/tcb-offsets.sym17
-rw-r--r--libc/nptl/sysdeps/powerpc/tls.h188
-rw-r--r--libc/nptl/sysdeps/pthread/Makefile50
-rw-r--r--libc/nptl/sysdeps/pthread/Subdirs2
-rw-r--r--libc/nptl/sysdeps/pthread/aio_misc.h74
-rw-r--r--libc/nptl/sysdeps/pthread/allocalim.h30
-rw-r--r--libc/nptl/sysdeps/pthread/bits/libc-lock.h568
-rw-r--r--libc/nptl/sysdeps/pthread/bits/sigthread.h38
-rw-r--r--libc/nptl/sysdeps/pthread/bits/stdio-lock.h105
-rwxr-xr-xlibc/nptl/sysdeps/pthread/configure159
-rw-r--r--libc/nptl/sysdeps/pthread/configure.in49
-rw-r--r--libc/nptl/sysdeps/pthread/createthread.c255
-rw-r--r--libc/nptl/sysdeps/pthread/flockfile.c33
-rw-r--r--libc/nptl/sysdeps/pthread/ftrylockfile.c33
-rw-r--r--libc/nptl/sysdeps/pthread/funlockfile.c33
-rw-r--r--libc/nptl/sysdeps/pthread/gai_misc.h119
-rw-r--r--libc/nptl/sysdeps/pthread/librt-cancellation.c108
-rw-r--r--libc/nptl/sysdeps/pthread/list.h114
-rw-r--r--libc/nptl/sysdeps/pthread/malloc-machine.h62
-rw-r--r--libc/nptl/sysdeps/pthread/posix-timer.h197
-rw-r--r--libc/nptl/sysdeps/pthread/pt-initfini.c125
-rw-r--r--libc/nptl/sysdeps/pthread/pt-longjmp.c29
-rw-r--r--libc/nptl/sysdeps/pthread/pthread-functions.h103
-rw-r--r--libc/nptl/sysdeps/pthread/pthread.h1115
-rw-r--r--libc/nptl/sysdeps/pthread/pthread_barrier_wait.c77
-rw-r--r--libc/nptl/sysdeps/pthread/pthread_cond_broadcast.c86
-rw-r--r--libc/nptl/sysdeps/pthread/pthread_cond_signal.c61
-rw-r--r--libc/nptl/sysdeps/pthread/pthread_cond_timedwait.c214
-rw-r--r--libc/nptl/sysdeps/pthread/pthread_cond_wait.c185
-rw-r--r--libc/nptl/sysdeps/pthread/pthread_getcpuclockid.c57
-rw-r--r--libc/nptl/sysdeps/pthread/pthread_once.c54
-rw-r--r--libc/nptl/sysdeps/pthread/pthread_rwlock_rdlock.c95
-rw-r--r--libc/nptl/sysdeps/pthread/pthread_rwlock_timedrdlock.c137
-rw-r--r--libc/nptl/sysdeps/pthread/pthread_rwlock_timedwrlock.c127
-rw-r--r--libc/nptl/sysdeps/pthread/pthread_rwlock_unlock.c57
-rw-r--r--libc/nptl/sysdeps/pthread/pthread_rwlock_wrlock.c87
-rw-r--r--libc/nptl/sysdeps/pthread/pthread_sigmask.c58
-rw-r--r--libc/nptl/sysdeps/pthread/pthread_spin_destroy.c29
-rw-r--r--libc/nptl/sysdeps/pthread/pthread_spin_init.c28
-rw-r--r--libc/nptl/sysdeps/pthread/pthread_spin_unlock.c30
-rw-r--r--libc/nptl/sysdeps/pthread/rt-unwind-resume.c1
-rw-r--r--libc/nptl/sysdeps/pthread/setxid.h64
-rw-r--r--libc/nptl/sysdeps/pthread/sigfillset.c21
-rw-r--r--libc/nptl/sysdeps/pthread/sigprocmask.c20
-rw-r--r--libc/nptl/sysdeps/pthread/tcb-offsets.h1
-rw-r--r--libc/nptl/sysdeps/pthread/timer_create.c170
-rw-r--r--libc/nptl/sysdeps/pthread/timer_delete.c70
-rw-r--r--libc/nptl/sysdeps/pthread/timer_getoverr.c45
-rw-r--r--libc/nptl/sysdeps/pthread/timer_gettime.c77
-rw-r--r--libc/nptl/sysdeps/pthread/timer_routines.c578
-rw-r--r--libc/nptl/sysdeps/pthread/timer_settime.c137
-rw-r--r--libc/nptl/sysdeps/pthread/tst-mqueue8x.c1
-rw-r--r--libc/nptl/sysdeps/pthread/tst-timer.c159
-rw-r--r--libc/nptl/sysdeps/pthread/unwind-forcedunwind.c110
-rw-r--r--libc/nptl/sysdeps/pthread/unwind-resume.c64
-rw-r--r--libc/nptl/sysdeps/s390/Makefile25
-rw-r--r--libc/nptl/sysdeps/s390/pthread_spin_init.c20
-rw-r--r--libc/nptl/sysdeps/s390/pthread_spin_lock.c34
-rw-r--r--libc/nptl/sysdeps/s390/pthread_spin_trylock.c34
-rw-r--r--libc/nptl/sysdeps/s390/pthread_spin_unlock.c33
-rw-r--r--libc/nptl/sysdeps/s390/pthreaddef.h41
-rw-r--r--libc/nptl/sysdeps/s390/tcb-offsets.sym7
-rw-r--r--libc/nptl/sysdeps/s390/tls.h176
-rw-r--r--libc/nptl/sysdeps/sh/Makefile3
-rw-r--r--libc/nptl/sysdeps/sh/pthread_spin_init.c20
-rw-r--r--libc/nptl/sysdeps/sh/pthread_spin_lock.c35
-rw-r--r--libc/nptl/sysdeps/sh/pthread_spin_trylock.S32
-rw-r--r--libc/nptl/sysdeps/sh/pthread_spin_unlock.S30
-rw-r--r--libc/nptl/sysdeps/sh/pthreaddef.h49
-rw-r--r--libc/nptl/sysdeps/sh/tcb-offsets.sym12
-rw-r--r--libc/nptl/sysdeps/sh/tls.h158
-rw-r--r--libc/nptl/sysdeps/sparc/Makefile3
-rw-r--r--libc/nptl/sysdeps/sparc/sparc32/pthread_spin_lock.c40
-rw-r--r--libc/nptl/sysdeps/sparc/sparc32/pthread_spin_trylock.c29
-rw-r--r--libc/nptl/sysdeps/sparc/sparc32/pthreaddef.h40
-rw-r--r--libc/nptl/sysdeps/sparc/sparc32/sparcv9/pthread_spin_lock.c39
-rw-r--r--libc/nptl/sysdeps/sparc/sparc32/sparcv9/pthread_spin_trylock.c1
-rw-r--r--libc/nptl/sysdeps/sparc/sparc32/sparcv9/pthread_spin_unlock.c1
-rw-r--r--libc/nptl/sysdeps/sparc/sparc64/pthread_spin_lock.c39
-rw-r--r--libc/nptl/sysdeps/sparc/sparc64/pthread_spin_trylock.c34
-rw-r--r--libc/nptl/sysdeps/sparc/sparc64/pthread_spin_unlock.c30
-rw-r--r--libc/nptl/sysdeps/sparc/sparc64/pthreaddef.h40
-rw-r--r--libc/nptl/sysdeps/sparc/tcb-offsets.sym7
-rw-r--r--libc/nptl/sysdeps/sparc/tls.h149
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/Implies1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/Makefile38
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/Versions15
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/aio_misc.h69
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/allocrtsig.c56
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/alpha/Makefile2
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/alpha/Versions13
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/alpha/aio_cancel.c33
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/alpha/bits/local_lim.h89
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h168
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/alpha/bits/semaphore.h37
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/alpha/clone.S9
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/alpha/createthread.c23
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/alpha/fork.c30
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/alpha/lowlevellock.h296
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/alpha/pt-vfork.S43
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/alpha/pthread_once.c96
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/alpha/sem_post.c5
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h169
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/alpha/timer_create.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/alpha/timer_delete.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/alpha/timer_getoverr.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/alpha/timer_gettime.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/alpha/timer_settime.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/alpha/vfork.S46
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/bits/local_lim.h89
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/bits/posix_opt.h181
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/createthread.c24
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/fork.c213
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/fork.h57
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/getpid.c65
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h170
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/bits/semaphore.h39
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/clone.S9
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/createthread.c49
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/dl-sysdep.h64
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/fork.c31
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S30
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S285
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i486/lowlevelrobustlock.S188
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_barrier_wait.S163
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_broadcast.S169
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_signal.S137
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S637
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S523
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_rdlock.S175
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S215
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S208
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_unlock.S141
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_wrlock.S166
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_post.S102
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_timedwait.S195
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_trywait.S90
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_wait.S139
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i586/libc-lowlevellock.S1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i586/lowlevellock.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i586/lowlevelrobustlock.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_barrier_wait.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_broadcast.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_signal.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_timedwait.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_wait.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_rdlock.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_timedrdlock.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_timedwrlock.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_unlock.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_wrlock.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i586/sem_post.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i586/sem_timedwait.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i586/sem_trywait.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i586/sem_wait.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i686/dl-sysdep.h61
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i686/libc-lowlevellock.S1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i686/lowlevellock.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i686/lowlevelrobustlock.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_barrier_wait.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_broadcast.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_signal.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_timedwait.S21
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_wait.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_rdlock.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_timedrdlock.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_timedwrlock.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_unlock.S21
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_wrlock.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i686/sem_post.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i686/sem_timedwait.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i686/sem_trywait.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/i686/sem_wait.S20
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/lowlevellock.h512
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/not-cancel.h105
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/pt-vfork.S68
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/pthread_once.S182
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/pthread_spin_init.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/pthread_spin_unlock.S1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/smp.h56
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h139
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/i386/vfork.S45
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/Makefile3
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/Versions13
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/__ia64_longjmp.S159
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/__sigstack_longjmp.c168
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/bits/local_lim.h89
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h169
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/bits/semaphore.h39
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/clone2.S9
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/createthread.c26
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/dl-sysdep.h68
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/fork.c31
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/lowlevellock.h287
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/pt-initfini.c50
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/pt-vfork.S60
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/pthread_once.c94
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h222
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/timer_create.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/timer_delete.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/timer_getoverr.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/timer_gettime.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/timer_settime.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/unwind-forcedunwind.c39
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/unwind_longjmp.c44
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/ia64/vfork.S69
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/internaltypes.h152
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/jmp-unwind.c39
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/kernel-posix-timers.h60
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/libc-lowlevellock.c21
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/libc_multiple_threads.c26
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/libc_pthread_init.c59
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/lowlevelbarrier.sym11
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/lowlevelcond.sym16
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/lowlevellock.c131
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.c97
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.sym6
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/lowlevelrwlock.sym14
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/mq_notify.c287
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/Makefile2
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/Versions5
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h218
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/bits/semaphore.h44
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/createthread.c25
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/fork.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h321
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/not-cancel.h1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S9
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/pt-vfork.S49
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h130
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S57
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/Versions7
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S9
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/pt-vfork.S49
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h119
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_create.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_delete.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_getoverr.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_gettime.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_settime.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S55
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/pt-longjmp.c68
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/pthread_once.c100
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/powerpc/sem_post.c48
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/pt-fork.c28
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/pt-raise.c52
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/pthread-pi-defines.sym6
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/pthread_attr_getaffinity.c69
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/pthread_attr_setaffinity.c95
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/pthread_getaffinity.c60
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/pthread_getcpuclockid.c111
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/pthread_kill.c70
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/pthread_mutex_cond_lock.c9
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/pthread_setaffinity.c99
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/pthread_yield.c30
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/raise.c75
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/register-atfork.c135
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h217
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/bits/semaphore.h43
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/fork.c31
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/jmp-unwind.c41
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/lowlevellock.h379
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/not-cancel.h1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/pthread_once.c111
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/clone.S9
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/pt-initfini.c154
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/pt-vfork.S54
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h115
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/vfork.S57
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/Versions7
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/clone.S9
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/pt-initfini.c136
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/pt-vfork.S57
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h128
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_create.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_delete.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_getoverr.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_gettime.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_settime.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/vfork.S59
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sem_post.c47
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sem_timedwait.c99
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sem_trywait.c50
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sem_wait.c63
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h168
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/bits/semaphore.h39
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/clone.S9
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/createthread.c24
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/fork.c30
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/libc-lowlevellock.S19
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevel-atomic.h79
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.S326
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.h410
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevelrobustlock.S224
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/not-cancel.h1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/pt-initfini.c143
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/pt-vfork.S66
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_barrier_wait.S196
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_cond_broadcast.S213
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_cond_signal.S139
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_cond_timedwait.S770
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_cond_wait.S628
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_once.S246
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_rdlock.S221
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedrdlock.S281
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedwrlock.S266
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_unlock.S170
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_wrlock.S203
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/sem_post.S87
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/sem_timedwait.S241
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/sem_trywait.S89
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/sem_wait.S167
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/sh4/lowlevellock.h4
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/smp.h24
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h163
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sh/vfork.S71
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sigtimedwait.c2
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sigwait.c2
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sigwaitinfo.c2
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sleep.c10
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/smp.h28
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/Makefile2
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/Versions6
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/aio_cancel.c33
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/bits/local_lim.h89
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/bits/pthreadtypes.h218
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/bits/semaphore.h44
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/fork.c29
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/lowlevellock.h301
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/not-cancel.h1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/pthread_once.c94
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/clone.S9
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/lowlevellock.c131
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/pt-vfork.S45
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/pthread_barrier_init.c62
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/pthread_barrier_wait.c100
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sem_init.c63
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sem_post.c54
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sem_timedwait.c117
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sem_trywait.c59
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sem_wait.c74
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/pthread_barrier_init.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/pthread_barrier_wait.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_init.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_post.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_timedwait.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_trywait.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_wait.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep-cancel.h106
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S49
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/Versions7
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/clone.S9
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/pt-vfork.S45
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep-cancel.h104
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/timer_create.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/timer_delete.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/timer_getoverr.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/timer_gettime.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/timer_settime.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S49
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/timer_create.c236
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/timer_delete.c94
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/timer_getoverr.c81
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/timer_gettime.c83
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/timer_routines.c181
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/timer_settime.c88
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/unregister-atfork.c111
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/unwindbuf.sym7
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/Makefile4
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/Versions7
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h222
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/bits/semaphore.h44
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/clone.S9
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/compat-timer.h46
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c31
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S30
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S283
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h455
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S194
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/not-cancel.h1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/pt-vfork.S33
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S160
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S143
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S127
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S470
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S423
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S270
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S177
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S220
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S211
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S130
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S165
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_spin_init.c1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_spin_unlock.S1
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S66
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S175
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_trywait.S58
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S120
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h138
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/timer_create.c66
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/timer_delete.c45
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/timer_getoverr.c39
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/timer_gettime.c38
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/timer_settime.c40
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/vfork.S43
-rw-r--r--libc/nptl/sysdeps/x86_64/Makefile28
-rw-r--r--libc/nptl/sysdeps/x86_64/pthread_spin_init.c1
-rw-r--r--libc/nptl/sysdeps/x86_64/pthread_spin_lock.c1
-rw-r--r--libc/nptl/sysdeps/x86_64/pthread_spin_trylock.S40
-rw-r--r--libc/nptl/sysdeps/x86_64/pthread_spin_unlock.S31
-rw-r--r--libc/nptl/sysdeps/x86_64/pthreaddef.h54
-rw-r--r--libc/nptl/sysdeps/x86_64/tcb-offsets.sym13
-rw-r--r--libc/nptl/sysdeps/x86_64/tls.h344
-rw-r--r--libc/nptl/tpp.c172
-rw-r--r--libc/nptl/tst-_res1.c69
-rw-r--r--libc/nptl/tst-_res1mod1.c23
-rw-r--r--libc/nptl/tst-_res1mod2.c1
-rw-r--r--libc/nptl/tst-align.c71
-rw-r--r--libc/nptl/tst-align2.c87
-rw-r--r--libc/nptl/tst-align3.c57
-rw-r--r--libc/nptl/tst-atfork1.c121
-rw-r--r--libc/nptl/tst-atfork2.c159
-rw-r--r--libc/nptl/tst-atfork2mod.c58
-rw-r--r--libc/nptl/tst-attr1.c306
-rw-r--r--libc/nptl/tst-attr2.c317
-rw-r--r--libc/nptl/tst-attr3.c422
-rw-r--r--libc/nptl/tst-backtrace1.c86
-rw-r--r--libc/nptl/tst-barrier1.c71
-rw-r--r--libc/nptl/tst-barrier2.c185
-rw-r--r--libc/nptl/tst-barrier3.c154
-rw-r--r--libc/nptl/tst-barrier4.c121
-rw-r--r--libc/nptl/tst-basic1.c82
-rw-r--r--libc/nptl/tst-basic2.c121
-rw-r--r--libc/nptl/tst-basic3.c87
-rw-r--r--libc/nptl/tst-basic4.c101
-rw-r--r--libc/nptl/tst-basic5.c74
-rw-r--r--libc/nptl/tst-basic6.c132
-rw-r--r--libc/nptl/tst-cancel-wrappers.sh92
-rw-r--r--libc/nptl/tst-cancel1.c163
-rw-r--r--libc/nptl/tst-cancel10.c126
-rw-r--r--libc/nptl/tst-cancel11.c123
-rw-r--r--libc/nptl/tst-cancel12.c127
-rw-r--r--libc/nptl/tst-cancel13.c129
-rw-r--r--libc/nptl/tst-cancel14.c136
-rw-r--r--libc/nptl/tst-cancel15.c141
-rw-r--r--libc/nptl/tst-cancel16.c231
-rw-r--r--libc/nptl/tst-cancel17.c341
-rw-r--r--libc/nptl/tst-cancel18.c174
-rw-r--r--libc/nptl/tst-cancel19.c287
-rw-r--r--libc/nptl/tst-cancel2.c100
-rw-r--r--libc/nptl/tst-cancel20.c264
-rw-r--r--libc/nptl/tst-cancel21.c294
-rw-r--r--libc/nptl/tst-cancel22.c121
-rw-r--r--libc/nptl/tst-cancel23.c1
-rw-r--r--libc/nptl/tst-cancel24.cc113
-rw-r--r--libc/nptl/tst-cancel3.c98
-rw-r--r--libc/nptl/tst-cancel4.c2330
-rw-r--r--libc/nptl/tst-cancel5.c1
-rw-r--r--libc/nptl/tst-cancel6.c79
-rw-r--r--libc/nptl/tst-cancel7.c211
-rw-r--r--libc/nptl/tst-cancel8.c143
-rw-r--r--libc/nptl/tst-cancel9.c126
-rw-r--r--libc/nptl/tst-cancelx1.c1
-rw-r--r--libc/nptl/tst-cancelx10.c1
-rw-r--r--libc/nptl/tst-cancelx11.c1
-rw-r--r--libc/nptl/tst-cancelx12.c1
-rw-r--r--libc/nptl/tst-cancelx13.c1
-rw-r--r--libc/nptl/tst-cancelx14.c1
-rw-r--r--libc/nptl/tst-cancelx15.c1
-rw-r--r--libc/nptl/tst-cancelx16.c1
-rw-r--r--libc/nptl/tst-cancelx17.c1
-rw-r--r--libc/nptl/tst-cancelx18.c1
-rw-r--r--libc/nptl/tst-cancelx2.c1
-rw-r--r--libc/nptl/tst-cancelx20.c1
-rw-r--r--libc/nptl/tst-cancelx21.c1
-rw-r--r--libc/nptl/tst-cancelx3.c1
-rw-r--r--libc/nptl/tst-cancelx4.c1
-rw-r--r--libc/nptl/tst-cancelx5.c1
-rw-r--r--libc/nptl/tst-cancelx6.c1
-rw-r--r--libc/nptl/tst-cancelx7.c1
-rw-r--r--libc/nptl/tst-cancelx8.c1
-rw-r--r--libc/nptl/tst-cancelx9.c1
-rw-r--r--libc/nptl/tst-cleanup0.c76
-rw-r--r--libc/nptl/tst-cleanup0.expect3
-rw-r--r--libc/nptl/tst-cleanup1.c100
-rw-r--r--libc/nptl/tst-cleanup2.c63
-rw-r--r--libc/nptl/tst-cleanup3.c98
-rw-r--r--libc/nptl/tst-cleanup4.c198
-rw-r--r--libc/nptl/tst-cleanup4aux.c121
-rw-r--r--libc/nptl/tst-cleanupx0.c1
-rw-r--r--libc/nptl/tst-cleanupx0.expect3
-rw-r--r--libc/nptl/tst-cleanupx1.c1
-rw-r--r--libc/nptl/tst-cleanupx2.c1
-rw-r--r--libc/nptl/tst-cleanupx3.c1
-rw-r--r--libc/nptl/tst-cleanupx4.c1
-rw-r--r--libc/nptl/tst-clock1.c51
-rw-r--r--libc/nptl/tst-clock2.c202
-rw-r--r--libc/nptl/tst-cond1.c94
-rw-r--r--libc/nptl/tst-cond10.c173
-rw-r--r--libc/nptl/tst-cond11.c191
-rw-r--r--libc/nptl/tst-cond12.c196
-rw-r--r--libc/nptl/tst-cond13.c2
-rw-r--r--libc/nptl/tst-cond14.c118
-rw-r--r--libc/nptl/tst-cond15.c160
-rw-r--r--libc/nptl/tst-cond16.c105
-rw-r--r--libc/nptl/tst-cond17.c2
-rw-r--r--libc/nptl/tst-cond18.c117
-rw-r--r--libc/nptl/tst-cond19.c76
-rw-r--r--libc/nptl/tst-cond2.c163
-rw-r--r--libc/nptl/tst-cond20.c170
-rw-r--r--libc/nptl/tst-cond21.c3
-rw-r--r--libc/nptl/tst-cond3.c113
-rw-r--r--libc/nptl/tst-cond4.c263
-rw-r--r--libc/nptl/tst-cond5.c106
-rw-r--r--libc/nptl/tst-cond6.c233
-rw-r--r--libc/nptl/tst-cond7.c168
-rw-r--r--libc/nptl/tst-cond8.c277
-rw-r--r--libc/nptl/tst-cond9.c150
-rw-r--r--libc/nptl/tst-context1.c206
-rw-r--r--libc/nptl/tst-detach1.c56
-rw-r--r--libc/nptl/tst-dlsym1.c66
-rw-r--r--libc/nptl/tst-eintr1.c105
-rw-r--r--libc/nptl/tst-eintr2.c118
-rw-r--r--libc/nptl/tst-eintr3.c72
-rw-r--r--libc/nptl/tst-eintr4.c56
-rw-r--r--libc/nptl/tst-eintr5.c81
-rw-r--r--libc/nptl/tst-exec1.c160
-rw-r--r--libc/nptl/tst-exec2.c155
-rw-r--r--libc/nptl/tst-exec3.c153
-rw-r--r--libc/nptl/tst-exec4.c116
-rw-r--r--libc/nptl/tst-execstack-mod.c1
-rw-r--r--libc/nptl/tst-execstack.c2
-rw-r--r--libc/nptl/tst-exit1.c79
-rw-r--r--libc/nptl/tst-exit2.c40
-rw-r--r--libc/nptl/tst-exit3.c81
-rw-r--r--libc/nptl/tst-fini1.c35
-rw-r--r--libc/nptl/tst-fini1mod.c72
-rw-r--r--libc/nptl/tst-flock1.c93
-rw-r--r--libc/nptl/tst-flock2.c260
-rw-r--r--libc/nptl/tst-fork1.c120
-rw-r--r--libc/nptl/tst-fork2.c90
-rw-r--r--libc/nptl/tst-fork3.c107
-rw-r--r--libc/nptl/tst-fork4.c65
-rw-r--r--libc/nptl/tst-getpid1.c115
-rw-r--r--libc/nptl/tst-getpid2.c2
-rw-r--r--libc/nptl/tst-getpid3.c114
-rw-r--r--libc/nptl/tst-initializers1-c89.c1
-rw-r--r--libc/nptl/tst-initializers1-c99.c1
-rw-r--r--libc/nptl/tst-initializers1-gnu89.c1
-rw-r--r--libc/nptl/tst-initializers1-gnu99.c1
-rw-r--r--libc/nptl/tst-initializers1.c48
-rw-r--r--libc/nptl/tst-join1.c83
-rw-r--r--libc/nptl/tst-join2.c104
-rw-r--r--libc/nptl/tst-join3.c123
-rw-r--r--libc/nptl/tst-join4.c125
-rw-r--r--libc/nptl/tst-join5.c208
-rw-r--r--libc/nptl/tst-join6.c2
-rw-r--r--libc/nptl/tst-key1.c89
-rw-r--r--libc/nptl/tst-key2.c115
-rw-r--r--libc/nptl/tst-key3.c156
-rw-r--r--libc/nptl/tst-key4.c137
-rw-r--r--libc/nptl/tst-kill1.c100
-rw-r--r--libc/nptl/tst-kill2.c139
-rw-r--r--libc/nptl/tst-kill3.c159
-rw-r--r--libc/nptl/tst-kill4.c74
-rw-r--r--libc/nptl/tst-kill5.c49
-rw-r--r--libc/nptl/tst-kill6.c162
-rw-r--r--libc/nptl/tst-locale1.c17
-rw-r--r--libc/nptl/tst-locale2.c13
-rw-r--r--libc/nptl/tst-mutex1.c77
-rw-r--r--libc/nptl/tst-mutex2.c242
-rw-r--r--libc/nptl/tst-mutex3.c242
-rw-r--r--libc/nptl/tst-mutex4.c278
-rw-r--r--libc/nptl/tst-mutex5.c202
-rw-r--r--libc/nptl/tst-mutex5a.c2
-rw-r--r--libc/nptl/tst-mutex6.c75
-rw-r--r--libc/nptl/tst-mutex7.c165
-rw-r--r--libc/nptl/tst-mutex7a.c2
-rw-r--r--libc/nptl/tst-mutex8.c367
-rw-r--r--libc/nptl/tst-mutex9.c202
-rw-r--r--libc/nptl/tst-mutexpi1.c27
-rw-r--r--libc/nptl/tst-mutexpi2.c2
-rw-r--r--libc/nptl/tst-mutexpi3.c2
-rw-r--r--libc/nptl/tst-mutexpi4.c2
-rw-r--r--libc/nptl/tst-mutexpi5.c2
-rw-r--r--libc/nptl/tst-mutexpi5a.c2
-rw-r--r--libc/nptl/tst-mutexpi6.c27
-rw-r--r--libc/nptl/tst-mutexpi7.c2
-rw-r--r--libc/nptl/tst-mutexpi7a.c2
-rw-r--r--libc/nptl/tst-mutexpi8.c2
-rw-r--r--libc/nptl/tst-mutexpi9.c2
-rw-r--r--libc/nptl/tst-mutexpp1.c45
-rw-r--r--libc/nptl/tst-mutexpp10.c334
-rw-r--r--libc/nptl/tst-mutexpp6.c45
-rw-r--r--libc/nptl/tst-oddstacklimit.c1
-rw-r--r--libc/nptl/tst-once1.c51
-rw-r--r--libc/nptl/tst-once2.c104
-rw-r--r--libc/nptl/tst-once3.c167
-rw-r--r--libc/nptl/tst-once4.c202
-rw-r--r--libc/nptl/tst-oncex3.c1
-rw-r--r--libc/nptl/tst-oncex4.c1
-rw-r--r--libc/nptl/tst-popen1.c60
-rw-r--r--libc/nptl/tst-raise1.c62
-rw-r--r--libc/nptl/tst-robust1.c339
-rw-r--r--libc/nptl/tst-robust2.c3
-rw-r--r--libc/nptl/tst-robust3.c20
-rw-r--r--libc/nptl/tst-robust4.c2
-rw-r--r--libc/nptl/tst-robust5.c2
-rw-r--r--libc/nptl/tst-robust6.c2
-rw-r--r--libc/nptl/tst-robust7.c212
-rw-r--r--libc/nptl/tst-robust8.c275
-rw-r--r--libc/nptl/tst-robustpi1.c2
-rw-r--r--libc/nptl/tst-robustpi2.c2
-rw-r--r--libc/nptl/tst-robustpi3.c2
-rw-r--r--libc/nptl/tst-robustpi4.c2
-rw-r--r--libc/nptl/tst-robustpi5.c2
-rw-r--r--libc/nptl/tst-robustpi6.c2
-rw-r--r--libc/nptl/tst-robustpi7.c2
-rw-r--r--libc/nptl/tst-robustpi8.c2
-rw-r--r--libc/nptl/tst-rwlock1.c117
-rw-r--r--libc/nptl/tst-rwlock10.c21
-rw-r--r--libc/nptl/tst-rwlock11.c21
-rw-r--r--libc/nptl/tst-rwlock12.c208
-rw-r--r--libc/nptl/tst-rwlock13.c71
-rw-r--r--libc/nptl/tst-rwlock14.c169
-rw-r--r--libc/nptl/tst-rwlock2.c143
-rw-r--r--libc/nptl/tst-rwlock3.c93
-rw-r--r--libc/nptl/tst-rwlock4.c190
-rw-r--r--libc/nptl/tst-rwlock5.c87
-rw-r--r--libc/nptl/tst-rwlock6.c226
-rw-r--r--libc/nptl/tst-rwlock7.c179
-rw-r--r--libc/nptl/tst-rwlock8.c164
-rw-r--r--libc/nptl/tst-rwlock9.c203
-rw-r--r--libc/nptl/tst-sched1.c98
-rw-r--r--libc/nptl/tst-sem1.c89
-rw-r--r--libc/nptl/tst-sem2.c54
-rw-r--r--libc/nptl/tst-sem3.c142
-rw-r--r--libc/nptl/tst-sem4.c147
-rw-r--r--libc/nptl/tst-sem5.c80
-rw-r--r--libc/nptl/tst-sem6.c81
-rw-r--r--libc/nptl/tst-sem7.c109
-rw-r--r--libc/nptl/tst-sem8.c74
-rw-r--r--libc/nptl/tst-sem9.c81
-rw-r--r--libc/nptl/tst-setuid1-static.c1
-rw-r--r--libc/nptl/tst-setuid1.c1085
-rw-r--r--libc/nptl/tst-signal1.c189
-rw-r--r--libc/nptl/tst-signal2.c198
-rw-r--r--libc/nptl/tst-signal3.c261
-rw-r--r--libc/nptl/tst-signal4.c60
-rw-r--r--libc/nptl/tst-signal5.c111
-rw-r--r--libc/nptl/tst-signal6.c192
-rw-r--r--libc/nptl/tst-signal7.c59
-rw-r--r--libc/nptl/tst-spin1.c57
-rw-r--r--libc/nptl/tst-spin2.c159
-rw-r--r--libc/nptl/tst-spin3.c55
-rw-r--r--libc/nptl/tst-stack1.c146
-rw-r--r--libc/nptl/tst-stack2.c79
-rw-r--r--libc/nptl/tst-stack3.c101
-rw-r--r--libc/nptl/tst-stackguard1-static.c1
-rw-r--r--libc/nptl/tst-stackguard1.c226
-rw-r--r--libc/nptl/tst-stdio1.c57
-rw-r--r--libc/nptl/tst-stdio2.c82
-rw-r--r--libc/nptl/tst-sysconf.c48
-rw-r--r--libc/nptl/tst-tls1.c122
-rw-r--r--libc/nptl/tst-tls2.c215
-rw-r--r--libc/nptl/tst-tls3.c215
-rw-r--r--libc/nptl/tst-tls3mod.c92
-rw-r--r--libc/nptl/tst-tls4.c191
-rw-r--r--libc/nptl/tst-tls4moda.c56
-rw-r--r--libc/nptl/tst-tls4modb.c65
-rw-r--r--libc/nptl/tst-tls5.c120
-rw-r--r--libc/nptl/tst-tls5.h28
-rw-r--r--libc/nptl/tst-tls5mod.c6
-rw-r--r--libc/nptl/tst-tls5moda.c6
-rw-r--r--libc/nptl/tst-tls5modb.c6
-rw-r--r--libc/nptl/tst-tls5modc.c6
-rw-r--r--libc/nptl/tst-tls5modd.c6
-rw-r--r--libc/nptl/tst-tls5mode.c8
-rw-r--r--libc/nptl/tst-tls5modf.c9
-rwxr-xr-xlibc/nptl/tst-tls6.sh53
-rw-r--r--libc/nptl/tst-tpp.h94
-rw-r--r--libc/nptl/tst-tsd1.c118
-rw-r--r--libc/nptl/tst-tsd2.c97
-rw-r--r--libc/nptl/tst-tsd3.c129
-rw-r--r--libc/nptl/tst-tsd4.c103
-rw-r--r--libc/nptl/tst-tsd5.c81
-rw-r--r--libc/nptl/tst-typesizes.c68
-rw-r--r--libc/nptl/tst-umask1.c137
-rw-r--r--libc/nptl/tst-unload.c48
-rw-r--r--libc/nptl/tst-vfork1.c1
-rw-r--r--libc/nptl/tst-vfork1x.c1
-rw-r--r--libc/nptl/tst-vfork2.c1
-rw-r--r--libc/nptl/tst-vfork2x.c1
-rw-r--r--libc/nptl/unwind.c176
-rw-r--r--libc/nptl/vars.c43
-rw-r--r--libc/nptl/version.c45
883 files changed, 89448 insertions, 0 deletions
diff --git a/libc/nptl/ANNOUNCE b/libc/nptl/ANNOUNCE
new file mode 100644
index 000000000..b63c657b8
--- /dev/null
+++ b/libc/nptl/ANNOUNCE
@@ -0,0 +1,92 @@
+Now that the Linux kernel is once again able to run all the tests we
+have and since glibc 2.3 was released it was time for a new code drop.
+I've uploaded the second code drop for the Native POSIX Thread
+Library:
+
+ ftp://people.redhat.com/drepper/nptl/nptl-0.2.tar.bz2
+
+You need
+
+- the latest of Linus' kernel from BitKeeper (or 2.5.41 when it
+ is released);
+
+- glibc 2.3
+
+- the very latest in tools such as
+
+ + gcc either from the current development branch or the gcc 3.2
+ from Red Hat Linux 8;
+
+ + binutils preferrably from CVS, from H.J. Lu's latest release for
+ Linux, or from RHL 8.
+
+
+Compiling glibc should proceed smoothly. But there are a number of
+tests which fail, mostly because some functionality is missing in
+glibc. Ignore those errors. It is only important that all tests in
+nptl/ are passing. Run
+
+ make subdirs=nptl check
+
+to run all thread tests.
+
+
+This version features several improvements:
+
+- all APIs are now implemented;
+
+- fork handling has been improved; stacks in the child are freed;
+ atfork handlers are removed if they were registered from a module
+ which gets unloaded.
+
+- pthread_tryjoin_np and pthread_timedjoin_np are implemented
+
+- TSD handling corrected and optimized.
+
+- many more tests which also test the underlying kernel implementation.
+
+- the build infrastructure has been implemented so that the DSO and
+ archives are built in usable form and with correct named.
+
+- libthread_db has been implemented. This is the library which is
+ needed by all program which need to get access to internals of
+ libpthread (mainly debuggers).
+
+- the CPU clock functions are implemented
+
+
+
+The white paper hasn't yet been updated. It's still available at
+
+ http://people.redhat.com/drepper/nptl-design.pdf
+
+
+This release should be ready for some serious testing. I know it is
+hard to compile which I why I'm looking into providing binary RPMs.
+They can be used on non-critical systems. I'll only be able to
+provide binaries for RHL8 based systems, though, and the kernel still
+must be installed separately.
+
+
+The next steps will include:
+
+- write more tests and fix the bugs which are discovered this way
+
+- update the white paper
+
+- write and run more performance tests
+
+- port to IA-64
+
+
+Interested parties are once again invited to join the mailing we
+created:
+
+
+ phil-list@redhat.com
+
+Go to
+
+ https://listman.redhat.com/mailman/listinfo/phil-list
+
+to subscribe, unsubscribe, or review the archive.
diff --git a/libc/nptl/Banner b/libc/nptl/Banner
new file mode 100644
index 000000000..7c1487e7b
--- /dev/null
+++ b/libc/nptl/Banner
@@ -0,0 +1 @@
+Native POSIX Threads Library by Ulrich Drepper et al
diff --git a/libc/nptl/ChangeLog b/libc/nptl/ChangeLog
new file mode 100644
index 000000000..127dfdc77
--- /dev/null
+++ b/libc/nptl/ChangeLog
@@ -0,0 +1,8284 @@
+2006-08-15 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/clock_settime.c (INTERNAL_VSYSCALL): Use
+ HAVE_CLOCK_GETRES_VSYSCALL as guard macro rather than
+ HAVE_CLOCK_GETTIME_VSYSCALL.
+ (maybe_syscall_settime_cpu): Use plain INTERNAL_VSYSCALL here.
+
+2006-08-14 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/bits/posix_opt.h
+ (_POSIX_THREAD_PRIO_PROTECT): Define to 200112L.
+ * descr.h (struct priority_protection_data): New type.
+ (struct pthread): Add tpp field.
+ * pthreadP.h (PTHREAD_MUTEX_PP_NORMAL_NP,
+ PTHREAD_MUTEX_PP_RECURSIVE_NP, PTHREAD_MUTEX_PP_ERRORCHECK_NP,
+ PTHREAD_MUTEX_PP_ADAPTIVE_NP): New enum values.
+ * pthread_mutex_init.c (__pthread_mutex_init): Handle non-robust
+ TPP mutexes.
+ * pthread_mutex_lock.c (__pthread_mutex_lock): Handle TPP mutexes.
+ * pthread_mutex_trylock.c (__pthread_mutex_trylock): Likewise.
+ * pthread_mutex_timedlock.c (pthread_mutex_timedlock): Likewise.
+ * pthread_mutex_unlock.c (__pthread_mutex_unlock_usercnt): Likewise.
+ * tpp.c: New file.
+ * pthread_setschedparam.c (__pthread_setschedparam): Handle priority
+ boosted by TPP.
+ * pthread_setschedprio.c (pthread_setschedprio): Likewise.
+ * pthread_mutexattr_getprioceiling.c
+ (pthread_mutexattr_getprioceiling): If ceiling is 0, ensure it is
+ in the SCHED_FIFO priority range.
+ * pthread_mutexattr_setprioceiling.c
+ (pthread_mutexattr_setprioceiling): Fix prioceiling validation.
+ * pthread_mutex_getprioceiling.c (pthread_mutex_getprioceiling): Fail
+ if mutex is not TPP. Ceiling is now in __data.__lock.
+ * pthread_mutex_setprioceiling.c: Include stdbool.h.
+ (pthread_mutex_setprioceiling): Fix prioceiling validation. Ceiling
+ is now in __data.__lock. Add locking.
+ * pthread_create.c (__free_tcb): Free pd->tpp structure.
+ * Makefile (libpthread-routines): Add tpp.
+ (xtests): Add tst-mutexpp1, tst-mutexpp6 and tst-mutexpp10.
+ * tst-tpp.h: New file.
+ * tst-mutexpp1.c: New file.
+ * tst-mutexpp6.c: New file.
+ * tst-mutexpp10.c: New file.
+ * tst-mutex1.c (TEST_FUNCTION): Don't redefine if already defined.
+ * tst-mutex6.c (TEST_FUNCTION): Likewise.
+
+2006-08-12 Ulrich Drepper <drepper@redhat.com>
+
+ [BZ #2843]
+ * pthread_join.c (pthread_join): Account for self being canceled
+ when checking for deadlocks.
+ * tst-join5.c: Cleanups. Allow to be used in tst-join6.
+ (tf1): Don't print anything after pthread_join returns, this would be
+ another cancellation point.
+ (tf2): Likewise.
+ * tst-join6.c: New file.
+ * Makefile (tests): Add tst-join6.
+
+2006-08-03 Ulrich Drepper <drepper@redhat.com>
+
+ [BZ #2892]
+ * pthread_setspecific.c (__pthread_setspecific): Check
+ out-of-range index before checking for unused key.
+
+ * sysdeps/pthread/gai_misc.h: New file.
+
+2006-08-01 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/smp.h: New file. Old Linux-specific
+ file. Don't use sysctl.
+ * sysdeps/unix/sysv/linux/smp.h: Always assume SMP. Archs can
+ overwrite the file if this is likely not true.
+
+2006-07-31 Daniel Jacobowitz <dan@codesourcery.com>
+
+ * allocatestack.c (__reclaim_stacks): Reset the PID on cached stacks.
+ * Makefile (tests): Add tst-getpid3.
+ * tst-getpid3.c: New file.
+
+2006-07-30 Roland McGrath <roland@redhat.com>
+
+ * Makefile (libpthread-routines): Add ptw-sigsuspend.
+
+ * sysdeps/unix/sysv/linux/i386/not-cancel.h
+ (pause_not_cancel): New macro.
+ (nanosleep_not_cancel): New macro.
+ (sigsuspend_not_cancel): New macro.
+ * pthread_mutex_timedlock.c (pthread_mutex_timedlock): Use
+ nanosleep_not_cancel macro from <not-cancel.h>.
+ * pthread_mutex_lock.c (__pthread_mutex_lock): Use pause_not_cancel
+ macro from <not-cancel.h>.
+
+2006-07-28 Ulrich Drepper <drepper@redhat.com>
+ Jakub Jelinek <jakub@redhat.com>
+
+ * descr.h: Change ENQUEUE_MUTEX and DEQUEUE_MUTEX for bit 0
+ notification of PI mutex. Add ENQUEUE_MUTEX_PI.
+ * pthreadP.h: Define PTHREAD_MUTEX_PI_* macros for PI mutex types.
+ * pthread_mutex_setprioceilining.c: Adjust for mutex type name change.
+ * pthread_mutex_init.c: Add support for priority inheritance mutex.
+ * pthread_mutex_lock.c: Likewise.
+ * pthread_mutex_timedlock.c: Likewise.
+ * pthread_mutex_trylock.c: Likewise.
+ * pthread_mutex_unlock.c: Likewise.
+ * sysdeps/pthread/pthread_cond_broadcast.c: For PI mutexes wake
+ all mutexes.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_broadcast.c: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.c: Likewise.
+ * sysdeps/unix/sysv/linux/pthread-pi-defines.sym: New file.
+ * sysdeps/unix/sysv/linux/Makefile (gen-as-const-header): Add
+ pthread-pi-defines.sym.
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h: Define FUTEX_LOCK_PI,
+ FUTEX_UNLOCK_PI, and FUTEX_TRYLOCK_PI.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h: Likewise.
+ * sysdeps/unix/sysv/linux/alpha/lowlevellock.h: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.h: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h: Likewise.
+ * sysdeps/unix/sysv/linux/s390/lowlevellock.h: Likewise.
+ * sysdeps/unix/sysv/linux/sh/lowlevellock.h: Likewise.
+ * sysdeps/unix/sysv/linux/sparc/lowlevellock.h: Likewise.
+ * sysdeps/unix/sysv/linux/bits/posix_opt.h: Define
+ _POSIX_THREAD_PRIO_INHERIT to 200112L.
+ * tst-mutex1.c: Adjust to allow use in PI mutex test.
+ * tst-mutex2.c: Likewise.
+ * tst-mutex3.c: Likewise.
+ * tst-mutex4.c: Likewise.
+ * tst-mutex5.c: Likewise.
+ * tst-mutex6.c: Likewise.
+ * tst-mutex7.c: Likewise.
+ * tst-mutex7a.c: Likewise.
+ * tst-mutex8.c: Likewise.
+ * tst-mutex9.c: Likewise.
+ * tst-robust1.c: Likewise.
+ * tst-robust7.c: Likewise.
+ * tst-robust8.c: Likewise.
+ * tst-mutexpi1.c: New file.
+ * tst-mutexpi2.c: New file.
+ * tst-mutexpi3.c: New file.
+ * tst-mutexpi4.c: New file.
+ * tst-mutexpi5.c: New file.
+ * tst-mutexpi6.c: New file.
+ * tst-mutexpi7.c: New file.
+ * tst-mutexpi7a.c: New file.
+ * tst-mutexpi8.c: New file.
+ * tst-mutexpi9.c: New file.
+ * tst-robust1.c: New file.
+ * tst-robust2.c: New file.
+ * tst-robust3.c: New file.
+ * tst-robust4.c: New file.
+ * tst-robust5.c: New file.
+ * tst-robust6.c: New file.
+ * tst-robust7.c: New file.
+ * tst-robust8.c: New file.
+ * Makefile (tests): Add the new tests.
+
+ * pthread_create.c (start_thread): Add some casts to avoid warnings.
+ * pthread_mutex_destroy.c: Remove unneeded label.
+
+2006-07-01 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread_mutex_init.c (__pthread_mutex_init): Move some
+ computations to compile time.
+
+2006-06-04 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/pthread.h: Add pthread_equal inline version.
+
+2006-05-15 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/fork.h: Mark __fork_handlers as hidden.
+
+2006-05-11 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread_key_create.c (__pthread_key_create): Do away with
+ __pthread_keys_lock.
+
+ * sysdeps/unix/sysv/linux/pthread_setaffinity.c
+ (__kernel_cpumask_size): Mark as hidden.
+ * sysdeps/unix/sysv/linux/pthread_attr_setaffinity.c: Likewise.
+
+ * sem_open.c (__sem_mappings_lock): Mark as hidden.
+ * semaphoreP.h (__sem_mappings_lock): Likewise.
+
+2006-05-10 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread_atfork.c: Mark __dso_handle as hidden.
+
+2006-05-09 Ulrich Drepper <drepper@redhat.com>
+
+ [BZ #2644]
+ * sysdeps/pthread/unwind-forcedunwind.c: Different solution for
+ the reload problem. Change the one path in pthread_cancel_init
+ which causes the problem. Force gcc to reload. Simplify callers.
+ * sysdeps/unix/sysv/linux/ia64/unwind-forcedunwind.c
+ (_Unwind_GetBSP): Undo last patch.
+
+2006-05-07 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/ia64/unwind-forcedunwind.c: Make sure the
+ function pointer is reloaded after pthread_cancel_init calls.
+
+ [BZ #2644]
+ * sysdeps/pthread/unwind-forcedunwind.c: Make sure functions
+ pointers are reloaded after pthread_cancel_init calls.
+
+2006-05-01 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/allocalim.h (__libc_use_alloca): Mark with
+ __always_inline.
+
+2006-04-27 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/timer_routines.c (timer_helper_thread):
+ Allocate new object which is passed to timer_sigev_thread so that
+ the timer can be deleted before the new thread is scheduled.
+
+2006-04-26 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/x86_64/tls.h: Include <asm/prctl.h> inside [! __ASSEMBLER__].
+
+2006-04-08 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h: Remove branch predicion
+ suffix for conditional jumps.
+ * sysdeps/unix/sysv/linux/i386/i486/sem_trywait.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_barrier_wait.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/sem_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/sem_wait.S: Likewise.
+
+ * init.c (sigcancel_handler): Compare with correct PID even if the
+ thread is in the middle of a fork call.
+ (sighandler_setxid): Likewise.
+ Reported by Suzuki K P <suzuki@in.ibm.com> .
+
+2006-04-07 Jakub Jelinek <jakub@redhat.com>
+
+ * pthreadP.h (FUTEX_TID_MASK): Sync with kernel.
+
+2006-04-06 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread_getattr_np.c (pthread_getattr_np): Close fp if getrlimit
+ fails [Coverity CID 105].
+
+2006-04-05 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/pthread.h: Add nonnull attributes.
+
+2006-04-03 Steven Munroe <sjmunroe@us.ibm.com>
+
+ [BZ #2505]
+ * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h [_ARCH_PWR4]:
+ Define __lll_rel_instr using lwsync.
+
+2006-03-27 Ulrich Drepper <drepper@redhat.com>
+
+ * allocatestack.c (allocate_stack): Always initialize robust_head.
+ * descr.h: Define struct robust_list_head.
+ (struct pthread): Use robust_list_head in robust mutex list definition.
+ Adjust ENQUEUE_MUTEX and DEQUEUE_MUTEX.
+ * init.c [!__ASSUME_SET_ROBUST_LIST] (__set_robust_list_avail): Define.
+ (__pthread_initialize_minimal_internal): Register robust_list with
+ the kernel.
+ * pthreadP.h: Remove PRIVATE_ from PTHREAD_MUTEX_ROBUST_* names.
+ Declare __set_robust_list_avail.
+ * pthread_create.c (start_thread): Register robust_list of new thread.
+ [!__ASSUME_SET_ROBUST_LIST]: If robust_list is not empty wake up
+ waiters.
+ * pthread_mutex_destroy.c: For robust mutexes don't look at the
+ number of users, it's unreliable.
+ * pthread_mutex_init.c: Allow use of pshared robust mutexes if
+ set_robust_list syscall is available.
+ * pthread_mutex_consistent.c: Adjust for PTHREAD_MUTEX_ROBUST_* rename.
+ * pthread_mutex_lock.c: Simplify robust mutex code a bit.
+ Set robust_head.list_op_pending before trying to lock a robust mutex.
+ * pthread_mutex_timedlock.c: Likewise.
+ * pthread_mutex_trylock.c: Likewise.
+ * pthread_mutex_unlock.c: Likewise for unlocking.
+ * Makefile (tests): Add tst-robust8.
+ * tst-robust8.c: New file.
+
+2006-03-08 Andreas Schwab <schwab@suse.de>
+
+ * sysdeps/unix/sysv/linux/ia64/dl-sysdep.h
+ (DL_SYSINFO_IMPLEMENTATION): Add missing newline.
+
+2006-03-05 Roland McGrath <roland@redhat.com>
+
+ * configure (libc_add_on): Disable add-on when $add_ons_automatic = yes
+ and $config_os doesn't match *linux*.
+
+2006-03-05 David S. Miller <davem@sunset.davemloft.net>
+
+ * sysdeps/unix/sysv/linux/sparc/sparc32/pt-vfork.S:
+ Use __syscall_error.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/sysdep-cancel.h: Likewise.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S: Likewise.
+ * sysdeps/unix/sysv/linux/sparc/sparc64/pt-vfork.S: Likewise.
+ * sysdeps/unix/sysv/linux/sparc/sparc64/sysdep-cancel.h: Likewise.
+ * sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S: Likewise.
+ * sysdeps/unix/sysv/linux/sparc/Makefile: New file.
+
+2006-03-02 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/aio_misc.h: Various cleanups.
+
+2006-03-01 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
+ (__lll_robust_lock_wait): Also set FUTEX_WAITERS bit if we got the
+ mutex.
+ (__lll_robust_timedlock_wait): Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelrobustlock.S
+ (__lll_robust_lock_wait): Likewise.
+ (__lll_robust_timedlock_wait): Likewise.
+ * sysdeps/unix/sysv/linux/lowlevelrobustlock.c
+ (__lll_robust_lock_wait): Likewise.
+ (__lll_robust_timedlock_wait): Likewise.
+
+2006-03-01 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/sparc/lowlevellock.h (lll_robust_mutex_dead,
+ lll_robust_mutex_trylock, lll_robust_mutex_lock,
+ lll_robust_mutex_cond_lock, lll_robust_mutex_timedlock,
+ lll_robust_mutex_unlock): Define.
+ (__lll_robust_lock_wait, __lll_robust_timedlock_wait): New prototypes.
+
+2006-02-28 H.J. Lu <hongjiu.lu@intel.com>
+
+ * sysdeps/unix/sysv/linux/ia64/clone2.S: Include <clone2.S>
+ instead of <clone.S>.
+
+2006-02-27 Jakub Jelinek <jakub@redhat.com>
+
+ * Makefile (libpthread-routines): Add
+ pthread_mutexattr_[sg]etprotocol, pthread_mutexattr_[sg]etprioceiling
+ and pthread_mutex_[sg]etprioceiling.
+ * Versions (GLIBC_2.4): Export pthread_mutexattr_getprotocol,
+ pthread_mutexattr_setprotocol, pthread_mutexattr_getprioceiling,
+ pthread_mutexattr_setprioceiling, pthread_mutex_getprioceiling and
+ pthread_mutex_setprioceiling.
+ * sysdeps/pthread/pthread.h (PTHREAD_PRIO_NONE, PTHREAD_PRIO_INHERIT,
+ PTHREAD_PRIO_PROTECT): New enum values.
+ (pthread_mutexattr_getprotocol, pthread_mutexattr_setprotocol,
+ pthread_mutexattr_getprioceiling, pthread_mutexattr_setprioceiling,
+ pthread_mutex_getprioceiling, pthread_mutex_setprioceiling): New
+ prototypes.
+ * pthreadP.h (PTHREAD_MUTEX_PRIO_INHERIT_PRIVATE_NP,
+ PTHREAD_MUTEX_PRIO_PROTECT_PRIVATE_NP): New enum values.
+ (PTHREAD_MUTEX_PRIO_CEILING_SHIFT, PTHREAD_MUTEX_PRIO_CEILING_MASK):
+ Define.
+ (PTHREAD_MUTEXATTR_PROTOCOL_SHIFT, PTHREAD_MUTEXATTR_PROTOCOL_MASK,
+ PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT,
+ PTHREAD_MUTEXATTR_PRIO_CEILING_MASK): Define.
+ (PTHREAD_MUTEXATTR_FLAG_BITS): Or in PTHREAD_MUTEXATTR_PROTOCOL_MASK
+ and PTHREAD_MUTEXATTR_PRIO_CEILING_MASK.
+ * pthread_mutex_init.c (__pthread_mutex_init): For the time being
+ return ENOTSUP for PTHREAD_PRIO_INHERIT or PTHREAD_PRIO_PROTECT
+ protocol mutexes.
+ * pthread_mutex_getprioceiling.c: New file.
+ * pthread_mutex_setprioceiling.c: New file.
+ * pthread_mutexattr_getprioceiling.c: New file.
+ * pthread_mutexattr_setprioceiling.c: New file.
+ * pthread_mutexattr_getprotocol.c: New file.
+ * pthread_mutexattr_setprotocol.c: New file.
+
+2006-02-27 Daniel Jacobowitz <dan@codesourcery.com>
+
+ * sysdeps/unix/sysv/linux/aio_misc.h: Include <limits.h>.
+
+2006-02-27 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/pthread/Subdirs: List nptl here too.
+ * configure (libc_add_on_canonical): New variable.
+
+ * sysdeps/unix/sysv/linux/sh/sh4/lowlevellock.h: Use #include_next.
+
+ * sysdeps/unix/sysv/linux/sleep.c: Use #include_next after #include of
+ self to get main source tree's file.
+ * sysdeps/unix/sysv/linux/alpha/clone.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/clone.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/vfork.S: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/clone2.S: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S: Likewise.
+ * sysdeps/unix/sysv/linux/s390/s390-32/clone.S: Likewise.
+ * sysdeps/unix/sysv/linux/s390/s390-64/clone.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/clone.S: Likewise.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/clone.S: Likewise.
+ * sysdeps/unix/sysv/linux/sparc/sparc64/clone.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/clone.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/vfork.S: Likewise.
+
+ * Makefile: Use $(sysdirs) in vpath directive.
+
+ * sysdeps/pthread/Makefile (CFLAGS-libc-start.c): Variable removed.
+ (CPPFLAGS-timer_routines.c): Likewise.
+
+ * Makeconfig (includes): Variable removed.
+
+2006-02-26 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/generic/pt-raise.c: Moved to ...
+ * pt-raise.c: ... here.
+ * sysdeps/generic/lowlevellock.h: Moved to ...
+ * lowlevellock.h: ... here.
+
+2006-02-23 Roland McGrath <roland@redhat.com>
+
+ * descr.h (struct pthread): Add final member `end_padding'.
+ (PTHREAD_STRUCT_END_PADDING): Use it.
+
+2006-02-20 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/mips: Directory removed, saved in ports repository.
+ * sysdeps/unix/sysv/linux/mips: Likewise.
+
+2006-02-18 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-robust1.c: Add second mutex to check that the mutex list is
+ handled correctly.
+
+2006-02-17 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/alpha/lowlevellock.h (lll_robust_mutex_dead,
+ lll_robust_mutex_trylock, lll_robust_mutex_lock,
+ lll_robust_mutex_cond_lock, lll_robust_mutex_timedlock,
+ lll_robust_mutex_unlock): New macros.
+ (__lll_robust_lock_wait, __lll_robust_timedlock_wait): New prototypes.
+ * sysdeps/unix/sysv/linux/s390/lowlevellock.h: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.h: Likewise.
+ * sysdeps/unix/sysv/linux/lowlevelrobustlock.c: New file.
+
+2006-02-17 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/unix/sysv/linux/sh/lowlevellock.h: Add lll_robust_mutex_*
+ definitions.
+ * sysdeps/unix/sysv/linux/sh/lowlevelrobustlock.S: New file.
+
+2006-02-17 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
+ (lll_robust_mutex_unlock): Avoid unnecessary wakeups.
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h
+ (lll_robust_mutex_unlock): Likewise.
+
+2006-02-13 Jakub Jelinek <jakub@redhat.com>
+
+ * descr.h [!__PTHREAD_MUTEX_HAVE_PREV] (DEQUEUE_MUTEX):
+ Set robust_list.__next rather than robust_list.
+ * sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h
+ (__pthread_list_t): New typedef.
+ (pthread_mutex_t): Replace __next and __prev fields with __list.
+ * sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h
+ (__pthread_list_t): New typedef.
+ (pthread_mutex_t): Replace __next and __prev fields with __list.
+ * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h
+ (__pthread_list_t, __pthread_slist_t): New typedefs.
+ (pthread_mutex_t): Replace __next and __prev fields with __list.
+ * sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h
+ (__pthread_list_t, __pthread_slist_t): New typedefs.
+ (pthread_mutex_t): Replace __next and __prev fields with __list.
+ * sysdeps/unix/sysv/linux/sparc/bits/pthreadtypes.h
+ (__pthread_list_t, __pthread_slist_t): New typedefs.
+ (pthread_mutex_t): Replace __next and __prev fields with __list.
+ * sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h
+ (__pthread_slist_t): New typedef.
+ (pthread_mutex_t): Replace __next field with __list.
+
+2006-02-15 Ulrich Drepper <drepper@redhat.com>
+
+ * pthreadP.h: Define PTHREAD_MUTEX_INCONSISTENT instead of
+ PTHREAD_MUTEX_OWNERDEAD.
+ (PTHREAD_MUTEX_ROBUST_PRIVATE_NP): Define as 16, not 256.
+ Define FUTEX_WAITERS, FUTEX_OWNER_DIED, FUTEX_TID_MASK.
+ * Makefile (libpthread-routines): Add lowlevelrobustlock.
+ * pthread_create.c (start_thread): Very much simplify robust_list loop.
+ * pthread_mutex_consistent.c: Inconsistent mutex have __owner now set
+ to PTHREAD_MUTEX_INCONSISTENT.
+ * pthread_mutex_destroy.c: Allow destroying of inconsistent mutexes.
+ * pthread_mutex_lock.c: Reimplement robust mutex handling.
+ * pthread_mutex_trylock.c: Likewise.
+ * pthread_mutex_timedlock.c: Likewise.
+ * pthread_mutex_unlock.c: Likewise.
+ * sysdeps/unix/sysv/linux/pthread_mutex_cond_lock.c: Likewise.
+ * sysdeps/unix/sysv/linux/Makefile (gen-as-const-headers): Add
+ lowlevelrobustlock.sym.
+ * sysdeps/unix/sysv/linux/lowlevelrobustlock.sym: New file.
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h: Add lll_robust_mutex_*
+ definitions.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelrobustlock.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i586/lowlevelrobustlock.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i686/lowlevelrobustlock.S: New file.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S: New file.
+
+2006-02-12 Ulrich Drepper <drepper@redhat.com>
+
+ * allocatestack.c (allocate_stack): Initialize robust_list.
+ * init.c (__pthread_initialize_minimal_internal): Likewise.
+ * descr.h (struct xid_command): Pretty printing.
+ (struct pthread): Use __pthread_list_t or __pthread_slist_t for
+ robust_list. Adjust macros.
+ * pthread_create.c (start_thread): Adjust robust_list handling.
+ * phtread_mutex_unlock.c: Don't allow unlocking from any thread
+ but the owner for all robust mutex types.
+ * sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h: Define
+ __pthread_list_t and __pthread_slist_t. Use them in pthread_mutex_t.
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h: Likewise.
+ * sysdeps/pthread/pthread.h: Adjust mutex initializers.
+
+ * sysdeps/unix/sysv/linux/i386/not-cancel.h: Define openat_not_cancel,
+ openat_not_cancel_3, openat64_not_cancel, and openat64_not_cancel_3.
+
+2006-02-08 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h (lll_futex_wait,
+ lll_futex_timedwait, lll_wait_tid): Add "memory" clobber.
+
+2006-01-20 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/unix/sysv/linux/sh/lowlevellock.h (lll_futex_wait):
+ Return status.
+ (lll_futex_timed_wait): Define.
+
+2006-01-19 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-cancel4.c: Test ppoll.
+
+2006-01-18 Andreas Jaeger <aj@suse.de>
+
+ [BZ #2167]
+ * sysdeps/unix/sysv/linux/mips/bits/pthreadtypes.h
+ (pthread_mutex_t): Follow changes for other archs. Based on patch
+ by Jim Gifford <patches@jg555.com>.
+
+2006-01-13 Richard Henderson <rth@redhat.com>
+
+ * sysdeps/alpha/tls.h (tcbhead_t): Rename member to __private.
+
+2006-01-10 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/alpha/jmpbuf-unwind.h: File moved to main source tree.
+ * sysdeps/i386/jmpbuf-unwind.h: Likewise.
+ * sysdeps/mips/jmpbuf-unwind.h: Likewise.
+ * sysdeps/powerpc/jmpbuf-unwind.h: Likewise.
+ * sysdeps/s390/jmpbuf-unwind.h: Likewise.
+ * sysdeps/sh/jmpbuf-unwind.h: Likewise.
+ * sysdeps/sparc/sparc32/jmpbuf-unwind.h: Likewise.
+ * sysdeps/sparc/sparc64/jmpbuf-unwind.h: Likewise.
+ * sysdeps/x86_64/jmpbuf-unwind.h: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/jmpbuf-unwind.h: Likewise.
+
+2006-01-09 Roland McGrath <roland@redhat.com>
+
+ * tst-initializers1-c89.c: New file.
+ * tst-initializers1-c99.c: New file.
+ * tst-initializers1-gnu89.c: New file.
+ * tst-initializers1-gnu99.c: New file.
+ * Makefile (tests): Add them.
+ (CFLAGS-tst-initializers1-c89.c): New variable.
+ (CFLAGS-tst-initializers1-c99.c): New variable.
+ (CFLAGS-tst-initializers1-gnu89.c): New variable.
+ (CFLAGS-tst-initializers1-gnu99.c): New variable.
+
+ * sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h (pthread_mutex_t):
+ Use __extension__ on anonymous union definition.
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/sparc/bits/pthreadtypes.h: Likewise.
+
+2006-01-08 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h (pthread_mutex_t):
+ Don't give the union a name because it changes the mangled name.
+ Instead name the struct for __data.
+ * sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h (pthread_mutex_t):
+ Likewise.
+ * sysdeps/unix/sysv/linux/sparc/bits/pthreadtypes.h (pthread_mutex_t):
+ Likewise.
+
+2006-01-09 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/sparc/sparc64/jmpbuf-unwind.h (_JMPBUF_UNWINDS_ADJ): Add
+ stack bias to mc_ftp field.
+
+2006-01-07 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/aio_misc.h (AIO_MISC_WAIT): Work around gcc
+ being too clever and reloading the futex value where it shouldn't.
+
+2006-01-06 Ulrich Drepper <drepper@redhat.com>
+
+ * descr.h [!__PTHREAD_MUTEX_HAVE_PREV] (DEQUEUE_MUTEX): Use
+ correct type.
+
+2006-01-06 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/sparc/sparc64/sysdep-cancel.h (PSEUDO):
+ Add cfi directives.
+
+2006-01-06 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/ia64/tls.h (tcbhead_t): Rename private member to __private.
+ * sysdeps/ia64/tcb-offsets.sym: Adjust for private->__private
+ rename in tcbhead_t.
+
+ * sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h (pthread_mutex_t):
+ Don't give the union a name because it changes the mangled name.
+ Instead name the struct for __data.
+ * sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h: Likewise.
+ * pthread_create.c (start_thread): Adjust robust mutex free loop.
+ * descr.h (ENQUEUE_MUTEX, DEQUEUE_MUTEX): Adjust.
+
+2006-01-05 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h (lll_futex_wait):
+ Return status.
+ (lll_futex_timed_wait): Define.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h: Likewise.
+ * sysdeps/pthread/aio_misc.h: New file.
+
+2006-01-03 Joseph S. Myers <joseph@codesourcery.com>
+
+ * Makefile ($(objpfx)$(multidir)): Use mkdir -p.
+
+2006-01-03 Steven Munroe <sjmunroe@us.ibm.com>
+
+ * sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h
+ (PSEUDO): Remove redundant cfi_startproc and cfi_endproc directives.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h: Likewise.
+
+2006-01-04 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-cancel24.cc: Use C headers instead of C++ headers.
+
+2006-01-03 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/sparc/lowlevellock.h: Remove #error for
+ sparc-linux configured glibc.
+ (lll_futex_wake_unlock): Define to 1 for sparc-linux configured glibc.
+ (__lll_mutex_trylock, __lll_mutex_cond_trylock, __lll_mutex_lock,
+ __lll_mutex_cond_lock, __lll_mutex_timedlock): Use
+ atomic_compare_and_exchange_val_24_acq instead of
+ atomic_compare_and_exchange_val_acq.
+ (lll_mutex_unlock, lll_mutex_unlock_force): Use atomic_exchange_24_rel
+ instead of atomic_exchange_rel.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/lowlevellock.c: New file.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/pthread_barrier_init.c: New
+ file.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/pthread_barrier_wait.c: New
+ file.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/sem_init.c: New file.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/sem_post.c: New file.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/sem_timedwait.c: New file.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/sem_trywait.c: New file.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/sem_wait.c: New file.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/pthread_barrier_init.c:
+ New file.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/pthread_barrier_wait.c:
+ New file.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_init.c: New file.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_post.c: New file.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_timedwait.c: New
+ file.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_trywait.c: New
+ file.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_wait.c: New file.
+
+2006-01-03 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/pthread.h [__WORDSIZE==64]: Don't use cast in
+ mutex initializers.
+
+2006-01-02 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/sparc/tls.h (tcbhead_t): Add pointer_guard field.
+ (THREAD_GET_POINTER_GUARD, THREAD_SET_POINTER_GUARD,
+ THREAD_COPY_POINTER_GUARD): Define.
+ * sysdeps/sparc/tcb-offsets.sym (POINTER_GUARD): Define.
+ * sysdeps/sparc/sparc64/jmpbuf-unwind.h: Revert 2005-12-27 changes.
+
+2006-01-01 Ulrich Drepper <drepper@redhat.com>
+
+ * version.c: Update copyright year.
+
+2005-12-29 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/unix/sysv/linux/sh/sysdep-cancel.h: Remove explicit
+ .eh_frame section, use cfi_* directives.
+ * sysdeps/unix/sysv/linux/sh/lowlevellock.S: Add cfi instrumentation.
+
+2005-12-30 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/ia64/jmpbuf-unwind.h: Undo last change for
+ now.
+
+2005-12-29 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/sigaction.c: Removed.
+ * sigaction.c: New file.
+ * sysdeps/unix/sysv/linux/Makefile: Define CFLAGS-sigaction.c.
+
+2005-12-28 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-signal7.
+ * tst-signal7.c: New file.
+
+2005-12-27 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/x86_64/jmpbuf-unwind.h (_jmpbuf_sp): New inline function.
+ (_JMPBUF_UNWINDS_ADJ): Use it, to PTR_DEMANGLE before comparison.
+ * sysdeps/alpha/jmpbuf-unwind.h: Likewise.
+ * sysdeps/i386/jmpbuf-unwind.h: Likewise.
+ * sysdeps/mips/jmpbuf-unwind.h: Likewise.
+ * sysdeps/powerpc/jmpbuf-unwind.h: Likewise.
+ * sysdeps/s390/jmpbuf-unwind.h: Likewise.
+ * sysdeps/sh/jmpbuf-unwind.h: Likewise.
+ * sysdeps/sparc/sparc32/jmpbuf-unwind.h: Likewise.
+ * sysdeps/sparc/sparc64/jmpbuf-unwind.h: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/jmpbuf-unwind.h: Likewise.
+
+2005-12-27 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h: Add __next
+ and __prev field to pthread_mutex_t.
+ * sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/sparc/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h: Add __next field
+ to pthread_mutex_t.
+
+2005-12-26 Ulrich Drepper <drepper@redhat.com>
+
+ * pthreadP.h: Define PTHREAD_MUTEX_ROBUST_PRIVATE_NP,
+ PTHREAD_MUTEX_ROBUST_PRIVATE_RECURSIVE_NP,
+ PTHREAD_MUTEX_ROBUST_PRIVATE_ERRORCHECK_NP,
+ PTHREAD_MUTEX_ROBUST_PRIVATE_ADAPTIVE_NP,
+ PTHREAD_MUTEXATTR_FLAG_ROBUST, PTHREAD_MUTEXATTR_FLAG_PSHARED,
+ and PTHREAD_MUTEXATTR_FLAG_BITS.
+ * descr.h (struct pthread): Add robust_list field and define
+ ENQUEUE_MUTEX and DEQUEUE_MUTEX macros.
+ * pthread_mutexattr_getrobust.c: New file.
+ * pthread_mutexattr_setrobust.c: New file.
+ * pthread_mutex_consistent.c: New file.
+ * sysdeps/pthread/pthread.h: Declare pthread_mutexattr_getrobust,
+ pthread_mutexattr_setrobust, and pthread_mutex_consistent.
+ Define PTHREAD_MUTEX_STALLED_NP and PTHREAD_MUTEX_ROBUST_NP.
+ Adjust pthread_mutex_t initializers.
+ * nptl/sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h: Add __next
+ field to pthread_mutex_t.
+ * nptl/sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h: Add __next
+ and __prev field to pthread_mutex_t.
+ * Versions [GLIBC_2.4]: Export pthread_mutexattr_getrobust_np,
+ pthread_mutexattr_setrobust_np, and pthread_mutex_consistent_np.
+ * pthread_mutexattr_getpshared.c: Use PTHREAD_MUTEXATTR_FLAG_PSHARED
+ and PTHREAD_MUTEXATTR_FLAG_BITS macros instead of magic numbers.
+ * pthread_mutexattr_gettype.c: Likewise.
+ * pthread_mutexattr_setpshared.c: Likewise.
+ * pthread_mutexattr_settype.c: Likewise.
+ * pthread_mutex_init.c: Reject robust+pshared attribute for now.
+ Initialize mutex kind according to robust flag.
+ * pthread_mutex_lock.c: Implement local robust mutex.
+ * pthread_mutex_timedlock.c: Likewise.
+ * pthread_mutex_trylock.c: Likewise.
+ * pthread_mutex_unlock.c: Likewise.
+ * pthread_create.c (start_thread): Mark robust mutexes which remained
+ locked as dead.
+ * tst-robust1.c: New file.
+ * tst-robust2.c: New file.
+ * tst-robust3.c: New file.
+ * tst-robust4.c: New file.
+ * tst-robust5.c: New file.
+ * tst-robust6.c: New file.
+ * tst-robust7.c: New file.
+ * Makefile (libpthread-routines): Add pthread_mutexattr_getrobust,
+ pthread_mutexattr_setrobust, and pthread_mutex_consistent.
+ (tests): Add tst-robust1, tst-robust2, tst-robust3, tst-robust4,
+ tst-robust5, tst-robust6, and tst-robust7.
+
+ * tst-typesizes.c: New file.
+ * Makefile (tests): Add tst-typesizes.
+
+ * tst-once3.c: More debug output.
+
+2005-12-24 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread_mutex_trylock.c (__pthread_mutex_trylock): Add break
+ missing after last change.
+
+ * version.c: Update copyright year.
+
+2005-12-23 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread_mutex_destroy.c: Set mutex type to an invalid value.
+ * pthread_mutex_lock.c: Return EINVAL for invalid mutex type.
+ * pthread_mutex_trylock.c: Likewise.
+ * pthread_mutex_timedlock.c: Likewise.
+ * pthread_mutex_unlock.c: Likewise.
+
+2005-12-22 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/pthread/sigaction.c: Use "" instead of <> to include self,
+ so that #include_next's search location is not reset to the -I..
+ directory where <nptl/...> can be found.
+
+2005-12-22 Ulrich Drepper <drepper@redhat.com>
+
+ [BZ #1913]
+ * sysdeps/unix/sysv/linux/i386/i486/sem_wait.S (__new_sem_wait):
+ Fix unwind info. Remove useless branch prediction prefix.
+ * tst-cancel24.cc: New file.
+ * Makefile: Add rules to build and run tst-cancel24.
+
+2005-12-21 Roland McGrath <roland@redhat.com>
+
+ * libc-cancellation.c: Use <> rather than "" #includes.
+ * pt-cleanup.c: Likewise.
+ * pthread_create.c: Likewise.
+ * pthread_join.c: Likewise.
+ * pthread_timedjoin.c: Likewise.
+ * pthread_tryjoin.c: Likewise.
+ * sysdeps/unix/sysv/linux/libc_pthread_init.c: Likewise.
+ * sysdeps/unix/sysv/linux/register-atfork.c: Likewise.
+ * sysdeps/unix/sysv/linux/unregister-atfork.c: Likewise.
+ * unwind.c: Likewise.
+
+2005-12-19 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/sh/tcb-offsets.sym: Add POINTER_GUARD.
+ * sysdeps/sh/tls.h (tcbhead_t): Remove private and add pointer_guard.
+ (THREAD_GET_POINTER_GUARD, THREAD_SET_POINTER_GUARD,
+ THREAD_COPY_POINTER_GUARD): Define.
+
+2005-12-19 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/ia64/tls.h (TLS_PRE_TCB_SIZE): Make room for 2 uintptr_t's
+ rather than one.
+ (THREAD_GET_POINTER_GUARD, THREAD_SET_POINTER_GUARD,
+ THREAD_COPY_POINTER_GUARD): Define.
+ * sysdeps/powerpc/tcb-offsets.sym (POINTER_GUARD): Add.
+ * sysdeps/powerpc/tls.h (tcbhead_t): Add pointer_guard field.
+ (THREAD_GET_POINTER_GUARD, THREAD_SET_POINTER_GUARD,
+ THREAD_COPY_POINTER_GUARD): Define.
+ * sysdeps/s390/tcb-offsets.sym (STACK_GUARD): Add.
+ * sysdeps/s390/tls.h (THREAD_GET_POINTER_GUARD,
+ THREAD_SET_POINTER_GUARD, THREAD_COPY_POINTER_GUARD): Define.
+ * sysdeps/unix/sysv/linux/ia64/__ia64_longjmp.S (__ia64_longjmp):
+ Use PTR_DEMANGLE for B0 if defined.
+
+2005-12-17 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread_create.c (__pthread_create_2_1): Use
+ THREAD_COPY_POINTER_GUARD if available.
+ * sysdeps/i386/tcb-offsets.sym: Add POINTER_GUARD.
+ * sysdeps/x86_64/tcb-offsets.sym: Likewise.
+ * sysdeps/i386/tls.h (tcbhead_t): Add pointer_guard.
+ Define THREAD_SET_POINTER_GUARD and THREAD_COPY_POINTER_GUARD.
+ * sysdeps/x86_64/tls.h: Likewise.
+
+2005-12-15 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/unix/sysv/linux/mq_notify.c: Don't use sysdeps/generic.
+
+2005-12-13 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/sigfillset.c: Adjust for files moved out of
+ sysdeps/generic.
+ * errno-loc.c: New file.
+
+2005-12-12 Roland McGrath <roland@redhat.com>
+
+ * init.c (__pthread_initialize_minimal_internal): Do __static_tls_size
+ adjustments before choosing stack size. Update minimum stack size
+ calculation to match allocate_stack change.
+
+2005-12-12 Ulrich Drepper <drepper@redhat.com>
+
+ * allocatestack.c (allocate_stack): Don't demand that there is an
+ additional full page available on the stack beside guard, TLS, the
+ minimum stack.
+
+2005-11-24 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h
+ (__cleanup_fct_attribute): Use __regparm__ not regparm.
+
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h: When
+ compiling 32-bit code we must define __cleanup_fct_attribute.
+
+005-11-24 Jakub Jelinek <jakub@redhat.com>
+
+ [BZ #1920]
+ * sysdeps/pthread/pthread.h (__pthread_unwind_next): Use
+ __attribute__ instead of __attribute.
+ * sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h
+ (__cleanup_fct_attribute): Likewise.
+
+2005-11-17 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/pthread/unwind-forcedunwind.c (pthread_cancel_init): Put
+ a write barrier before writing libgcc_s_getcfa.
+
+2005-11-06 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/configure: Removed.
+
+2005-11-05 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/ia64/pt-initfini.c: Remove trace of
+ optional init_array/fini_array support.
+
+2005-10-24 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/sem_trywait.S: Remove unnecessary
+ versioned_symbol use.
+
+2005-10-16 Roland McGrath <roland@redhat.com>
+
+ * init.c (__pthread_initialize_minimal_internal): Even when using a
+ compile-time default stack size, apply the minimum that allocate_stack
+ will require, and round up to page size.
+
+2005-10-10 Daniel Jacobowitz <dan@codesourcery.com>
+
+ * Makefile ($(test-modules)): Remove static pattern rule.
+
+2005-10-14 Jakub Jelinek <jakub@redhat.com>
+ Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/pthread_once.S: Fix stack
+ alignment in callback function.
+ * Makefile: Add rules to build and run tst-align3.
+ * tst-align3.c: New file.
+
+2005-10-03 Jakub Jelinek <jakub@redhat.com>
+
+ * allocatestack.c (setxid_signal_thread): Add
+ INTERNAL_SYSCALL_DECL (err).
+
+2005-10-02 Jakub Jelinek <jakub@redhat.com>
+
+ * allocatestack.c (setxid_signal_thread): Need to use
+ atomic_compare_and_exchange_bool_acq.
+
+2005-10-01 Ulrich Drepper <drepper@redhat.com>
+ Jakub Jelinek <jakub@redhat.com>
+
+ * descr.h: Define SETXID_BIT and SETXID_BITMASK. Adjust
+ CANCEL_RESTMASK.
+ (struct pthread): Move specific_used field to avoid padding.
+ Add setxid_futex field.
+ * init.c (sighandler_setxid): Reset setxid flag and release the
+ setxid futex.
+ * allocatestack.c (setxid_signal_thread): New function. Broken
+ out of the bodies of the two loops in __nptl_setxid. For undetached
+ threads check whether they are exiting and if yes, don't send a signal.
+ (__nptl_setxid): Simplify loops by using setxid_signal_thread.
+ * pthread_create.c (start_thread): For undetached threads, check
+ whether setxid bit is set. If yes, wait until signal has been
+ processed.
+
+ * allocatestack.c (STACK_VARIABLES): Initialize them.
+ * pthread_create.c (__pthread_create_2_1): Initialize pd.
+
+2004-09-02 Jakub Jelinek <jakub@redhat.com>
+
+ * pthread_cond_destroy.c (__pthread_cond_destroy): If there are
+ waiters, awake all waiters on the associated mutex.
+
+2005-09-22 Roland McGrath <roland@redhat.com>
+
+ * perf.c [__x86_64__] (HP_TIMING_NOW): New macro (copied from
+ ../sysdeps/x86_64/hp-timing.h).
+
+2005-08-29 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h (FUTEX_WAKE_OP,
+ FUTEX_OP_CLEAR_WAKE_IF_GT_ONE): Define.
+ (lll_futex_wake_unlock): Define.
+ * sysdeps/unix/sysv/linux/alpha/lowlevellock.h (FUTEX_WAKE_OP,
+ FUTEX_OP_CLEAR_WAKE_IF_GT_ONE): Define.
+ (lll_futex_wake_unlock): Define.
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.h (FUTEX_WAKE_OP,
+ FUTEX_OP_CLEAR_WAKE_IF_GT_ONE): Define.
+ (lll_futex_wake_unlock): Define.
+ * sysdeps/unix/sysv/linux/s390/lowlevellock.h (FUTEX_WAKE_OP,
+ FUTEX_OP_CLEAR_WAKE_IF_GT_ONE): Define.
+ (lll_futex_wake_unlock): Define.
+ * sysdeps/unix/sysv/linux/sparc/lowlevellock.h (FUTEX_WAKE_OP,
+ FUTEX_OP_CLEAR_WAKE_IF_GT_ONE): Define.
+ (lll_futex_wake_unlock): Define.
+ * sysdeps/pthread/pthread_cond_signal.c (__pthread_cond_signal): Use
+ lll_futex_wake_unlock.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_signal.S
+ (FUTEX_WAKE_OP, FUTEX_OP_CLEAR_WAKE_IF_GT_ONE): Define.
+ (__pthread_cond_signal): Use FUTEX_WAKE_OP.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
+ (FUTEX_WAKE_OP, FUTEX_OP_CLEAR_WAKE_IF_GT_ONE): Define.
+ (__pthread_cond_signal): Use FUTEX_WAKE_OP.
+
+2005-09-05 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/unix/sysv/linux/sh/lowlevellock.S (__lll_mutex_lock_wait):
+ Fix typo in register name.
+
+2005-08-23 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/timer_routines.c (timer_helper_thread):
+ Use __sigfillset. Document that sigfillset does the right thing wrt
+ to SIGSETXID.
+
+2005-07-11 Jakub Jelinek <jakub@redhat.com>
+
+ [BZ #1102]
+ * sysdeps/pthread/pthread.h (PTHREAD_MUTEX_INITIALIZER,
+ PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP,
+ PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP,
+ PTHREAD_MUTEX_ADAPTIVE_NP, PTHREAD_RWLOCK_INITIALIZER,
+ PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP,
+ PTHREAD_COND_INITIALIZER): Supply zeros for all fields
+ in the structure.
+ * Makefile (tests): Add tst-initializers1.
+ (CFLAGS-tst-initializers1.c): Set.
+ * tst-initializers1.c: New test.
+
+2005-07-11 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h (pthread_rwlock_t):
+ Make sure __flags are located at offset 48 from the start of the
+ structure.
+
+2005-07-02 Roland McGrath <roland@redhat.com>
+
+ * Makeconfig: Comment fix.
+
+2005-07-05 Jakub Jelinek <jakub@redhat.com>
+
+ * descr.h (PTHREAD_STRUCT_END_PADDING): Define.
+ * sysdeps/ia64/tls.h (TLS_PRE_TCB_SIZE): If PTHREAD_STRUCT_END_PADDING
+ is smaller than 8 bytes, increase TLS_PRE_TCB_SIZE by 16 bytes.
+ (THREAD_SYSINFO, THREAD_SELF, DB_THREAD_SELF): Don't assume
+ TLS_PRE_TCB_SIZE is sizeof (struct pthread).
+ (THREAD_SET_STACK_GUARD, THREAD_COPY_STACK_GUARD): Define.
+ * sysdeps/ia64/tcb-offsets.sym (PID, TID, MULTIPLE_THREADS_OFFSET):
+ Use TLS_PRE_TCB_SIZE instead of sizeof (struct pthread).
+ * sysdeps/unix/sysv/linux/ia64/createthread.c (TLS_VALUE): Don't
+ assume TLS_PRE_TCB_SIZE is sizeof (struct pthread).
+
+2005-06-25 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/i386/tls.h (tcbhead_t): Add stack_guard field.
+ (THREAD_SET_STACK_GUARD, THREAD_COPY_STACK_GUARD): Define.
+ * sysdeps/x86_64/tls.h (tcbhead_t): Add sysinfo and stack_guard
+ fields.
+ (THREAD_SET_STACK_GUARD, THREAD_COPY_STACK_GUARD): Define.
+ * sysdeps/s390/tls.h (tcbhead_t): Add stack_guard
+ field. Put in sysinfo field unconditionally.
+ (THREAD_SET_STACK_GUARD, THREAD_COPY_STACK_GUARD): Define.
+ * sysdeps/powerpc/tls.h (tcbhead_t): Add stack_guard field.
+ (THREAD_SET_STACK_GUARD, THREAD_COPY_STACK_GUARD): Define.
+ * sysdeps/sparc/tls.h (tcbhead_t): Add sysinfo and stack_guard
+ fields.
+ (THREAD_SET_STACK_GUARD, THREAD_COPY_STACK_GUARD): Define.
+ * pthread_create.c (__pthread_create_2_1): Use
+ THREAD_COPY_STACK_GUARD macro.
+ * Makefile: Add rules to build and run tst-stackguard1{,-static}
+ tests.
+ * tst-stackguard1.c: New file.
+ * tst-stackguard1-static.c: New file.
+
+2005-06-14 Alan Modra <amodra@bigpond.net.au>
+
+ * sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h (PSEUDO):
+ Invoke CGOTSETUP and CGOTRESTORE.
+ (CGOTSETUP, CGOTRESTORE): Define.
+
+2005-05-29 Richard Henderson <rth@redhat.com>
+
+ * tst-cancel4.c (WRITE_BUFFER_SIZE): New.
+ (tf_write, tf_writev): Use it.
+ (do_test): Use socketpair instead of pipe. Set SO_SNDBUF to
+ the system minimum.
+
+2005-05-23 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h
+ [IS_IN_librt] (CENABLE, CDISABLE): Use JUMPTARGET instead of
+ __librt_*_asynccancel@local.
+
+2005-05-17 Alan Modra <amodra@bigpond.net.au>
+
+ * sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h: Delete
+ all occurrences of JUMPTARGET. Instead append @local to labels.
+
+2005-05-20 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/i386/tls.h (TLS_INIT_TCB_SIZE, TLS_INIT_TCB_ALIGN): Define to
+ size/alignment of struct pthread rather than tcbhead_t.
+ * sysdeps/x86_64/tls.h (TLS_INIT_TCB_SIZE, TLS_INIT_TCB_ALIGN):
+ Likewise.
+ * sysdeps/s390/tls.h (TLS_INIT_TCB_SIZE, TLS_INIT_TCB_ALIGN):
+ Likewise.
+ * sysdeps/sparc/tls.h (TLS_INIT_TCB_SIZE, TLS_INIT_TCB_ALIGN):
+ Likewise.
+
+2005-05-19 Richard Henderson <rth@redhat.com>
+
+ * sysdeps/ia64/pthread_spin_lock.c (pthread_spin_lock): Use
+ __sync_val_compare_and_swap, not explicit _si variant.
+ * sysdeps/ia64/pthread_spin_trylock.c (pthread_spin_trylock): Likewise.
+
+2005-05-03 Ulrich Drepper <drepper@redhat.com>
+
+ [BZ #915]
+ * sysdeps/pthread/pthread.h: Avoid empty initializers.
+
+2005-05-03 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/sysdep-cancel.h: Remove explicit
+ .eh_frame section, use cfi_* directives.
+
+2005-04-27 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/pthread_getcpuclockid.c: Use <> instead
+ of "" includes.
+
+2005-04-27 Ulrich Drepper <drepper@redhat.com>
+
+ [BZ #1075]
+ * tst-cancel17.c (do_test): Add arbitrary factor to make sure
+ aio_write blocks.
+
+2005-04-27 Roland McGrath <roland@redhat.com>
+
+ * Makefile (tests): Remove tst-clock2.
+
+ * sysdeps/unix/sysv/linux/timer_create.c (timer_create): Handle
+ CLOCK_PROCESS_CPUTIME_ID and CLOCK_PROCESS_THREAD_ID specially,
+ translating to the kernel clockid_t for our own process/thread clock.
+
+ * sysdeps/unix/sysv/linux/pthread_getcpuclockid.c: New file.
+
+2005-04-15 Jakub Jelinek <jakub@redhat.com>
+
+ * old_pthread_cond_init.c: Include <errno.h>.
+ (__pthread_cond_init_2_0): Fail with EINVAL if COND_ATTR is
+ process shared or uses clock other than CLOCK_REALTIME.
+ * pthread_cond_init.c (__pthread_cond_init): Remove bogus comment.
+
+2005-04-13 David S. Miller <davem@davemloft.net>
+
+ * sysdeps/sparc/sparc64/jmpbuf-unwind.h: New file.
+ * sysdeps/sparc/sparc64/clone.S: New file.
+
+2005-04-05 Jakub Jelinek <jakub@redhat.com>
+
+ [BZ #1102]
+ * sysdeps/pthread/pthread.h (__pthread_cleanup_routine): Use
+ __inline instead of inline.
+ * sysdeps/pthread/bits/libc-lock.h (__libc_cleanup_routine): Likewise.
+
+2005-03-31 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S: Use
+ functionally equivalent, but shorter instructions.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S:
+ Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/sem_wait.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_once.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S:
+ Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/sem_post.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S: Likewise.
+
+2005-03-28 Daniel Jacobowitz <dan@codesourcery.com>
+
+ * sysdeps/mips/Makefile: New file.
+ * sysdeps/mips/nptl-sysdep.S: New file.
+ * sysdeps/mips/tcb-offsets.sym: New file.
+ * sysdeps/mips/pthread_spin_lock.S: New file.
+ * sysdeps/mips/pthread_spin_trylock.S: New file.
+ * sysdeps/mips/pthreaddef.h: New file.
+ * sysdeps/mips/tls.h: New file.
+ * sysdeps/mips/jmpbuf-unwind.h: New file.
+ * sysdeps/unix/sysv/linux/mips/lowlevellock.h: New file.
+ * sysdeps/unix/sysv/linux/mips/bits/pthreadtypes.h: New file.
+ * sysdeps/unix/sysv/linux/mips/bits/semaphore.h: New file.
+ * sysdeps/unix/sysv/linux/mips/pthread_once.c: New file.
+ * sysdeps/unix/sysv/linux/mips/fork.c: New file.
+ * sysdeps/unix/sysv/linux/mips/pt-vfork.S: New file.
+ * sysdeps/unix/sysv/linux/mips/vfork.S: New file.
+ * sysdeps/unix/sysv/linux/mips/clone.S: New file.
+ * sysdeps/unix/sysv/linux/mips/createthread.c: New file.
+ * sysdeps/unix/sysv/linux/mips/sysdep-cancel.h: New file.
+
+2005-03-23 Ulrich Drepper <drepper@redhat.com>
+
+ [BZ #1112]
+ * pthread_create.c (__pthread_create_2_1): Rename syscall error
+ variable to scerr.
+
+2005-03-10 Jakub Jelinek <jakub@redhat.com>
+
+ * tst-getpid1.c (do_test): Align stack passed to clone{2,}.
+
+2005-02-25 Roland McGrath <roland@redhat.com>
+
+ * alloca_cutoff.c: Correct license text.
+ * tst-unload.c: Likewise.
+ * sysdeps/pthread/allocalim.h: Likewise.
+ * sysdeps/pthread/pt-initfini.c: Likewise.
+ * sysdeps/pthread/bits/libc-lock.h: Likewise.
+ * sysdeps/pthread/bits/sigthread.h: Likewise.
+ * sysdeps/unix/sysv/linux/bits/local_lim.h: Likewise.
+ * sysdeps/unix/sysv/linux/bits/posix_opt.h: Likewise.
+
+2005-02-16 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/pthread/pthread-functions.h (struct pthread_functions):
+ Use unsigned int * for ptr_nthreads.
+
+2005-02-14 Alan Modra <amodra@bigpond.net.au>
+
+ [BZ #721]
+ * sysdeps/powerpc/tcb-offsets.sym (thread_offsetof): Redefine to suit
+ gcc4.
+
+2005-02-07 Richard Henderson <rth@redhat.com>
+
+ [BZ #787]
+ * sysdeps/pthread/pthread.h (__sigsetjmp): Use pointer as first
+ argument.
+
+2004-11-03 Marcus Brinkmann <marcus@gnu.org>
+
+ * sysdeps/generic/lowlevellock.h (__generic_mutex_unlock): Fix
+ order of arguments in invocation of atomic_add_zero.
+
+2005-01-26 Jakub Jelinek <jakub@redhat.com>
+
+ [BZ #737]
+ * sysdeps/unix/sysv/linux/i386/i486/sem_trywait.S (__new_sem_trywait):
+ Use direct %gs segment access or, if NO_TLS_DIRECT_SEG_REFS,
+ at least gotntpoff relocation and addition.
+ * sysdeps/unix/sysv/linux/i386/i486/sem_timedwait.S (sem_timedwait):
+ Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/sem_post.S (__new_sem_post):
+ Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/sem_wait.S (__new_sem_wait):
+ Likewise.
+
+2005-01-06 Ulrich Drepper <drepper@redhat.com>
+
+ * allocatestack.c (init_one_static_tls): Adjust initialization of DTV
+ entry for static tls deallocation fix.
+ * sysdeps/alpha/tls.h (dtv_t): Change pointer type to be struct which
+ also contains information whether the memory pointed to is static
+ TLS or not.
+ * sysdeps/i386/tls.h: Likewise.
+ * sysdeps/ia64/tls.h: Likewise.
+ * sysdeps/powerpc/tls.h: Likewise.
+ * sysdeps/s390/tls.h: Likewise.
+ * sysdeps/sh/tls.h: Likewise.
+ * sysdeps/sparc/tls.h: Likewise.
+ * sysdeps/x86_64/tls.h: Likewise.
+
+2004-12-27 Ulrich Drepper <drepper@redhat.com>
+
+ * init.c (__pthread_initialize_minimal_internal): Use __sigemptyset.
+
+2004-12-21 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/i386/tls.h (CALL_THREAD_FCT): Maintain 16 byte alignment of
+ %esp.
+ * Makefile (tests): Add tst-align2.
+ * tst-align2.c: New test.
+ * sysdeps/i386/Makefile (CFLAGS-tst-align{,2}.c): Add
+ -mpreferred-stack-boundary=4.
+
+2004-12-18 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/bits/local_lim.h:
+ New file removed withdrawn for the moment.
+
+2004-12-17 Richard Henderson <rth@redhat.com>
+
+ * sysdeps/unix/sysv/linux/alpha/clone.S: New file.
+ * sysdeps/alpha/tcb-offsets.sym (TID_OFFSET): New.
+
+2004-12-16 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/bits/local_lim.h: New file.
+ Increased PTHREAD_STACK_MIN.
+
+ * tst-context1.c (stacks): Use bigger stack size.
+
+2004-12-16 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/sparc/sparc32/clone.S: New file.
+ * sysdeps/sparc/tcb-offsets.sym: Add TID.
+
+2004-12-15 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/s390/s390-32/clone.S: New file.
+ * sysdeps/unix/sysv/linux/s390/s390-64/clone.S: New file.
+ * sysdeps/s390/tcb-offsets.sym (TID): Add.
+
+2004-12-15 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S: New file.
+
+2004-12-14 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/powerpc/tcb-offsets.sym: Add TID.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S: New file.
+
+ * tst-getpid1.c: If child crashes, report this first. Print which
+ signal.
+
+2004-12-09 Ulrich Drepper <drepper@redhat.com>
+
+ * init.c (__pthread_initialize_minimal_internal): Also unblock
+ SIGSETXID.
+
+2004-12-01 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/bits/posix_opt.h (_POSIX_CPUTIME,
+ _POSIX_THREAD_CPUTIME): Define to 0.
+ * sysdeps/pthread/timer_create.c (timer_create): Remove unused code
+ handling CLOCK_PROCESS_CPUTIME_ID and CLOCK_THREAD_CPUTIME_ID.
+ * sysdeps/pthread/timer_routines.c (__timer_signal_thread_pclk,
+ __timer_signal_thread_tclk): Remove.
+ (init_module): Remove their initialization.
+ (thread_cleanup): Remove their cleanup assertions.
+ * sysdeps/pthread/posix-timer.h (__timer_signal_thread_pclk,
+ __timer_signal_thread_tclk): Remove.
+ * sysdeps/unix/sysv/linux/i386/bits/posix_opt.h: Removed.
+ * sysdeps/unix/sysv/linux/ia64/bits/posix_opt.h: Removed.
+ * sysdeps/unix/sysv/linux/x86_64/bits/posix_opt.h: Removed.
+
+2004-12-07 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/ia64/tcb-offsets.sym (TID): Add.
+ * sysdeps/unix/sysv/linux/ia64/clone2.S: New file.
+
+ * Makefile (tests): Add tst-getpid2.
+ * tst-getpid1.c (TEST_CLONE_FLAGS): Define.
+ (do_test): Use it. Use __clone2 instead of clone on ia64.
+ * tst-getpid2.c: New test.
+
+2004-12-07 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/unix/sysv/linux/sh/clone.S: New file.
+
+2004-12-04 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-getpid1.
+ * tst-getpid1.c: New file.
+ * sysdeps/unix/sysv/linux/i386/clone.S: New file.
+ * sysdeps/unix/sysv/linux/x86_64/clone.S: New file.
+
+2004-12-02 Roland McGrath <roland@redhat.com>
+
+ * Makefile (libpthread-nonshared): Variable removed.
+ ($(objpfx)libpthread_nonshared.a): Target removed.
+ ($(inst_libdir)/libpthread_nonshared.a): Likewise.
+ These are now handled by generic magic from
+ libpthread-static-only-routines being set.
+
+2004-11-27 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/bits/posix_opt.h (_POSIX_PRIORITIZED_IO,
+ _POSIX2_CHAR_TERM, _POSIX_THREAD_PRIO_INHERIT,
+ _POSIX_THREAD_PRIO_PROTECT): Define.
+ * sysdeps/unix/sysv/linux/i386/bits/posix_opt.h: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/bits/posix_opt.h: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/bits/posix_opt.h: Likewise.
+
+2004-11-26 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/bits/posix_opt.h (_POSIX_ADVISORY_INFO,
+ _POSIX_SPORADIC_SERVER, _POSIX_THREAD_SPORADIC_SERVER, _POSIX_TRACE,
+ _POSIX_TRACE_EVENT_FILTER, _POSIX_TRACE_INHERIT, _POSIX_TRACE_LOG,
+ _POSIX_TYPED_MEMORY_OBJECTS, _POSIX_IPV6, _POSIX_RAW_SOCKETS): Define.
+ * sysdeps/unix/sysv/linux/i386/bits/posix_opt.h: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/bits/posix_opt.h: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/bits/posix_opt.h: Likewise.
+
+2004-11-24 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/x86_64/Makefile [nptl]: Define CFLAGS-pthread_create.c.
+
+ * Makefile (libpthread-routines): Add pthread_setschedprio.
+ * Versions [libpthread, GLIBC_2.3.4]: Add pthread_setschedprio.
+ * sysdeps/pthread/pthread.h: Declare pthread_setschedprio.
+ * pthread_setschedprio.c: New file.
+
+2004-11-20 Jakub Jelinek <jakub@redhat.com>
+
+ * pthread_create.c (pthread_cancel): Add PTHREAD_STATIC_FN_REQUIRE.
+ * pthread_cancel.c (pthread_create): Likewise.
+
+ * Makefile (libpthread-routines): Add vars.
+ * sysdeps/pthread/createthread.c (__pthread_multiple_threads): Remove.
+ * init.c (__default_stacksize, __is_smp): Remove.
+ * vars.c: New file.
+ * pthreadP.h (__find_thread_by_id): If !SHARED, add weak_function
+ and define a wrapper macro.
+ (PTHREAD_STATIC_FN_REQUIRE): Define.
+ * allocatestack.c (__find_thread_by_id): Undefine.
+ * pthread_create (__pthread_keys): Remove.
+ (pthread_mutex_lock, pthread_mutex_unlock, pthread_once,
+ pthread_key_create, pthread_setspecific, pthread_getspecific): Add
+ PTHREAD_STATIC_FN_REQUIRE.
+
+2004-11-18 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/sh/tls.h (DB_THREAD_SELF): Set the correct bias
+ parameter to REGISTER macro.
+
+2004-11-17 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/unix/sysv/linux/timer_routines.c (__start_helper_thread):
+ Make sure SIGCANCEL is blocked as well.
+
+2004-11-10 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/pthread/setxid.h: New file.
+ * sysdeps/pthread/pthread-functions.h (HAVE_PTR__NPTL_SETXID): Remove.
+ (struct xid_command): Add forward decl.
+ (struct pthread_functions): Change return type of __nptl_setxid hook
+ to int.
+ * pthreadP.h (__nptl_setxid): Change return type to int.
+ * allocatestack.c (__nptl_setxid): Call INTERNAL_SYSCALL_NCS in the
+ calling thread, return its return value and set errno on failure.
+ * descr.h (struct xid_command): Change id type to long array.
+
+ * Makefile: Add rules to build and test tst-setuid1 and
+ tst-setuid1-static.
+ * tst-setuid1.c: New test.
+ * tst-setuid1-static.c: New test.
+
+2004-11-10 Jakub Jelinek <jakub@redhat.com>
+
+ * Makefile (tests): Add tst-exit3.
+ * tst-exit3.c: New test.
+
+2004-11-09 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-exit2.
+ * tst-exit2.c: New file.
+
+2004-11-09 Roland McGrath <roland@redhat.com>
+
+ [BZ #530]
+ * sysdeps/pthread/createthread.c (do_clone): Increment __nptl_nthreads
+ here, before calling clone.
+ * pthread_create.c (start_thread): Don't do it here.
+
+2004-11-02 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/smp.h: Include <errno.h>.
+
+2004-10-29 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/unix/sysv/linux/sh/sem_timedwait.S (sem_timedwait):
+ Set ETIMEDOUT to errno when time is up. Tweak to avoid
+ assembler warning.
+
+2004-10-28 Jakub Jelinek <jakub@redhat.com>
+
+ * pthread_create.c (__pthread_create_2_1): Avoid leaking stacks
+ if sched_priority is not between minprio and maxprio.
+
+2004-10-25 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_timedwait.S
+ (__pthread_cond_timedwait): Use clock_gettime syscall if exists.
+
+ * sysdeps/unix/sysv/linux/sh/lowlevellock.S
+ (__lll_mutex_timedlock_wait): Fix a bad branch condition.
+
+2004-10-24 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/smp.h (is_smp_system): Use
+ not-cancelable I/O functions.
+
+2004-10-21 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/unix/sysv/linux/sh/lowlevellock.S
+ (__lll_mutex_timedlock_wait): If woken but cannot get the lock,
+ make sure 2 is stored in the futex and we looked at the old value.
+ Fix a few other problems to return the correct value.
+
+2004-10-14 Richard Henderson <rth@redhat.com>
+
+ * sysdeps/alpha/tcb-offsets.sym (thread_offsetof): Redefine to
+ make gcc4 happy.
+
+2004-10-06 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/jmp-unwind.c: Include pthreadP.h instead
+ of pthread-functions.h and pthreaddef.h.
+ * sysdeps/unix/sysv/linux/s390/jmp-unwind.c: Likewise.
+
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h (pthread_cond_t):
+ Change __data.__nwaiters from int to unsigned int.
+
+ * tst-clock2.c (do_test): Don't fail if _POSIX_THREAD_CPUTIME == 0 and
+ sysconf (_SC_THREAD_CPUTIME) returns negative value.
+
+ * allocatestack.c (__find_thread_by_id): Move attribute_hidden
+ before return type.
+
+ * sysdeps/s390/jmpbuf-unwind.h: Include bits/wordsize.h.
+ (JMPBUF_CFA_UNWINDS_ADJ): Subtract 96 resp. 160 bytes from CFA.
+
+2004-10-06 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-cancel4.c (tf_msgrcv): Check for failure in msgget. If the
+ test fails, remove message queue.
+ (tf_msgsnd): Likewise.
+
+2004-10-05 Jakub Jelinek <jakub@redhat.com>
+
+ * tst-clock1.c: Change #ifdef to #if defined.
+ * tst-clock2.c: Likewise.
+ * tst-cond11.c: Likewise.
+
+ * sysdeps/pthread/timer_create.c (timer_create): Use
+ defined _POSIX_CPUTIME && _POSIX_CPUTIME >= 0 instead of
+ defined CLOCK_PROCESS_CPUTIME_ID #ifs and similarly for
+ THREAD_CPUTIME.
+
+2004-10-05 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/bits/posix_opt.h (_POSIX_CPUTIME,
+ _POSIX_THREAD_CPUTIME): Define to 0.
+
+2004-10-04 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/bits/posix_opt.h: Define _POSIX_CPUTIME
+ and _POSIX_THREAD_CPUTIME to zero.
+ * sysdeps/unix/sysv/linux/ia64/bits/posix_opt.h: Likewise.
+ * tst-barrier2.c: Fix testing for POSIX feature.
+ * tst-clock1.c: Likewise.
+ * tst-clock2.c: Likewise.
+ * tst-cond11.c: Likewise.
+ * tst-cond4.c: Likewise.
+ * tst-cond6.c: Likewise.
+ * tst-flock2.c: Likewise.
+ * tst-mutex4.c: Likewise.
+ * tst-mutex9.c: Likewise.
+ * tst-rwlock12.c: Likewise.
+ * tst-rwlock4.c: Likewise.
+ * tst-signal1.c: Likewise.
+ * tst-spin2.c: Likewise.
+ * sysdeps/pthread/posix-timer.h: Likewise.
+ * sysdeps/pthread/timer_create.c: Likewise.
+ * sysdeps/pthread/timer_routines.c: Likewise.
+
+2004-10-01 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
+ (__lll_mutex_timedlock_wait): Address futex correctly.
+
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S
+ (__lll_mutex_timedlock_wait): If woken but cannot get the lock,
+ make sure 2 is stored in the futex and we looked at the old value.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
+ (__lll_mutex_timedlock_wait): Likewise. Fix a few other problems
+ which might very well made the code not working at all before.
+ [BZ #417]
+
+2004-09-28 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/pthread_kill.c (__pthread_kill): Don't
+ allow SIGSETXID to be sent.
+ * sysdeps/pthread/sigaction.c (__sigaction): Don't allow action
+ for SIGSETXID to be defined.
+ * sysdeps/pthread/pthread_sigmask.c (pthread_sigmask): Make sure
+ SIGSETXID cannot be blocked.
+
+ * sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h (pthread_cond_t):
+ Add __extension__ to long long types.
+ * sysdeps/unix/sysv/linux/sparc/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h: Likewise.
+
+2004-09-25 Ulrich Drepper <drepper@redhat.com>
+
+ * descr.h (struct pthread): Add stopped_start field.
+ * sysdeps/pthread/createthread.c (create_thread): Set
+ start_stopped flag in descriptor for new thread appropriately.
+ * pthread_create.c (start_thread): Only take lock to be stopped on
+ startup if stopped_start flag says so.
+
+2004-09-24 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread_create.c (__pthread_create_2_1): Remember whether thread
+ is created detached and if yes, do not try to free the stack in case
+ the thread creation failed.
+ * sysdeps/pthread/createthread.c (do_clone): Free stack here if clone
+ call fails. Don't depend on INTERNAL_SYSCALL_ERRNO return zero in
+ case there has been no error. [BZ #405]
+
+ * pthread_create.c (start_thread): Don't wait for scheduler data
+ etc to be set at the beginning of the function. The cancellation
+ infrastructure must have been set up. And enable async
+ cancellation before potentially going to sleep. [BZ #401]
+
+2004-09-20 Ulrich Drepper <drepper@redhat.com>
+
+ * Versions: Remove exports for pthread_set*id_np functions.
+ * sysdeps/pthread/pthread.h: Remove pthread_set*id_np prototypes
+ for now.
+ * Makefile: Don't build pthread_set*id code for now.
+
+2004-09-19 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/allocrtsig.c: Allocate second signal for
+ internal use.
+ * allocatestack.c (__nptl_setxid): New function.
+ * descr.h (struct xid_command): Define type.
+ * init.c (pthread_functions): Add ptr__nptl_setxid initialization.
+ (sighandler_setxid): New function.
+ (__pthread_initialize_minimal): Register sighandler_setxid for
+ SIGCANCEL.
+ * pt-allocrtsig.c: Update comment.
+ * pthreadP.h: Define SIGSETXID. Declare __xidcmd variable.
+ Declare __nptl_setxid.
+ * sysdeps/pthread/pthread-functions.h: Add ptr__nptl_setxid.
+ * sysdeps/pthread/pthread.h: Declare pthread_setgid_np,
+ pthread_setuid_np, pthread_setegid_np, pthread_seteuid_np,
+ pthread_setregid_np, pthread_setreuid_np, pthread_setresgid_np,
+ and pthread_setresuid_np.
+ * pthread_setgid_np.c: New file.
+ * pthread_setuid_np.c: New file.
+ * pthread_setegid_np.c: New file.
+ * pthread_seteuid_np.c: New file.
+ * pthread_setregid_np.c: New file.
+ * pthread_setreuid_np.c: New file.
+ * pthread_setresgid_np.c: New file.
+ * pthread_setresuid_np.c: New file.
+ * Versions [libpthread, GLIBC_2.3.4]: Add pthread_setgid_np,
+ pthread_setuid_np, pthread_setegid_np, pthread_seteuid_np,
+ pthread_setregid_np, pthread_setreuid_np, pthread_setresgid_np,
+ and pthread_setresuid_np.
+ * Makefile (libpthread-routines): Add pthread_setuid, pthread_seteuid,
+ pthread_setreuid, pthread_setresuid, pthread_setgid, pthread_setegid,
+ pthread_setregid, and pthread_setresgid.
+
+2004-09-18 Ulrich Drepper <drepper@redhat.com>
+
+ * allocatestack.c (allocate_stack): Return EAGAIN instead of
+ ENOMEM when out of memory.
+
+2004-09-10 Roland McGrath <roland@redhat.com>
+
+ [BZ #379]
+ * allocatestack.c (allocate_stack): Remove [__ASSUME_CLONE_STOPPED]
+ code, since we don't try to use the broken CLONE_STOPPED any more.
+ * pthread_create.c (start_thread): Likewise.
+
+2004-09-15 Richard Henderson <rth@redhat.com>
+
+ * sysdeps/unix/sysv/linux/alpha/vfork.S: Use libc_hidden_def.
+
+2004-09-01 David Mosberger <davidm@hpl.hp.com>
+
+ * sysdeps/unix/sysv/linux/ia64/jmpbuf-unwind.h
+ (__libc_unwind_longjmp): Delete macro and declare as function.
+ * sysdeps/unix/sysv/linux/ia64/Makefile (sysdep_routines): Mention
+ __ia64_longjmp, sigstack_longjmp, and __sigstack_longjmp for
+ nptl directory.
+ * sysdeps/unix/sysv/linux/ia64/__ia64_longjmp.S: New file.
+ * sysdeps/unix/sysv/linux/ia64/__sigstack_longjmp.c: New file.
+ * sysdeps/unix/sysv/linux/ia64/unwind_longjmp.c: New file.
+
+2004-09-12 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/pthread.h: Make rwlock prototypes available also
+ for __USE_XOPEN2K.
+ * sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h: Define rwlock
+ types also for __USE_XOPEN2K.
+ * sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/sparc/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h: Likewise.
+ [BZ #320]
+
+2004-09-08 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/pthread.h
+ (PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP): Make safe for C++.
+ (PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP): Likewise.
+ (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP): Likewise.
+ (PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP): Likewise.
+ [BZ #375]
+
+2004-09-07 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h: Allow
+ PSEUDO to be used with . prefix.
+
+ * sysdeps/unix/sysv/linux/alpha/pthread_once.c (__pthread_once):
+ Use atomic_increment instead of atomic_exchange_and_add.
+ * sysdeps/unix/sysv/linux/sparc/pthread_once.c (__pthread_once):
+ Likewise.
+ * sysdeps/unix/sysv/linux/ia64/pthread_once.c (__pthread_once):
+ Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/pthread_once.c (__pthread_once):
+ Likewise.
+
+ * allocatestack.c (allocate_stack): Use atomic_increment_val
+ instead of atomic_exchange_and_add.
+ * sysdeps/unix/sysv/linux/sem_post.c (__new_sem_post): Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/sem_post.c (__new_sem_post):
+ Likewise.
+ * sysdeps/pthread/pthread_barrier_wait.c (pthread_barrier_wait):
+ Likewise.
+
+ * sysdeps/pthread/pthread.h (pthread_once): Remove __THROW since
+ the initialization function might throw.
+
+2005-09-05 Richard Henderson <rth@redhat.com>
+
+ * sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h (SINGLE_THREAD_P):
+ Move definition inside libpthread, libc, librt check. Provide
+ definition for rtld.
+
+2004-09-02 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/alpha/jmpbuf-unwind.h: Define __libc_unwind_longjmp.
+ * sysdeps/i386/jmpbuf-unwind.h: Likewise
+ * sysdeps/powerpc/jmpbuf-unwind.h: Likewise.
+ * sysdeps/s390/jmpbuf-unwind.h: Likewise.
+ * sysdeps/sh/jmpbuf-unwind.h: Likewise.
+ * sysdeps/sparc/sparc32/jmpbuf-unwind.h: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/jmpbuf-unwind.h: Likewise.
+ * sysdeps/x86_64/jmpbuf-unwind.h: Likewise.
+ * unwind.c: Use it.
+
+ * sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h (pthread_cond_t):
+ Rename __data.__clock to __data.__nwaiters, make it unsigned int.
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h (pthread_cond_t):
+ Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S:
+ Decrement __nwaiters. If pthread_cond_destroy has been called and
+ this is the last waiter, signal pthread_cond_destroy caller and
+ avoid using the pthread_cond_t structure after unlock.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Likewise.
+ Read clock type from the least significant bits of __nwaiters instead
+ of __clock.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/internaltypes.h: Define COND_CLOCK_BITS.
+
+2004-08-31 Jakub Jelinek <jakub@redhat.com>
+
+ [BZ #342]
+ * Makefile (tests): Add tst-cond20 and tst-cond21.
+ * tst-cond20.c: New test.
+ * tst-cond21.c: New test.
+ * sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h
+ (pthread_cond_t): Rename __data.__clock to __data.__nwaiters, make
+ it unsigned int.
+ * sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h (pthread_cond_t):
+ Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h
+ (pthread_cond_t): Likewise.
+ * sysdeps/unix/sysv/linux/sparc/bits/pthreadtypes.h (pthread_cond_t):
+ Likewise.
+ * sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h (pthread_cond_t):
+ Likewise.
+ * sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h (pthread_cond_t):
+ Likewise.
+ * sysdeps/unix/sysv/linux/lowlevelcond.sym (cond_clock): Remove.
+ (cond_nwaiters): New.
+ (clock_bits): New.
+ * pthread_cond_destroy.c (__pthread_cond_destroy): Return EBUSY
+ if there are waiters not signalled yet.
+ Wait until all already signalled waiters wake up.
+ * sysdeps/pthread/pthread_cond_wait.c (__condvar_cleanup): Decrement
+ __nwaiters. If pthread_cond_destroy has been called and this is the
+ last waiter, signal pthread_cond_destroy caller and avoid using
+ the pthread_cond_t structure after unlock.
+ (__pthread_cond_wait): Increment __nwaiters in the beginning,
+ decrement it when leaving. If pthread_cond_destroy has been called
+ and this is the last waiter, signal pthread_cond_destroy caller.
+ * sysdeps/pthread/pthread_cond_timedwait.c (__pthread_cond_timedwait):
+ Likewise. Read clock type from the least significant bits of
+ __nwaiters instead of __clock.
+ * pthread_condattr_setclock.c (pthread_condattr_setclock): Check
+ whether clock ID can be encoded in COND_CLOCK_BITS bits.
+ * pthread_condattr_getclock.c (pthread_condattr_getclock): Decode
+ clock type just from the last COND_CLOCK_BITS bits of value.
+ * pthread_cond_init.c (__pthread_cond_init): Initialize __nwaiters
+ instead of __clock, just from second bit of condattr's value.
+
+2004-08-30 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h: Include
+ bits/wordsize.h. Make the header match i386 header when __WORDSIZE
+ != 64.
+ * sysdeps/unix/sysv/linux/x86_64/bits/semaphore.h: Likewise.
+
+2004-08-15 Roland McGrath <roland@frob.com>
+
+ * pthread_atfork.c: Update copyright terms including special exception
+ for these trivial files, which are statically linked into executables
+ that use dynamic linking for the significant library code.
+
+2004-08-09 Jakub Jelinek <jakub@redhat.com>
+
+ * DESIGN-rwlock.txt: Add decreasing of nr_readers_queued to
+ pthread_rwlock_rdlock.
+ * sysdeps/pthread/pthread_rwlock_rdlock (__pthread_rwlock_rdlock):
+ Decrease __nr_readers_queued after reacquiring lock.
+ * sysdeps/pthread/pthread_rwlock_timedrdlock
+ (pthread_rwlock_timedrdlock): Likewise.
+ Reported by Bob Cook <bobcook47@hotmail.com>.
+
+2004-08-11 Jakub Jelinek <jakub@redhat.com>
+
+ * tst-rwlock14.c (tf): Read main thread handle from *ARG
+ before pthread_barrier_wait.
+
+2004-08-07 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S:
+ Remove unnecessary exception handling data.
+
+2004-07-23 Jakub Jelinek <jakub@redhat.com>
+
+ [BZ #284]
+ * sysdeps/pthread/pthread.h (pthread_getcpuclockid): Use __clockid_t
+ instead of clockid_t.
+
+2004-07-21 Roland McGrath <roland@redhat.com>
+
+ * Makefile ($(objpfx)multidir.mk): Use $(make-target-directory).
+
+2004-07-19 Roland McGrath <roland@redhat.com>
+
+ * tst-cancel4.c (tf_waitid): Use WEXITED flag bit if available.
+
+2004-07-02 Roland McGrath <roland@redhat.com>
+
+ * configure: Don't exit.
+
+2004-07-14 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_timedwait.S
+ (__pthread_cond_timedwait): Check for invalid nanosecond in
+ timeout value.
+
+2004-07-07 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile: Add rules to build and run tst-fini1.
+ * tst-fini1.c: New file.
+ * tst-fini1mod.c: New file.
+
+2004-07-05 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/sysdep-cancel.h: Define NO_CANCELLATION
+ if no cancellation support is needed.
+ * sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h: Likewise.
+ * sysdeps/unix/sysv/linux/sh/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/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/powerpc/lowlevellock.h: Define __NR_futex
+ only if not already defined.
+
+2004-07-05 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h (lll_unlock): Use
+ constraint "m" instead of "0" for futex.
+
+ * shlib-versions: Add powerpc64-.*-linux.*.
+
+2004-07-04 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
+ (pthread_rwlock_timedrdlock): Use cmpq instead of cmpl to check
+ for valid tv_nsec.
+ * tst-rwlock14.c (do_test): Test for invalid tv_nsec equal to
+ 1 billion and 64-bit tv_nsec which is valid when truncated to 32
+ bits.
+
+2004-06-29 Roland McGrath <roland@redhat.com>
+
+ * Banner: NPTL no longer has its own version number.
+ * Makefile (nptl-version): Variable removed.
+ * sysdeps/pthread/Makefile (CFLAGS-confstr.c): Set LIBPTHREAD_VERSION
+ using $(version), the glibc version number.
+
+2004-06-29 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/unix/sysv/linux/sh/pthread_once.S (__pthread_once):
+ Fix branch offset for a PLT entry.
+ * sysdeps/unix/sysv/linux/sh/sem_post.S (__new_sem_post):
+ Likewise.
+ * sysdeps/unix/sysv/linux/sh/sem_timedwait.S (sem_timedwait):
+ Likewise.
+ * sysdeps/unix/sysv/linux/sh/sem_trywait.S (__new_sem_trywait):
+ Likewise.
+ * sysdeps/unix/sysv/linux/sh/sem_wait.S (__new_sem_wait):
+ Likewise.
+
+2004-06-28 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/alpha/tcb-offsets.sym (MULTIPLE_THREADS_OFFSET): Define
+ unconditionally.
+
+2004-06-28 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/pthread/pthread_rwlock_timedwrlock.c
+ (pthread_rwlock_timedwrlock): Return EINVAL if tv_nsec is negative,
+ instead of tv_sec.
+ * sysdeps/pthread/pthread_rwlock_timedrdlock.c
+ (pthread_rwlock_timedrdlock): Likewise.
+
+2004-06-22 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/s390/lowlevellock.h (lll_futex_requeue):
+ Set __r7 to val, not mutex.
+
+2004-06-27 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile: Add rules to build tst-rwlock14.
+ * tst-rwlock14.c: New file.
+
+2004-06-24 Boris Hu <boris.hu@intel.com>
+
+ * sysdeps/pthread/pthread_rwlock_timedrdlock.c: Add timeout validation
+ check.
+ * sysdeps/pthread/pthread_rwlock_timedwrlock.c: Likewise.
+
+2004-06-19 Andreas Jaeger <aj@suse.de>
+
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: Fix
+ assembler in last patch.
+
+2004-06-17 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/pthread_cond_timedwait.c
+ (__pthread_cond_timedwait): Also check for negativ nanoseconds.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S
+ (__pthread_cond_timedwait): Check for invalid nanosecond in
+ timeout value.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: Likewise.
+ * tst-cond19.c: New file.
+ * Makefile: Add rules to build and run tst-cond19.
+
+2004-06-15 Steven Munroe <sjmunroe@us.ibm.com>
+
+ * tst-context1.c (GUARD_PATTERN): Defined.
+ (tst_context_t): Define struct containing ucontext_t & guard words.
+ (ctx): Declare as an array of tst_context_t.
+ (fct): Verify uc_link & guard words are still valid.
+ (tf): Initialize guard words in ctx. Adjust ctx refs for new struct.
+
+2004-06-13 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h (pthread_cond_t):
+ Add __data.__futex field, reshuffle __data.__clock.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_signal.S
+ (__pthread_cond_signal): Increment __futex at the same time as
+ __wakeup_seq or __total_seq. Pass address of __futex instead of
+ address of low 32-bits of __wakeup_seq to futex syscall.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_wait.S
+ (__pthread_cond_wait): Likewise. Pass __futex value from before
+ releasing internal lock to FUTEX_WAIT.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_timedwait.S
+ (__pthread_cond_timedwait): Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_broadcast.S
+ (FUTEX_CMP_REQUEUE): Define.
+ (__pthread_cond_broadcast): Set __futex to 2 * __total_seq.
+ Use FUTEX_CMP_REQUEUE operation instead of FUTEX_REQUEUE.
+ Pass __futex value from before the unlock and __futex address instead
+ of address of low 32-bits of __wakeup_seq to futex syscall.
+ Fallback to FUTEX_WAKE all on any errors.
+
+2004-06-08 Jakub Jelinek <jakub@redhat.com>
+
+ * pthread_mutexattr_getpshared.c (pthread_mutex_getpshared): Fix
+ comment typo.
+ * pthread_mutexattr_gettype.c (pthread_mutexattr_gettype): Likewise.
+ * pthread_mutexattr_init.c (__pthread_mutexattr_init): Likewise.
+ * pthread_mutexattr_settype.c (__pthread_mutexattr_settype): Likewise.
+ * pthread_mutexattr_setpshared.c (pthread_mutexattr_setpshared):
+ Likewise. Reported by Bob Cook <bobcook47@hotmail.com>.
+
+2004-06-11 Martin Schwidefsky <schwidefsky@de.ibm.com>
+
+ * sysdeps/unix/sysv/linux/s390/lowlevellock.h (lll_compare_and_swap):
+ Add memory clobber to inline assembly.
+ (__lll_mutex_trylock): Likewise.
+ (__lll_mutex_cond_trylock): Likewise.
+
+2004-06-07 Martin Schwidefsky <schwidefsky@de.ibm.com>
+
+ * sysdeps/unix/sysv/linux/s390/lowlevellock.h (lll_futex_requeue):
+ Pass val argument as 6th system call argument in %r7.
+
+2004-05-21 Jakub Jelinek <jakub@redhat.com>
+
+ * Makefile (tests): Add tst-cond16.
+ * sysdeps/unix/sysv/linux/lowlevelcond.sym (cond_futex): Add.
+ * pthread_cond_init.c (__pthread_cond_init): Clear __data.__futex.
+ * sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h (pthread_cond_t):
+ Add __data.__futex field, reshuffle __data.__clock.
+ * sysdeps/unix/sysv/linux/i386/pthread_cond_signal.S
+ (__pthread_cond_signal): Increment __futex at the same time as
+ __wakeup_seq or __total_seq. Pass address of __futex instead of
+ address of low 32-bits of __wakeup_seq to futex syscall.
+ * sysdeps/unix/sysv/linux/i386/pthread_cond_wait.S
+ (__pthread_cond_wait): Likewise. Pass __futex value from before
+ releasing internal lock to FUTEX_WAIT.
+ * sysdeps/unix/sysv/linux/i386/pthread_cond_timedwait.S
+ (__pthread_cond_timedwait): Likewise.
+ * sysdeps/unix/sysv/linux/i386/pthread_cond_broadcast.S
+ (FUTEX_CMP_REQUEUE): Define.
+ (__pthread_cond_broadcast): Set __futex to 2 * __total_seq.
+ Use FUTEX_CMP_REQUEUE operation instead of FUTEX_REQUEUE.
+ Pass __futex value from before the unlock and __futex address instead
+ of address of low 32-bits of __wakeup_seq to futex syscall.
+ Fallback to FUTEX_WAKE all on any errors.
+ * sysdeps/unix/sysv/linux/alpha/lowlevellock.h (FUTEX_CMP_REQUEUE):
+ Define.
+ (lll_futex_requeue): Add val argument, use FUTEX_CMP_REQUEUE
+ internally. Return non-zero if error, zero if success.
+ * sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h (pthread_cond_t):
+ Add __data.__futex field, reshuffle __data.__clock.
+ * sysdeps/unix/sysv/linux/s390/lowlevellock.h (FUTEX_CMP_REQUEUE):
+ Define.
+ (lll_futex_requeue): Add val argument, return 1 unconditionally
+ for the time being.
+ * sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h (pthread_cond_t):
+ Add __data.__futex field, reshuffle __data.__clock.
+ * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h (FUTEX_CMP_REQUEUE):
+ Define.
+ (lll_futex_requeue): Add val argument, use FUTEX_CMP_REQUEUE
+ internally. Return non-zero if error, zero if success.
+ * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h
+ (pthread_cond_t): Add __data.__futex field, reshuffle __data.__clock.
+ * sysdeps/unix/sysv/linux/sparc/lowlevellock.h (FUTEX_CMP_REQUEUE):
+ Define.
+ (lll_futex_requeue): Add val argument, use FUTEX_CMP_REQUEUE
+ internally. Return non-zero if error, zero if success.
+ * sysdeps/unix/sysv/linux/sparc/bits/pthreadtypes.h (pthread_cond_t):
+ Add __data.__futex field, reshuffle __data.__clock.
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.h (FUTEX_CMP_REQUEUE):
+ Define.
+ (lll_futex_requeue): Add val argument, use FUTEX_CMP_REQUEUE
+ internally. Return non-zero if error, zero if success.
+ * sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h (pthread_cond_t):
+ Add __data.__futex field, reshuffle __data.__clock.
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h (pthread_cond_t):
+ Add __data.__futex field, reshuffle __data.__clock.
+ * sysdeps/pthread/pthread_cond_signal.c (__pthread_cond_signal):
+ Increment __futex at the same time as __wakeup_seq or __total_seq.
+ Pass address of __futex instead of address of low 32-bits of
+ __wakeup_seq to futex syscall.
+ * sysdeps/pthread/pthread_cond_wait.c (__pthread_cond_wait): Likewise.
+ Pass __futex value from before releasing internal lock
+ to FUTEX_WAIT.
+ * sysdeps/pthread/pthread_cond_timedwait.c (__pthread_cond_timedwait):
+ Likewise. Avoid unnecessary shadowing of variables.
+ * sysdeps/pthread/pthread_cond_broadcast.c (__pthread_cond_broadcast):
+ Set __futex to 2 * __total_seq. Pass __futex value from before the
+ unlock and __futex address instead of address of low 32-bits of
+ __wakeup_seq to futex_requeue macro, adjust for new return value
+ meaning.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
+ (__pthread_cond_signal): Increment __futex at the same time as
+ __wakeup_seq or __total_seq. Pass address of __futex instead of
+ address of low 32-bits of __wakeup_seq to futex syscall.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
+ (__pthread_cond_wait): Likewise. Pass __futex value from before
+ releasing internal lock to FUTEX_WAIT.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
+ (__pthread_cond_timedwait): Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
+ (FUTEX_CMP_REQUEUE): Define.
+ (__pthread_cond_broadcast): Set __futex to 2 * __total_seq.
+ Use FUTEX_CMP_REQUEUE operation instead of FUTEX_REQUEUE.
+ Pass __futex value from before the unlock and __futex address instead
+ of address of low 32-bits of __wakeup_seq to futex syscall.
+ Fallback to FUTEX_WAKE all on any errors.
+
+2004-06-03 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/unix/sysv/linux/sh/lowlevellock.h (lll_mutex_lock):
+ Add nop to align the end of critical section.
+ (lll_mutex_cond_lock, lll_mutex_timedlock): Likewise.
+
+2004-06-01 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h (pthread_cond_t):
+ Add __broadcast_seq field.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_broadcast.S: Mark
+ all waiters as woken with woken_seq and bump broadcast counter.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_wait.S: Use new
+ __broadcast_seq. Increment __woken_seq correctly when cleanuped.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_timedwait.S: Likewise.
+ Comment typo fixes. Avoid returning -ETIMEDOUT.
+
+2004-06-01 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S
+ (__condvar_tw_cleanup): Fix access to saved broadcast_seq value.
+ Reported by Kaz Kojima.
+
+2004-05-25 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/aio_misc.h: New file.
+
+2004-05-21 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/pthread/pthread_cond_wait.c (__pthread_cond_wait): Compare
+ __broadcast_seq with bc_seq after acquiring internal lock instead of
+ before it.
+
+2004-05-18 Jakub Jelinek <jakub@redhat.com>
+
+ * Makefile (.NOTPARALLEL): Only serialize make check/xcheck, not
+ compilation.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S
+ (__pthread_cond_timedwait): Avoid returning -ETIMEDOUT.
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h
+ (pthread_cond_t): Add __data.__broadcast_seq field.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
+ (FRAME_SIZE): Define.
+ (__pthread_cond_timedwait): Use it. Store/check broadcast_seq.
+ Comment typo fixes.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S (FRAME_SIZE):
+ Define.
+ (__pthread_cond_wait): Use it. Store/check broadcast_seq. Comment
+ typo fixes.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
+ (__pthread_cond_broadcast): Increment broadcast_seq. Comment typo
+ fixes.
+
+2004-05-18 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/lowlevelcond.sym: Add broadcast_seq entry.
+ * sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h (pthread_cond_t):
+ Add __broadcast_seq field.
+ * sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/sparc/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_broadcast.S: Mark
+ all waiters as woken with woken_seq and bump broadcast counter.
+ * sysdeps/pthread/pthread_cond_broadcast.c: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S: Use new
+ __broadcast_seq field.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Likewise.
+ * sysdeps/pthread/pthread_cond_wait.c: Likewise.
+ * sysdeps/pthread/pthread_cond_timedwait.c: Likewise.
+ * pthread_cond_init.c: Initialize __broadcast_seq field.
+ * Makefile (tests): Add tst-cond17 and tst-cond18.
+ Add .NOTPARALLEL goal.
+ * tst-cond16.c: New file. From Jakub.
+ * tst-cond17.c: New file. From Jakub.
+ * tst-cond18.c: New file. From Jakub.
+
+2004-05-16 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/sem_timedwait.S: Correct some
+ unwind info.
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S:
+ Parametrize frame size. Correct some unwind info.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Likewise.
+
+2004-05-04 Jakub Jelinek <jakub@redhat.com>
+
+ * tst-stack3.c: Note testing functionality beyond POSIX.
+
+2004-05-04 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h (USE___THREAD):
+ Change conditional from ifdef to if.
+
+2004-04-23 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h (SYSDEP_CANCEL_ERRNO,
+ SYSDEP_CANCEL_ERROR): Define.
+ (PSEUDO): Use it.
+
+2004-05-01 Jakub Jelinek <jakub@redhat.com>
+
+ * Versions (libpthread): Remove __pthread_cleanup_upto@@GLIBC_PRIVATE.
+
+2004-04-20 Jakub Jelinek <jakub@redhat.com>
+
+ * sem_unlink.c (sem_unlink): Change EPERM into EACCES.
+
+2004-04-19 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/unix/sysv/linux/sh/sem_timedwait.S: Add frame info.
+ Use HIDDEN_JUMPTARGET to jump to __pthread_unwind.
+ * sysdeps/unix/sysv/linux/sh/sem_wait.S: Remove unneeded frame
+ info. Use HIDDEN_JUMPTARGET to jump to __pthread_unwind.
+
+2004-04-19 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/timer_routines.c: Make sure helper
+ thread has all signals blocked.
+
+2004-04-18 Andreas Jaeger <aj@suse.de>
+
+ * sysdeps/unix/sysv/linux/x86_64/bits/semaphore.h
+ (SEM_VALUE_MAX): Add missing brace.
+
+2004-04-17 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/pthread/Makefile (tests): Add tst-mqueue8x
+ in rt subdir.
+ (CFLAGS-tst-mqueue8x.c): Add -fexceptions.
+ * sysdeps/pthread/tst-mqueue8x.c: New test.
+ * tst-cancel4.c: Update comment about message queues.
+
+ * sysdeps/pthread/timer_gettime.c (timer_gettime): For expired timer
+ return it_value { 0, 0 }.
+ * sysdeps/pthread/timer_create.c (timer_create): Handle SIGEV_NONE
+ like SIGEV_SIGNAL.
+ * sysdeps/pthread/timer_routines.c (thread_expire_timer): Remove
+ assertion for SIGEV_NONE.
+ (thread_attr_compare): Compare all attributes, not just a partial
+ subset.
+
+2004-04-17 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/mq_notify.c: Include stdlib.h.
+
+2004-04-17 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/alpha/bits/semaphore.h (SEM_VALUE_MAX):
+ Just use a plain number.
+ * sysdeps/unix/sysv/linux/i386/bits/semaphore.h: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/bits/semaphore.h: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/bits/semaphore.h: Likewise.
+ * sysdeps/unix/sysv/linux/s390/bits/semaphore.h: Likewise.
+ * sysdeps/unix/sysv/linux/sh/bits/semaphore.h: Likewise.
+ * sysdeps/unix/sysv/linux/sparc/bits/semaphore.h: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/bits/semaphore.h: Likewise.
+
+2004-04-16 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_wait.S: Remove unneeded
+ frame info.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_timedwait.S: Likewise.
+
+2004-04-15 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/timer_routines.c: Include errno.h.
+ (timer_helper_thread): Use inline rt_sigtimedwait syscall instead
+ of calling sigwaitinfo.
+
+2004-04-16 Ulrich Drepper <drepper@redhat.com>
+
+ * allocatestack.c (allocate_stack): Set reported_guardsize
+ unconditionally.
+ * pthread_getattr_np.c (pthread_getattr_np): Use
+ reported_guardsize instead of guardsize.
+ * descr.h (struct pthread): Add reported_guardsize field.
+
+2004-04-13 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/mq_notify.c: Shut up GCC warning.
+
+2004-04-12 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/mq-notify.c: New file.
+
+2004-04-08 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/bits/local_lim.h (MQ_PRIO_MAX): Define.
+ * sysdeps/unix/sysv/linux/alpha/bits/local_lim.h (MQ_PRIO_MAX): Define.
+ * sysdeps/unix/sysv/linux/ia64/bits/local_lim.h (MQ_PRIO_MAX): Define.
+ * sysdeps/unix/sysv/linux/sparc/bits/local_lim.h (MQ_PRIO_MAX): Define.
+ * sysdeps/unix/sysv/linux/bits/posix_opt.h (_POSIX_MESSAGE_PASSING):
+ Define.
+ * sysdeps/unix/sysv/linux/i386/bits/posix_opt.h
+ (_POSIX_MESSAGE_PASSING): Define.
+ * sysdeps/unix/sysv/linux/ia64/bits/posix_opt.h
+ (_POSIX_MESSAGE_PASSING): Define.
+ * sysdeps/unix/sysv/linux/x86_64/bits/posix_opt.h
+ (_POSIX_MESSAGE_PASSING): Define.
+
+2004-04-04 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-context1.c (fct): Check whether correct stack is used.
+
+2004-04-03 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h: Never use
+ matching constraints for asm mem parameters.
+
+ * tst-clock2.c (tf): Don't define unless needed.
+
+2004-03-30 H.J. Lu <hongjiu.lu@intel.com>
+
+ * Makefile (link-libc-static): Use $(static-gnulib) instead of
+ $(gnulib).
+
+2004-03-30 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/pthread-functions.h: Add ptr__nptl_deallocate_tsd.
+ * init.c (pthread_functions): Add ptr__nptl_deallocate_tsd.
+ * pthreadP.h: Declare __nptl_deallocate_tsd.
+ * pthread_create.c (deallocate_tsd): Remove to __nptl_deallocate_tsd.
+ Adjust caller.
+
+ * Makefile (tests): Add tst-tsd5.
+ * tst-tsd5.c: New file.
+
+2004-03-29 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/pthread_attr_setaffinity.c
+ (__pthread_attr_setaffinity_old): Prepend GLIBC_ to version names
+ is SHLIB_COMPAT check.
+ * sysdeps/unix/sysv/linux/pthread_attr_getaffinity.c
+ (__pthread_attr_getaffinity_old): Likewise.
+ * sysdeps/unix/sysv/linux/pthread_getaffinity.c
+ (__pthread_getaffinity_old): Likewise.
+ * sysdeps/unix/sysv/linux/pthread_setaffinity.c
+ (__pthread_setaffinity_old): Likewise.
+
+2004-03-26 Ulrich Drepper <drepper@redhat.com>
+
+ * allocatestack.c (_make_stacks_executable): Call
+ _dl_make_stack_executable first.
+
+2004-03-24 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/i386/pthread_spin_lock.c (pthread_spin_lock): Use "m"
+ constraint instead of "0".
+
+2004-03-24 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h
+ (lll_mutex_cond_trylock): Define as wrapper around __lll_cond_trylock.
+
+ * sysdeps/unix/sysv/linux/getpid.c (really_getpid): Reorganize
+ code to avoid warning.
+
+2004-03-24 Andreas Jaeger <aj@suse.de>
+
+ * sysdeps/unix/sysv/linux/pthread_attr_setaffinity.c
+ (__pthread_attr_setaffinity_old): Remove const.
+
+2004-03-23 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/smp.h: New file.
+ * sysdeps/unix/sysv/linux/sh/smp.h: New file.
+ * init.c: Define __is_smp.
+ (__pthread_initialize_minimal_internal): Call is_smp_system to
+ initialize __is_smp.
+ * pthreadP.h: Declare __is_smp.
+ Define MAX_ADAPTIVE_COUNT is necessary.
+ * pthread_mutex_init.c: Add comment regarding __spins field.
+ * pthread_mutex_lock.c: Implement adaptive mutex type.
+ * pthread_mutex_timedlock.c: Likewise.
+ * sysdeps/unix/sysv/linux/pthread_mutex_cond_lock.c: Likewise.
+ * sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h (pthread_mutex_t):
+ Add __spins field.
+ * sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/sparc/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h: Define
+ lll_mutex_cond_trylock.
+ * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/sparc/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h: Likewise.
+ Define BUSY_WAIT_NOP.
+ * sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h: Likewise.
+
+ * tst-mutex5.c: Add support for testing adaptive mutexes.
+ * tst-mutex7.c: Likewise.
+ * tst-mutex5a.c: New file.
+ * tst-mutex7a.c: New file.
+ * Makefile (tests): Add tst-mutex5a and tst-mutex7a.
+
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
+ (__lll_mutex_timedlock_wait): Preserve r8 and r9 since the
+ vgettimeofday call might destroy the content.
+
+ * sysdeps/ia64/pthread_spin_lock.c (pthread_spin_lock): Use hint
+ @pause in the loop.
+
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h (lll_mutex_trylock):
+ No need to restrict type of ret. Make it int. Add comment.
+
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h (lll_mutex_trylock):
+ Remove unnecessary setne instruction.
+
+2004-03-22 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/pthread_getaffinity.c
+ (__pthread_getaffinity_new): Use INT_MAX instead of UINT_MAX.
+ * pthread_getattr_np.c (pthread_getattr_np): Double size every cycle.
+ If realloc fails, break out of the loop.
+
+2004-03-20 Andreas Jaeger <aj@suse.de>
+
+ * sysdeps/unix/sysv/linux/pthread_setaffinity.c
+ (__pthread_setaffinity_old): Fix interface.
+ * sysdeps/unix/sysv/linux/pthread_getaffinity.c
+ (__pthread_getaffinity_old): Likewise.
+
+ * sysdeps/unix/sysv/linux/pthread_setaffinity.c
+ (__pthread_setaffinity_new): Remove duplicate declaration.
+
+2004-03-20 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/unix/sysv/linux/sh/sysdep-cancel.h (CENABLE): Save
+ the return value to a safe register.
+ (CDISABLE): Set the function argument correctly.
+
+2004-03-17 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/unix/sysv/linux/sh/lowlevel-atomic.h (XCHG): Define.
+ * sysdeps/unix/sysv/linux/sh/lowlevellock.S (__lll_mutex_lock_wait):
+ Rewrite so that only one locked memory operation per round is needed.
+ * sysdeps/unix/sysv/linux/sh/pthread_barrier_wait.S
+ (pthread_barrier_wait): After wakeup, release lock only when the
+ last thread stopped using the barrier object.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_wait.S
+ (__pthread_cond_wait): Don't store mutex address if the current
+ value is ~0l. Add correct cleanup support and unwind info.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_broadcast.S
+ (__pthread_cond_broadcast): Don't use requeue for pshared condvars.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_signal.S: Update comment.
+ * sysdeps/unix/sysv/linux/sh/pthread_once.S (__pthread_once):
+ Add correct cleanup support and unwind info.
+ * sysdeps/unix/sysv/linux/sh/sem_wait.S (__new_sem_wait): Likewise.
+ * sysdeps/unix/sysv/linux/sh/sysdep-cancel.h: Add unwind
+ information for syscall wrappers.
+
+2004-03-18 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/internaltypes.h (struct pthread_attr): Add
+ cpusetsize field, remove next.
+ * sysdeps/pthread/pthread.h (pthread_getaffinity_np): Add new second
+ parameter for size of the CPU set.
+ (pthread_setaffinity_np): Likewise.
+ (pthread_attr_getaffinity_np): Likewise.
+ (pthread_attr_setaffinity_np): Likewise.
+ * sysdeps/unix/sysv/linux/pthread_attr_getaffinity.c: Implement
+ interface change, keep compatibility code.
+ * sysdeps/unix/sysv/linux/pthread_attr_setaffinity.c: Likewise.
+ * sysdeps/unix/sysv/linux/pthread_getaffinity.c: Likewise.
+ * sysdeps/unix/sysv/linux/pthread_setaffinity.c: Likewise.
+ * pthreadP.h: Remove hidden_proto for pthread_getaffinity_np. Declare
+ __pthread_getaffinity_np.
+ * Versions: Add version for changed interfaces.
+ * tst-attr3.c: Adjust test for interface change.
+ * pthread_getattr_np.c: Query the kernel about the affinity mask with
+ increasing buffer sizes.
+ * pthread_attr_destroy.c: Remove unused list handling.
+ * pthread_attr_init.c: Likewise.
+
+2004-03-17 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/unix/sysv/linux/timer_create.c (timer_create): Pass missing
+ first argument to clock_getres so we ever enable kernel timers.
+
+2004-03-15 Ulrich Weigand <uweigand@de.ibm.com>
+
+ * init.c (nptl_version): Add __attribute_used__ to nptl_version.
+
+2004-03-12 Richard Henderson <rth@redhat.com>
+
+ * sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h: Propagate
+ oldvalue from CENABLE to CDISABLE.
+
+2004-03-12 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/bits/local_lim.h: Define HOST_NAME_MAX.
+ * sysdeps/unix/sysv/linux/alpha/bits/local_lim.h: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/bits/local_lim.h: Likewise.
+ * sysdeps/unix/sysv/linux/sparc/bits/local_lim.h: Likewise.
+
+2004-03-11 Richard Henderson <rth@redhat.com>
+
+ * sysdeps/alpha/tcb-offsets.sym (PID_OFFSET): New.
+ * sysdeps/unix/sysv/linux/alpha/pt-vfork.S: Save/restore PID.
+ * sysdeps/unix/sysv/linux/alpha/vfork.S: New file.
+
+2004-03-11 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/s390/s390-64/vfork.S (__vfork): Use jgnl
+ instead of jnl instruction to jump to SYSCALL_ERROR_LABEL.
+ * sysdeps/unix/sysv/linux/s390/s390-64/pt-vfork.S (__vfork): Likewise.
+
+2004-03-11 Jakub Jelinek <jakub@redhat.com>
+
+ * forward.c (__pthread_cond_broadcast_2_0,
+ __pthread_cond_destroy_2_0, __pthread_cond_init_2_0,
+ __pthread_cond_signal_2_0, __pthread_cond_wait_2_0,
+ __pthread_cond_timedwait_2_0): Use return 0 as defaction instead of 0.
+
+2004-03-11 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/sh/tcb-offsets.sym: Add PID.
+ * sysdeps/unix/sysv/linux/sh/pt-vfork.S: Properly handle PID cache.
+ * sysdeps/unix/sysv/linux/sh/vfork.S: New file.
+
+2004-03-10 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S: No need to
+ include <sysdep-cancel.h>, vfork is no cancellation point.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/pt-vfork.S: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc32/pt-vfork.S: Likewise.
+
+2004-03-10 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/s390/s390-32/vfork.S (__vfork): Add
+ libc_hidden_def.
+ * sysdeps/unix/sysv/linux/s390/s390-64/vfork.S (__vfork): Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S (__vfork):
+ Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S (__vfork):
+ Likewise.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S (__vfork): Likewise.
+ * sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S (__vfork): Likewise.
+ * sysdeps/unix/sysv/linux/ia64/pt-vfork.S: Include tcb-offsets.h.
+ * sysdeps/unix/sysv/linux/ia64/vfork.S (__vfork): Use DO_CALL instead
+ of DO_CALL_VIA_BREAK. Work around a gas problem.
+
+ * sysdeps/unix/sysv/linux/powerpc/pt-vfork.S: Remove.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S: New file.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc32/pt-vfork.S: New file.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S: New file.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/pt-vfork.S: New file.
+ * sysdeps/powerpc/tcb-offsets.sym: Add PID.
+
+ * sysdeps/unix/sysv/linux/ia64/pt-vfork.S (__vfork): Don't use
+ a local register for saving old PID. Negate PID in parent upon exit.
+
+ * sysdeps/unix/sysv/linux/s390/s390-32/pt-vfork.S: Include
+ tcb-offsets.h.
+ (__vfork): Negate PID if non-zero and set to INT_MIN if zero
+ before syscall, set to the old value in the parent afterwards.
+ * sysdeps/unix/sysv/linux/s390/s390-32/vfork.S: New file.
+ * sysdeps/unix/sysv/linux/s390/s390-64/pt-vfork.S: Include
+ tcb-offsets.h.
+ (__vfork): Negate PID if non-zero and set to INT_MIN if zero
+ before syscall, set to the old value in the parent afterwards.
+ * sysdeps/unix/sysv/linux/s390/s390-64/vfork.S: New file.
+ * sysdeps/s390/tcb-offsets.sym: Add PID.
+
+ * sysdeps/unix/sysv/linux/sparc/pt-vfork.S: Remove.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S: New file.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/pt-vfork.S: New file.
+ * sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S: New file.
+ * sysdeps/unix/sysv/linux/sparc/sparc64/pt-vfork.S: New file.
+ * sysdeps/sparc/tcb-offsets.sym: Add PID.
+
+2004-03-10 Andreas Schwab <schwab@suse.de>
+
+ * sysdeps/ia64/tcb-offsets.sym: Add PID.
+ * sysdeps/unix/sysv/linux/ia64/vfork.S: New file.
+ * sysdeps/unix/sysv/linux/ia64/pt-vfork.S: Properly handle PID cache.
+
+2004-03-09 Jakub Jelinek <jakub@redhat.com>
+
+ * tst-cancel20.c (do_one_test): Clear in_sh_body first.
+ * tst-cancel21.c (do_one_test): Likewise.
+ Reported by Gordon Jin <gordon.jin@intel.com>.
+
+2004-02-09 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/vfork.S (SAVE_PID): Negate PID
+ if non-zero and set to INT_MIN if zero.
+ * sysdeps/unix/sysv/linux/x86_64/vfork.S (SAVE_PID): Likewise.
+ * sysdeps/unix/sysv/linux/i386/pt-vfork.S: Include tcb-offsets.h.
+ (SAVE_PID, RESTORE_PID): Define.
+ (__vfork): Use it.
+ * sysdeps/unix/sysv/linux/x86_64/pt-vfork.S: Include tcb-offsets.h.
+ Use relative path to avoid including NPTL i386/vfork.S.
+ (SAVE_PID, RESTORE_PID): Define.
+ * sysdeps/unix/sysv/linux/raise.c: Include limits.h.
+ (raise): Handle THREAD_SELF->pid INT_MIN the same as 0.
+ * Makefile (tests): Add tst-vfork1, tst-vfork2, tst-vfork1x and
+ tst-vfork2x.
+ (tests-reverse): Add tst-vfork1x and tst-vfork2x.
+ * tst-vfork1.c: New test.
+ * tst-vfork2.c: New test.
+ * tst-vfork1x.c: New test.
+ * tst-vfork2x.c: New test.
+
+2004-03-08 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/i386/tcb-offsets.sym: Add PID.
+ * sysdeps/x86_64/tcb-offsets.sym: Likewise.
+ * sysdeps/unix/sysv/linux/i386/vfork.S: New file.
+ * sysdeps/unix/sysv/linux/x86_64/vfork.S: New file.
+
+2004-03-08 Steven Munroe <sjmunroe@us.ibm.com>
+
+ * sysdeps/unix/sysv/linux/powerpc/Versions: Remove leading tabs.
+
+2004-03-08 H.J. Lu <hongjiu.lu@intel.com>
+
+ * sysdeps/s390/tls.h (INIT_SYSINFO): _dl_sysinfo is now in
+ _rtld_global_ro.
+
+2004-03-07 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/ia64/tls.h (INIT_SYSINFO): _dl_sysinfo is now in
+ _rtld_global_ro.
+
+ * tst-once4.c: Remove unnecessary macro definition.
+
+ * tst-mutex7.c (do_test): Limit thread stack size.
+ * tst-once2.c (do_test): Likewise.
+ * tst-tls3.c (do_test): Likewise.
+ * tst-tls1.c (do_test): Likewise.
+ * tst-signal3.c (do_test): Likewise.
+ * tst-kill6.c (do_test): Likewise.
+ * tst-key4.c (do_test): Likewise.
+ * tst-join4.c (do_test): Likewise.
+ * tst-fork1.c (do_test): Likewise.
+ * tst-context1.c (do_test): Likewise.
+ * tst-cond2.c (do_test): Likewise.
+ * tst-cond10.c (do_test): Likewise.
+ * tst-clock2.c (do_test): Likewise.
+ * tst-cancel10.c (do_test): Likewise.
+ * tst-basic2.c (do_test): Likewise.
+ * tst-barrier4.c (do_test): Likewise.
+
+2004-03-05 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/i386/tls.h: Use GLRO instead of GL where appropriate.
+
+2004-03-01 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S
+ (__pthread_cond_timedwait): Optimize wakeup test.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S
+ (__pthread_cond_wait): Likewise.
+ * sysdeps/pthread/pthread_cond_wait.c (__pthread_cond_wait): Likewise.
+ * sysdeps/pthread/pthread_cond_timedwait.c (__pthread_cond_timedwait):
+ Likewise.
+
+2004-02-29 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S
+ (__lll_mutex_lock_wait): Optimize a bit more. Just one copy of
+ the atomic instruction needed.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
+ (__lll_mutex_lock_wait): Likewise.
+
+2004-02-28 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-cond14 and tst-cond15.
+ * tst-cond14.c: New file.
+ * tst-cond15.c: New file.
+
+2004-02-27 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/createthread.c (create_thread): Remove use of
+ CLONE_STOPPED. We cannot use SIGCONT which means CLONE_STOPPED
+ needs to be implemented differently to be useful.
+
+2004-02-26 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread_attr_setschedparam.c: Don't test priority against limits
+ here. Set ATTR_FLAG_SCHED_SET flag.
+ * pthread_attr_setschedpolicy.c: Set ATTR_FLAG_POLICY_SET flag.
+ * pthread_create.c (__pthread_create_2_1): Copy scheduling attributes
+ from parent thread to child. If attribute is used and scheduling
+ parameters are not inherited, copy parameters from attribute or
+ compute them. Check priority value.
+ * pthread_getschedparam.c: If the parameters aren't known yet get
+ them from the kernel.
+ * pthread_setschedparam.c: Set ATTR_FLAG_SCHED_SET and
+ ATTR_FLAG_POLICY_SET flag for thread.
+ * sysdeps/unix/sysv/linux/internaltypes.h: Define ATTR_FLAG_SCHED_SET
+ and ATTR_FLAG_POLICY_SET.
+
+ * sysdeps/pthread/createthread.c: Use tgkill if possible.
+
+ * pthread_attr_getstackaddr.c (__pthread_attr_getstackaddr): Don't
+ fail if stack address hasn't been set. Just return 0.
+
+2004-02-25 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests-nolibpthread): Add tst-unload. Don't link with
+ libpthread for the files in this list.
+ (CFLAGS-tst-unload): Removed.
+ * tst-unload.c (do_test): Don't use complete path for
+ LIBPHREAD_SO.
+
+ * Makefile: Define sonames for tst-tls5mod, tst-_res1mod1, and
+ tst-_res1mod2.
+
+2004-02-22 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S
+ (__lll_mutex_lock_wait): Rewrite so that only one locked memory
+ operation per round is needed.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
+ (__lll_mutex_lock_wait): Likewise.
+
+2004-02-20 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-cancel9.c (cleanup): Don't print to stderr.
+
+2004-02-20 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/sh/jmpbuf-unwind.h (_JMPBUF_UNWINDS_ADJ): Fix variable name.
+
+2004-02-20 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/sparc/sparc32/sysdep-cancel.h
+ (__syscall_error_handler2): Call CDISABLE.
+ * sysdeps/unix/sysv/linux/sparc/sparc64/sysdep-cancel.h
+ (__syscall_error_handler2): Call CDISABLE.
+
+ * sysdeps/pthread/pthread_barrier_wait.c (pthread_barrier_wait):
+ Release lock before the loop, don't reacquire it.
+
+ * sysdeps/unix/sysv/linux/ia64/dl-sysdep.h (DL_ARGV_NOT_RELRO): Define.
+
+2004-02-19 Andreas Schwab <schwab@suse.de>
+
+ * sysdeps/pthread/pthread_barrier_wait.c (pthread_barrier_wait):
+ Fix last change.
+
+2004-02-18 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_barrier_wait.S
+ (pthread_barrier_wait): After wakeup, release lock only when the
+ last thread stopped using the barrier object.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
+ (pthread_barrier_wait): Likewise.
+ * sysdeps/pthread/pthread_barrier_wait.c (pthread_barrier_wait):
+ Likewise.
+ * Makefile (tests): Add tst-barrier4.
+ * tst-barrier4.c: New file.
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S
+ (__pthread_cond_timedwait): Perform timeout test while holding
+ internal lock to prevent wakeup race.
+ Patch by Dinakar Guniguntala <dgunigun@in.ibm.com>.
+ * sysdeps/pthread/pthread_cond_timedwait.c
+ (__pthread_cond_timedwait): Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
+ (__pthread_cond_timedwait): Likewise.
+
+2004-02-18 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
+ (__pthread_rwlock_unlock): Access WRITER as 32-bit value.
+ * Makefile (tests): Add tst-rwlock13.
+ * tst-rwlock13.c: New test.
+
+2004-02-16 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S
+ (__condvar_tw_cleanup): Little optimization.
+ Patch by Dinakar Guniguntala <dgunigun@in.ibm.com>.
+
+2004-02-16 Steven Munroe <sjmunroe@us.ibm.com>
+
+ * sysdeps/unix/sysv/linux/powerpc/pt-longjmp.c: Replace libc with
+ libpthread as "lib" parameter to SHLIB_COMPAT.
+ (__novmx_siglongjmp): Fix typo in function name.
+ (__novmx_longjmp): Fix typo in function name.
+
+2004-02-13 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/pthread_cond_wait.c (__pthread_cond_wait): Add a
+ __builtin_expect.
+
+ * sysdeps/generic/pt-longjmp.c: Moved to...
+ * sysdeps/pthread/pt-longjmp.c: ...here. New file.
+
+2004-01-29 Steven Munroe <sjmunroe@us.ibm.com>
+
+ * Makefile (libpthread-routines): Add pt-cleanup.
+ * pt-longjmp.c: Removed.
+ * pt-cleanup.c: Copied __pthread_cleanup_upto to here. New file.
+ * sysdeps/generic/pt-longjmp.c: Copied longjmp to here. New file.
+ * sysdeps/unix/sysv/linux/powerpc/Versions: New file.
+ Version longjmp, siglongjmp for GLIBC_2.3.4.
+ * sysdeps/unix/sysv/linux/powerpc/pt-longjmp.c: New File.
+
+2004-02-13 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/pthread_cond_timedwait.c
+ (__pthread_cond_timedwait): Optimize. Drop internal lock earlier.
+ Reuse code. Add __builtin_expects.
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S
+ (__pthread_cond_timedwait): Get internal lock in case timeout has
+ passed before the futex syscall.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: Likewise.
+
+2004-01-20 Ulrich Drepper <drepper@redhat.com>
+
+ * allocatestack.c: Pretty printing.
+
+ * sysdeps/pthread/createthread.c (create_thread): Don't add
+ CLONE_DETACHED bit if it is not necessary.
+
+2004-01-16 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread_getattr_np.c: Include ldsodefs.h.
+
+2004-01-16 Richard Henderson <rth@redhat.com>
+
+ * allocatestack.c: Don't declare __libc_stack_end.
+ * init.c (__pthread_initialize_minimal_internal): Likewise.
+ * pthread_getattr_np.c (pthread_getattr_np): Likewise.
+
+2004-01-15 Richard Henderson <rth@redhat.com>
+
+ * sysdeps/alpha/tls.h (tcbhead_t): Add private.
+ (TLS_INIT_TCB_SIZE, TLS_INIT_TCB_ALIGN, TLS_TCB_SIZE,
+ TLS_PRE_TCB_SIZE, TLS_TCB_ALIGN, INSTALL_DTV, INSTALL_NEW_DTV,
+ GET_DTV, THREAD_DTV, THREAD_SELF, DB_THREAD_SELF): Match ia64.
+ (TLS_TCB_OFFSET, THREAD_ID, NO_TLS_OFFSET): Remove.
+ (THREAD_GETMEM, THREAD_GETMEM_NC): Simplify.
+ (THREAD_SETMEM, THREAD_SETMEM_NC): Likewise.
+ * sysdeps/unix/sysv/linux/alpha/createthread.c (TLS_VALUE): Match ia64.
+
+2004-01-14 Ulrich Drepper <drepper@redhat.com>
+
+ * init.c (pthread_functions): Make array const.
+
+2004-01-13 Ulrich Drepper <drepper@redhat.com>
+
+ * allocatestack.c (__make_stacks_executable): Change interface.
+ Check parameters. Pass parameter on to libc counterpart.
+ * pthreadP.h: Change declaration.
+
+2004-01-13 Richard Henderson <rth@redhat.com>
+
+ * pthread_attr_setstack.c (__old_pthread_attr_setstack): Use
+ prototype form.
+ * pthread_attr_setstacksize.c (__old_pthread_attr_setstacksize):
+ Likewise.
+
+ * sysdeps/alpha/Makefile: New file.
+ * sysdeps/alpha/tcb-offsets.sym: New file.
+ * sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h (SINGLE_THREAD_P):
+ Use MULTIPLE_THREADS_OFFSET to implement !libpthread !libc version.
+
+ * sysdeps/unix/sysv/linux/alpha/lowlevellock.h: Rewrite based
+ on powerpc version.
+
+2004-01-08 Jakub Jelinek <jakub@redhat.com>
+
+ * Makefile (tests): Add tst-backtrace1.
+ * tst-backtrace1.c: New test.
+
+2003-12-11 Ulrich Weigand <uweigand@de.ibm.com>
+
+ * sysdeps/alpha/tls.h (DB_THREAD_SELF): Pass bit size of thread
+ register as second parameter to the REGISTER macro.
+ * sysdeps/ia64/tls.h (DB_THREAD_SELF): Likewise.
+ * sysdeps/powerpc/tls.h (DB_THREAD_SELF): Likewise.
+ * sysdeps/sh/tls.h (DB_THREAD_SELF): Likewise.
+ * sysdeps/sparc/tls.h (DB_THREAD_SELF): Likewise.
+ * sysdeps/s390/tls.h (DB_THREAD_SELF): Pass __WORDSIZE as bit size
+ of thread register as second parameter to REGISTER macro in 64 case.
+
+2004-01-03 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/Makefile (CFLAGS-getpid.c): Removed.
+ (CFLAGS-getpid.o): Defined.
+ (CFLAGS-getpid.os): Defined.
+
+2003-12-31 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread_getattr_np.c (pthread_getattr_np): Make sure stack info
+ returned for main thread does not overlap with any other VMA.
+ Patch by Jakub Jelinek.
+
+2003-12-29 Jakub Jelinek <jakub@redhat.com>
+
+ * tst-raise1.c: Include stdio.h.
+
+2003-12-23 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/raise.c (raise): Protect pid = selftid
+ setting with __ASSUME_TGKILL || defined __NR_tgkill.
+ If pid is 0, set it to selftid.
+ * sysdeps/unix/sysv/linux/getpid.c (really_getpid): Make inline.
+ Don't set self->pid but self->tid. If self->pid == 0 and self->tid
+ != 0, return self->tid without doing a syscall.
+ * descr.h (struct pthread): Move pid field after tid.
+
+ * Makefile (tests): Add tst-raise1.
+ * tst-raise1.c: New file.
+
+2003-12-23 Roland McGrath <roland@redhat.com>
+
+ * tst-oddstacklimit.c: New file.
+ * Makefile (tests): Add it.
+ (tst-oddstacklimit-ENV): New variable.
+
+ * init.c (__pthread_initialize_minimal_internal): Round stack rlimit
+ value up to page size for __default_stacksize.
+
+2003-12-21 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-eintr5.
+ * tst-eintr5.c: New file.
+
+ * eintr.c (eintr_source): Prevent sending signal to self.
+
+ * tst-eintr2.c (tf1): Improve error message.
+
+2003-12-20 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/Makefile (CFLAGS-getpid.c): Define.
+ * sysdeps/unix/sysv/linux/getpid.c: New file.
+ * pthread_cancel.c: Add comment explaining use of PID field.
+ * sysdeps/unix/sysv/linux/pthread_kill.c: Likewise.
+ * pthread_getattr_np.c: Use abs() when comparing PID and TID fields.
+ * sysdeps/unix/sysv/linux/fork.c: Negate PID field of parent
+ temporarily to signal the field must not be relied on and updated
+ by getpid().
+ * sysdeps/unix/sysv/linux/pt-raise.c: Handle case where PID is
+ temporarily negative.
+ * sysdeps/unix/sysv/linux/raise.c: Likewise.
+
+2003-12-19 Ulrich Drepper <drepper@redhat.com>
+
+ * eintr.c (setup_eintr): Add new parameter. Pass to thread function.
+ (eintr_source): If ARG != NULL, use pthread_kill.
+ * tst-eintr1.c: Adjust for this change.
+ * tst-eintr2.c: Likewise.
+ * Makefile (tests): Add tst-eintr3 and tst-eintr4.
+ * tst-eintr3.c: New file.
+ * tst-eintr4.c: New file.
+
+2003-12-19 Jakub Jelinek <jakub@redhat.com>
+
+ * libc-cancellation.c (__libc_enable_asynccancel): Don't cancel
+ if CANCELSTATE_BITMASK is set.
+ * sysdeps/pthread/librt-cancellation.c (__librt_enable_asynccancel):
+ Likewise.
+
+ * Makefile (tests): Add tst-cancel22 and tst-cancel23.
+ (tests-reverse): Add tst-cancel23.
+ * tst-cancel22.c: New test.
+ * tst-cancel23.c: New test.
+
+2003-12-18 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-eintr1.c: Better error messages.
+
+ * Makefile (tests): Add tst-eintr2.
+ * tst-eintr2.c: New file.
+
+2003-12-18 Jakub Jelinek <jakub@redhat.com>
+
+ * Makefile (tests): Add tst-cancel21 and tst-cancelx21.
+ (CFLAGS-tst-cancelx21.c): Set.
+ * tst-cancel21.c: New test.
+ * tst-cancelx21.c: New test.
+
+ * unwind.c (FRAME_LEFT): Add adj argument. Subtract it from each
+ comparison operand.
+ (unwind_stop): Use _JMPBUF_CFA_UNWINDS_ADJ macro instead of
+ _JMPBUF_CFA_UNWINDS. Adjust FRAME_LEFT invocations.
+ * pt-longjmp.c: Include jmpbuf-unwind.h.
+ (__pthread_cleanup_upto): Use _JMPBUF_UNWINDS_ADJ macro instead of
+ _JMPBUF_UNWINDS. Adjust compared pointers.
+ * init.c (__pthread_initialize_minimal_internal): Initialize
+ pd->stackblock_size.
+ * sysdeps/pthread/jmpbuf-unwind.h: Removed.
+ * sysdeps/alpha/jmpbuf-unwind.h: New file.
+ * sysdeps/i386/jmpbuf-unwind.h: New file.
+ * sysdeps/powerpc/jmpbuf-unwind.h: New file.
+ * sysdeps/s390/jmpbuf-unwind.h: New file.
+ * sysdeps/sh/jmpbuf-unwind.h: New file.
+ * sysdeps/sparc/sparc32/jmpbuf-unwind.h: New file.
+ * sysdeps/x86_64/jmpbuf-unwind.h: New file.
+ * sysdeps/unix/sysv/linux/ia64/jmpbuf-unwind.h: Include stdint.h.
+ (_JMPBUF_CFA_UNWINDS): Remove.
+ (_JMPBUF_CFA_UNWINDS_ADJ, _JMPBUF_UNWINDS_ADJ): Define.
+
+2003-12-12 Jakub Jelinek <jakub@redhat.com>
+
+ * Makefile (tests): Add tst-cancel20 and tst-cancelx20.
+ (CFLAGS-tst-cancelx20.c): Set.
+ * tst-cancel20.c: New test.
+ * tst-cancelx20.c: New test.
+
+2003-12-17 Ulrich Drepper <drepper@redhat.com>
+
+ * init.c (__pthread_initialize_minimal_internal): Don't treat
+ architectures with separate register stack special here when
+ computing default stack size.
+
+2003-12-17 Roland McGrath <roland@redhat.com>
+
+ * Makefile (tst-cancelx7-ARGS): New variable.
+ Reportd by Greg Schafer <gschafer@zip.com.au>.
+
+2003-12-17 Jakub Jelinek <jakub@redhat.com>
+
+ * Makefile (tests): Add tst-stack3. Depend on $(objpfx)tst-stack3-mem.
+ (generated): Add tst-stack3.mtrace and tst-stack3-mem.
+ (tst-stack3-ENV): Set.
+ ($(objpfx)tst-stack3-mem): New.
+ * tst-stack3.c: New test.
+
+2003-12-10 David Mosberger <davidm@hpl.hp.com>
+
+ * sysdeps/unix/sysv/linux/ia64/pt-initfini.c (_init_EPILOG_BEGINS):
+ Add unwind directives. Drop unused .regstk directive.
+ (_fini_EPILOG_BEGINS): Add unwind directives.
+
+2003-12-11 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h (lll_futex_wait):
+ Assume parameter is a pointer.
+ (lll_futex_wake): Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h (lll_futex_wait):
+ Likewise.
+ (lll_futex_wake): Likewise.
+ Reported by Boris Hu.
+ * sysdeps/unix/sysv/linux/unregister-atfork.c
+ (__unregister_atfork): Pass pointer to refcntr to lll_futex_wait.
+
+ * sysdeps/unix/sysv/linux/sem_wait.c (__new_sem_wait): Simplify a bit.
+
+2003-12-10 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/bits/libc-lock.h (__rtld_lock_initialize): Define.
+ * sysdeps/unix/sysv/linux/fork.c (__libc_fork): Call
+ __rtld_lock_initialize for ld.so lock.
+ Patch in part by Adam Li <adam.li@intel.com>.
+
+2003-12-02 David Mosberger <davidm@hpl.hp.com>
+
+ * Makefile (link-libc-static): Remove -lgcc_eh---it's already mentioned
+ in $(gnulib). Also, remove stale comment.
+
+2003-11-12 David Mosberger <davidm@hpl.hp.com>
+
+ * sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h (PSEUDO): Take
+ advantage of new syscall stub and optimize accordingly.
+
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.h (__NR_futex): Rename
+ from SYS_futex, to match expectations of
+ sysdep.h:DO_INLINE_SYSCALL.
+ (lll_futex_clobbers): Remove.
+ (lll_futex_timed_wait): Rewrite in terms of DO_INLINE_SYSCALL.
+ (lll_futex_wake): Likewise.
+ (lll_futex_requeue): Likewise.
+ (__lll_mutex_trylock): Rewrite to a macro, so we can include this
+ file before DO_INLINE_SYSCALL is defined (proposed by Jakub
+ Jelinek).
+ (__lll_mutex_lock): Likewise.
+ (__lll_mutex_cond_lock): Likewise.
+ (__lll_mutex_timed_lock): Likewise.
+ (__lll_mutex_unlock): Likewise.
+ (__lll_mutex_unlock_force): Likewise.
+
+ * sysdeps/ia64/tls.h: Move declaration of __thread_self up so it
+ comes before the include of <sysdep.h>.
+ (THREAD_SELF_SYSINFO): New macro.
+ (THREAD_SYSINFO): Likewise.
+ (INIT_SYSINFO): New macro.
+ (TLS_INIT_TP): Call INIT_SYSINFO.
+
+ * sysdeps/ia64/tcb-offsets.sym: Add SYSINFO_OFFSET.
+
+ * sysdeps/pthread/createthread.c (create_thread): Use
+ THREAD_SELF_SYSINFO and THREAD_SYSINFO instead of open code.
+ * allocatestack.c (allocate_stack): Use THREAD_SYSINFO and
+ THREAD_SELF_SYSINFO instead of open code.
+ * sysdeps/i386/tls.h (THREAD_SELF_SYSINFO): New macro.
+ (THREAD_SYSINFO): Likewise.
+
+ * sysdeps/unix/sysv/linux/ia64/dl-sysdep.h: New file.
+
+ * sysdeps/unix/sysv/linux/ia64/pt-vfork.S: Work around gas problem.
+
+2003-12-06 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/ia64/pt-initfini.c: Use .init_array
+ instead of .init. Patch by David Mosberger.
+
+2003-11-30 Thorsten Kukuk <kukuk@suse.de>
+
+ * sysdeps/pthread/configure.in: Remove broken declaration in C
+ cleanup handling check.
+
+2003-11-30 Andreas Jaeger <aj@suse.de>
+
+ * Makefile (CFLAGS-pt-initfini.s): Add $(fno_unit_at_a_time).
+ * sysdeps/unix/sysv/linux/x86_64/Makefile (CFLAGS-pt-initfini.s):
+ Likewise.
+
+2003-11-27 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/internaltypes.h (ATTR_FLAG_OLDATTR): Define.
+ * pthread_attr_destroy.c: Include shlib-compat.h.
+ (__pthread_attr_destroy): Return immediately if ATTR_FLAG_OLDATTR
+ is set in iattr->flags.
+ * pthread_attr_init.c (__pthread_attr_init_2_0): Set ATTR_FLAG_OLDATTR.
+
+2003-11-21 Jakub Jelinek <jakub@redhat.com>
+
+ * Makefile (distribute): Add tst-cleanup4aux.c.
+
+ * tst-cond12.c (prepare): Add prototype. Move after test-skeleton.c
+ include.
+
+2003-11-21 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-cond12.c (do_test): If USE_COND_SIGNAL is defined, use
+ pthread_cond_signal.
+
+ * sysdeps/pthread/pthread_cond_wait.c (__pthread_cond_wait): Don't
+ store mutex address if the current value is ~0l.
+ * sysdeps/pthread/pthread_cond_timedwait.c
+ (__pthread_cond_timedwait): Likewise.
+ * sysdeps/pthread/pthread_cond_broadcast.c
+ (__pthread_cond_broadcast): Don't use requeue for pshared
+ condvars.
+
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
+ (__pthread_cond_wait): Don't store mutex address if the current
+ value is ~0l.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
+ (__pthread_cond_timedwait): Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
+ (__pthread_cond_broadcast): Don't use requeue for pshared
+ condvars.
+
+ * pthread_cond_init.c (__pthread_cond_init): Initialize __mutex
+ element with ~0l for pshared condvars, with NULL otherwise.
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S
+ (__pthread_cond_wait): Don't store mutex address if the current
+ value is ~0l.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S
+ (__pthread_cond_timedwait): Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_broadcast.S
+ (__pthread_cond_broadcast): Don't use requeue for pshared
+ condvars.
+
+ * Makefile: Add rules to build and run tst-cond12 and tst-cond13.
+ * tst-cond12.c: New file.
+ * tst-cond13.c: New file.
+
+2003-11-17 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/configure.in: Make missing forced unwind support
+ fatal.
+
+2003-11-11 Ulrich Drepper <drepper@redhat.com>
+
+ * pthreadP.h: Don't declare __pthread_unwind as weak inside libpthread.
+
+2003-11-06 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile: Add magic to clean up correctly.
+
+2003-11-05 Jakub Jelinek <jakub@redhat.com>
+
+ * unwind.c (FRAME_LEFT): Define.
+ (unwind_stop): Handle old style cleanups here.
+ (__pthread_unwind): Handle old style cleanups only if
+ !HAVE_FORCED_UNWIND.
+ * Makefile (tests): Add tst-cleanup4 and tst-cleanupx4.
+ (CFLAGS-tst-cleanupx4.c): Add -fexceptions.
+ ($(objpfx)tst-cleanup4): Depend on $(objpfx)tst-cleanup4aux.o.
+ ($(objpfx)tst-cleanupx4): Likewise.
+ * tst-cleanup4.c: New test.
+ * tst-cleanup4aux.c: New.
+ * tst-cleanupx4.c: New test.
+
+2003-11-04 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/bits/stdio-lock.h: Use lll_*lock instead of
+ lll_mutex_*lock macros to skip atomic operations on some archs.
+
+2003-11-03 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/tst-timer.c (main): Initialize
+ sigev2.sigev_value as well.
+
+2003-10-15 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/pthread/configure.in: Barf if visibility attribute support
+ is missing.
+ * sysdeps/pthread/configure: Regenerated.
+
+2003-10-09 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/unix/sysv/linux/sh/lowlevellock.h: Completely revamp the
+ locking macros. No distinction between normal and mutex locking
+ anymore.
+ * sysdeps/unix/sysv/linux/sh/lowlevellock.S: Rewrite mutex locking.
+ Merge bits from lowlevelmutex.S we still need.
+ * sysdeps/unix/sysv/linux/sh/libc-lowlevelmutex.S: Remove.
+ * sysdeps/unix/sysv/linux/sh/lowlevelmutex.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/not-cancel.h: New file.
+ * sysdeps/unix/sysv/linux/sh/pthread_barrier_wait.S: Adjust for
+ new mutex implementation.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_broadcast.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_signal.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_wait.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_rdlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedrdlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedwrlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_unlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_wrlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/sysdep-cancel.h (PSEUDO): Also defined
+ symbol for entry point to avoid cancellation.
+
+2003-10-07 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/sysdep-cancel.h: Backout 2003-10-02
+ changes.
+ (SAVE_OLDTYPE_0): Fix a typo.
+
+2003-10-03 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/pthread_once.S (__pthread_once):
+ Check __sigsetjmp return value. Reported by Daniel Jacobowitz.
+
+2003-10-02 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/sysdep-cancel.h (DOCARGS_1): Use
+ correct offset.
+
+2003-10-02 Jakub Jelinek <jakub@redhat.com>
+
+ * Makefile (tests): Add tst-cancel19.
+ * tst-cancel19.c: New test.
+
+2003-10-02 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/sysdep-cancel.h: Fix saving and
+ restoring of the old cancellation type.
+
+2003-09-30 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/pthread/malloc-machine.h: Remove misleading comment.
+
+2003-09-27 Wolfram Gloger <wg@malloc.de>
+
+ * sysdeps/pthread/malloc-machine.h: New file
+
+2003-09-24 Roland McGrath <roland@redhat.com>
+
+ * allocatestack.c (__make_stacks_executable): Don't ignore return
+ value from _dl_make_stack_executable.
+
+2003-09-24 Ulrich Drepper <drepper@redhat.com>
+
+ * allocatestack.c (__make_stacks_executable): Also change
+ permission of the currently unused stacks.
+
+ * allocatestack.c (change_stack_perm): Split out from
+ __make_stacks_executable.
+ (allocate_stack): If the required permission changed between the time
+ we started preparing the stack and queueing it, change the permission.
+ (__make_stacks_executable): Call change_stack_perm.
+
+ * Makefile: Build tst-execstack-mod locally.
+ * tst-execstack-mod.c: New file.
+
+2003-09-23 Jakub Jelinek <jakub@redhat.com>
+
+ * Makefile (tests): Only add tst-execstack if have-z-execstack is yes.
+
+2003-09-23 Roland McGrath <roland@redhat.com>
+
+ * tst-execstack.c: New file.
+ * Makefile (tests): Add it.
+ ($(objpfx)tst-execstack, $(objpfx)tst-execstack.out): New targets.
+ (LDFLAGS-tst-execstack): New variable.
+
+ * allocatestack.c (allocate_stack): Use GL(dl_stack_flags) to decide
+ whether to use PROT_EXEC for stack mmap.
+ (__make_stacks_executable): New function.
+ * pthreadP.h: Declare it.
+ * init.c (__pthread_initialize_minimal_internal): Set
+ GL(dl_make_stack_executable_hook) to that.
+
+2003-09-22 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h: Adjust for latest
+ recommendation from AMD re avoidance of lock prefix.
+
+2003-09-22 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/lowlevellock.c (__lll_timedlock_wait): Use
+ lll_futex_timed_wait instead of lll_futex_wait.
+ * sysdeps/unix/sysv/linux/s390/lowlevellock.c: Removed.
+ * sysdeps/unix/sysv/linux/s390/lowlevelmutex.c: Removed.
+ * sysdeps/unix/sysv/linux/s390/libc-lowlevellock.c: Removed.
+ * sysdeps/unix/sysv/linux/s390/libc-lowlevelmutex.c: Removed.
+ * sysdeps/unix/sysv/linux/s390/sem_trywait.c: Removed.
+ * sysdeps/unix/sysv/linux/s390/sem_wait.c: Removed.
+ * sysdeps/unix/sysv/linux/s390/sem_post.c: Removed.
+ * sysdeps/unix/sysv/linux/s390/sem_timedwait.c: Removed.
+ * sysdeps/unix/sysv/linux/s390/lowlevellock.h: Include atomic.h.
+ Completely revamp the locking macros. No distinction between
+ normal and mutex locking anymore.
+ * sysdeps/unix/sysv/linux/sparc/lowlevellock.h: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.h (__lll_lock_wait,
+ __lll_lock_timedwait): Fix prototypes.
+ * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h (__lll_lock_wait,
+ __lll_lock_timedwait): Likewise.
+ (lll_mutex_lock, lll_mutex_cond_lock): Use _val instead of _bool
+ macros, add __builtin_expect.
+ (lll_mutex_timedlock): Likewise. Fix return value.
+ * sysdeps/unix/sysv/linux/i386/i486/libc-lowlevelmutex.S: Removed.
+ * sysdeps/unix/sysv/linux/i386/i586/libc-lowlevelmutex.S: Removed.
+ * sysdeps/unix/sysv/linux/i386/i586/lowlevelmutex.S: Removed.
+ * sysdeps/unix/sysv/linux/i386/i686/libc-lowlevelmutex.S: Removed.
+ * sysdeps/unix/sysv/linux/i386/i686/lowlevelmutex.S: Removed.
+ * sysdeps/unix/sysv/linux/x86_64/libc-lowlevelmutex.S: Removed.
+ * sysdeps/unix/sysv/linux/lowlevelmutex.c: Removed.
+ * sysdeps/unix/sysv/linux/libc-lowlevelmutex.c: Removed.
+
+2003-09-22 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S
+ (__lll_mutex_lock_wait): Minor optimization to avoid one atomic
+ operation if possible.
+
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h: Don't play tricks
+ like jumping over the lock prefix.
+
+2003-09-21 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h: Completely revamp the
+ locking macros. No distinction between normal and mutex locking
+ anymore.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.h: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S: Rewrite mutex
+ locking. Merge bits from lowlevelmutex.S we still need.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.S: Likewise.
+ * sysdeps/unix/sysv/linux/lowlevellock.c: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelmutex.S: Removed.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevelmutex.S: Removed.
+ * Makefile (routines): Remove libc-lowlevelmutex.
+ (libpthread-rountines): Remove lowlevelmutex.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_barrier_wait.S: Adjust
+ for new mutex implementation.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_broadcast.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_rdlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S:
+ Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S:
+ Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_unlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_wrlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S: Likewise
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S:
+ Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S:
+ Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_signal.S: Likewise.
+ Don't use requeue.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S: Likewise.
+ * sysdeps/pthread/pthread_cond_signal.c: Don't use requeue.
+
+2003-09-20 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h: Don't match memory
+ in parameters of asm with output parameters.
+
+ * pthread_mutex_unlock.c (__pthread_mutex_unlock_usercnt): Change
+ type of DECR parameter to int.
+ * pthreadP.h: Adjust prototype of __pthread_mutex_unlock_usercnt.
+
+2003-09-18 Jakub Jelinek <jakub@redhat.com>
+
+ * tst-attr3.c (tf, do_test): Print stack start/end/size and
+ guardsize for each thread.
+
+2003-09-17 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/pthread/pthread.h (pthread_getattr_np): Clarify usage.
+ * sysdeps/unix/sysv/linux/pthread_attr_setaffinity.c
+ (pthread_attr_setaffinity_np): Handle cpuset == NULL.
+
+ * sysdeps/unix/sysv/linux/pthread_attr_getaffinity.c
+ (pthread_attr_getaffinity_np): Don't segfault if iattr->cpuset is
+ NULL.
+ * pthread_getattr_np.c: Set cpuset using pthread_getaffinity_np.
+ * pthreadP.h (pthread_getaffinity_np): Add hidden_proto.
+ * sysdeps/unix/sysv/linux/pthread_getaffinity.c
+ (pthread_getaffinity_np): Add hidden_def.
+
+ * Makefile (tests): Add tst-attr3.
+ * tst-attr3.c: New test.
+
+ * sysdeps/i386/Makefile (CFLAGS-tst-align.c): Remove.
+
+2003-09-15 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/i386/Makefile (CFLAGS-pthread_create.c,
+ CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
+
+2003-09-17 Jakub Jelinek <jakub@redhat.com>
+
+ * Makefile (CFLAGS-tst-align.c): Add $(stack-align-test-flags).
+ * tst-align.c: Include tst-stack-align.h.
+ (tf, do_test): Use TEST_STACK_ALIGN macro.
+
+2003-09-17 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread_attr_init.c (__pthread_attr_init_2_0): Remove unused
+ variable.
+
+2003-09-16 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread_getattr_np.c (pthread_getattr_np): Correctly fill in the
+ stack-related values for the initial thread.
+
+2003-09-15 Jakub Jelinek <jakub@redhat.com>
+
+ * Makefile (CFLAGS-pthread_once.c): Add $(uses-callbacks).
+
+2003-09-11 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread_mutex_lock.c: Minor code rearrangements.
+
+2003-09-05 Roland McGrath <roland@redhat.com>
+
+ * pthread_create.c (__pthread_pthread_sizeof_descr): Removed.
+ Instead, include ../nptl_db/db_info.c to do its magic.
+ * pthread_key_create.c (__pthread_pthread_keys_max): Removed.
+ (__pthread_pthread_key_2ndlevel_size): Likewise.
+ * sysdeps/alpha/tls.h (DB_THREAD_SELF): New macro.
+ * sysdeps/i386/tls.h (DB_THREAD_SELF): New macro.
+ * sysdeps/ia64/tls.h (DB_THREAD_SELF): New macro.
+ * sysdeps/powerpc/tls.h (DB_THREAD_SELF): New macro.
+ * sysdeps/s390/tls.h (DB_THREAD_SELF): New macro.
+ * sysdeps/sh/tls.h (DB_THREAD_SELF): New macro.
+ * sysdeps/sparc/tls.h (DB_THREAD_SELF): New macro.
+ * sysdeps/x86_64/tls.h (DB_THREAD_SELF): New macro.
+ * sysdeps/alpha/td_ta_map_lwp2thr.c: File removed.
+ * sysdeps/generic/td_ta_map_lwp2thr.c: File removed.
+ * sysdeps/i386/td_ta_map_lwp2thr.c: File removed.
+ * sysdeps/ia64/td_ta_map_lwp2thr.c: File removed.
+ * sysdeps/powerpc/td_ta_map_lwp2thr.c: File removed.
+ * sysdeps/s390/td_ta_map_lwp2thr.c: File removed.
+ * sysdeps/sh/td_ta_map_lwp2thr.c: File removed.
+ * sysdeps/sparc/td_ta_map_lwp2thr.c: File removed.
+ * sysdeps/x86_64/td_ta_map_lwp2thr.c: File removed.
+
+2003-09-08 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h: Change type
+ of pthread_t to be compatible with LT.
+ * sysdeps/unix/sysv/linux/sparc/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h: Likewise.
+
+2003-09-04 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/not-cancel.h (fcntl_not_cancel): Define.
+
+2003-09-04 Jakub Jelinek <jakub@redhat.com>
+
+ * unwind-forcedunwind.c: Move to...
+ * sysdeps/pthread/unwind-forcedunwind.c: ...here.
+ (pthread_cancel_init): Use ARCH_CANCEL_INIT if defined.
+ * sysdeps/pthread/jmpbuf-unwind.h: New file.
+ * sysdeps/unix/sysv/linux/ia64/unwind-forcedunwind.c: New file.
+ * sysdeps/unix/sysv/linux/ia64/jmpbuf-unwind.h: New file.
+ * unwind.c: Include jmpbuf-unwind.h.
+ (unwind_stop): Use _JMPBUF_CFA_UNWINDS macro.
+
+2003-09-02 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/ia64/bits/local_lim.h: New file.
+ * sysdeps/unix/sysv/linux/ia64/Versions (libpthread): Export
+ pthread_attr_setstack and pthread_attr_setstacksize @@GLIBC_2.3.3.
+ * sysdeps/unix/sysv/linux/alpha/bits/local_lim.h: New file.
+ * sysdeps/unix/sysv/linux/alpha/Versions: New file.
+ * sysdeps/unix/sysv/linux/sparc/bits/local_lim.h: New file.
+ * sysdeps/unix/sysv/linux/sparc/Versions: New file.
+ * pthread_attr_setstack.c (__old_pthread_attr_setstack): New function.
+ (pthread_attr_setstack): If PTHREAD_STACK_MIN != 16384, export
+ as @@GLIBC_2.3.2 and also export compatibility @GLIBC_2.2.
+ * pthread_attr_setstacksize.c (__old_pthread_attr_setstacksize): New
+ function.
+ (pthread_attr_setstacksize): If PTHREAD_STACK_MIN != 16384, export
+ as @@GLIBC_2.3.2 and also export compatibility @GLIBC_2.1.
+ * Makefile (tests): Add tst-stack2.
+ * tst-stack2.c: New test.
+ * tst-stack1.c: Include limits.h and sys/param.h.
+ (do_test): Set size to MAX (4 * getpagesize (), PTHREAD_STACK_MIN).
+
+ * pthread_condattr_setpshared.c: Include errno.h.
+ (pthread_condattr_setpshared): Return EINVAL if pshared
+ is neither PTHREAD_PROCESS_PRIVATE nor PTHREAD_PROCESS_SHARED.
+
+ * sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h (PSEUDO): Also
+ defined symbol for entry point to avoid cancellation.
+ * sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h (PSEUDO):
+ Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h (PSEUDO):
+ Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h (PSEUDO):
+ Likewise.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/sysdep-cancel.h (PSEUDO):
+ Likewise.
+ * sysdeps/unix/sysv/linux/sparc/sparc64/sysdep-cancel.h (PSEUDO):
+ Likewise.
+ * sysdeps/unix/sysv/linux/i386/not-cancel.h (__open_nocancel,
+ __close_nocancel, __read_nocancel, __write_nocancel,
+ __waitpid_nocancel): Add attribute_hidden. If not in libc.so,
+ libpthread.so or librt.so, define to corresponding function
+ without _nocancel suffix.
+ * sysdeps/unix/sysv/linux/s390/not-cancel.h: New file.
+ * sysdeps/unix/sysv/linux/powerpc/not-cancel.h: New file.
+ * sysdeps/unix/sysv/linux/sparc/not-cancel.h: New file.
+
+ * sysdeps/unix/sysv/linux/x86_64/not-cancel.h: Fix a typo.
+
+2003-09-02 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/not-cancel.h: New file.
+ * sysdeps/unix/sysv/linux/x86_64/not-cancel.h: New file.
+
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h: Make sure the code
+ in subsections has a symbol associated with it.
+
+ * sysdeps/unix/sysv/linux/i386/sysdep-cancel.h (PSEUDO): Also
+ defined symbol for entry point to avoid cancellation.
+ * sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h (PSEUDO): Likewise.
+
+2003-09-01 Jakub Jelinek <jakub@redhat.com>
+
+ * Makefile (tests): Add tst-tls5.
+ (module-names): Add tst-tls5mod{,a,b,c,d,e,f}.
+ ($(objpfx)tst-tls5mod{,a,b,c,d,e,f}.so-no-z-defs): Set to yes.
+ ($(objpfx)tst-tls5): New.
+ ($(objpfx)tst-tls6.out): Likewise.
+ (tests): Depend on $(objpfx)tst-tls6.out.
+ * tst-tls3.c: Include stdint.h and pthreaddef.h.
+ (do_test): Check pthread_self () return value alignment.
+ * tst-tls3mod.c: Include stdint.h and pthreaddef.h.
+ (tf): Check pthread_self () return value alignment.
+ * tst-tls5.c: New test.
+ * tst-tls5.h: New.
+ * tst-tls5mod.c: New.
+ * tst-tls5moda.c: New.
+ * tst-tls5modb.c: New.
+ * tst-tls5modc.c: New.
+ * tst-tls5modd.c: New.
+ * tst-tls5mode.c: New.
+ * tst-tls5modf.c: New.
+ * tst-tls6.sh: New test.
+
+ * sysdeps/pthread/pthread-functions.h (struct pthread_functions): Add
+ ptr___pthread_cond_timedwait and ptr___pthread_cond_timedwait_2_0.
+ * init.c (pthread_functions): Initialize them.
+ * forward.c (pthread_cond_timedwait@GLIBC_2.0,
+ pthread_cond_timedwait@@GLIBC_2.3.2): New forwards.
+ * Versions (libc): Export pthread_cond_timedwait@GLIBC_2.0,
+ pthread_cond_timedwait@@GLIBC_2.3.2.
+
+2003-09-01 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/alpha/timer_create.c: New file.
+ * sysdeps/unix/sysv/linux/alpha/timer_delete.c: New file.
+ * sysdeps/unix/sysv/linux/alpha/timer_getoverr.c: New file.
+ * sysdeps/unix/sysv/linux/alpha/timer_gettime.c: New file.
+ * sysdeps/unix/sysv/linux/alpha/timer_settime.c: New file.
+ * sysdeps/unix/sysv/linux/alpha/Versions: New file.
+
+ * sysdeps/unix/sysv/linux/alpha/aio_cancel.c: New file.
+
+ * sysdeps/unix/sysv/linux/ia64/bits/posix_opt.h: Define
+ _POSIX_THREAD_PRIORITY_SCHEDULING.
+ * sysdeps/unix/sysv/linux/x86_64/bits/posix_opt.h: Likewise.
+
+2003-08-31 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/bits/stdio-lock.h (_IO_acquire_lock): Avoid
+ nested function, use static inline function from libio.h.
+ Code by Richard Henderson.
+
+ * sysdeps/pthread/bits/libc-lock.h: Mark pthread_setcancelstate as
+ weak.
+
+2003-08-30 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/sparc/sparc64/Versions: New file.
+ * sysdeps/unix/sysv/linux/sparc/sparc64/timer_create.c: New file.
+ * sysdeps/unix/sysv/linux/sparc/sparc64/timer_delete.c: New file.
+ * sysdeps/unix/sysv/linux/sparc/sparc64/timer_getoverr.c: New file.
+ * sysdeps/unix/sysv/linux/sparc/sparc64/timer_gettime.c: New file.
+ * sysdeps/unix/sysv/linux/sparc/sparc64/timer_settime.c: New file.
+ * sysdeps/unix/sysv/linux/sparc/sparc64/sysdep-cancel.h: New file.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/sysdep-cancel.h: New file.
+ * sysdeps/unix/sysv/linux/sparc/bits/pthreadtypes.h: New file.
+ * sysdeps/unix/sysv/linux/sparc/bits/semaphore.h: New file.
+ * sysdeps/unix/sysv/linux/sparc/lowlevellock.h: New file.
+ * sysdeps/unix/sysv/linux/sparc/pthread_once.c: New file.
+ * sysdeps/unix/sysv/linux/sparc/pt-vfork.S: New file.
+ * sysdeps/unix/sysv/linux/sparc/fork.c: New file.
+ * sysdeps/unix/sysv/linux/sparc/aio_cancel.c: New file.
+ * sysdeps/sparc/sparc32/sparcv9/pthread_spin_lock.c: New file.
+ * sysdeps/sparc/sparc32/sparcv9/pthread_spin_trylock.c: New file.
+ * sysdeps/sparc/sparc32/sparcv9/pthread_spin_unlock.c: New file.
+ * sysdeps/sparc/sparc32/pthread_spin_lock.c: New file.
+ * sysdeps/sparc/sparc32/pthread_spin_trylock.c: New file.
+ * sysdeps/sparc/sparc32/pthreaddef.h: New file.
+ * sysdeps/sparc/sparc64/pthread_spin_lock.c: New file.
+ * sysdeps/sparc/sparc64/pthread_spin_trylock.c: New file.
+ * sysdeps/sparc/sparc64/pthread_spin_unlock.c: New file.
+ * sysdeps/sparc/sparc64/pthreaddef.h: New file.
+ * sysdeps/sparc/tls.h: New file.
+ * sysdeps/sparc/tcb-offsets.sym: New file.
+ * sysdeps/sparc/Makefile: New file.
+ * sysdeps/sparc/td_ta_map_lwp2thr.c: New file.
+ * init.c [__sparc__] (__NR_set_tid_address): Define.
+
+2003-08-29 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/pthread/bits/stdio-lock.h (_IO_acquire_lock,
+ _IO_release_lock): Define.
+
+2003-08-29 Jakub Jelinek <jakuB@redhat.com>
+
+ * tst-cancel4.c (tf_sigwait, tf_sigwaitinfo, tf_sigtimedwait): Add
+ sigemptyset before sigaddset. Reported by jreiser@BitWagon.com.
+
+2003-08-27 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/pthread.h (pthread_exit): Remove __THROW.
+ (__pthread_cleanup_class): Add missing return types of member
+ functions.
+
+2003-08-26 Steven Munroe <sjmunroe@us.ibm.com>
+
+ * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h
+ (lll_mutex_unlock_force): Add memory barrier between store and futex
+ syscall.
+
+2003-08-25 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-cancel4.c (do_test): Also unlink tempfname and remove
+ tempmsg in first loop.
+
+2003-08-18 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/bits/posix_opt.h: Define
+ _POSIX_THREAD_PRIORITY_SCHEDULING.
+ * sysdeps/unix/sysv/linux/i386/bits/posix_opt.h: Likewise.
+
+2003-08-07 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/pthread/bits/libc-lock.h [_LIBC && SHARED]
+ (__rtld_lock_default_lock_recursive,
+ __rtld_lock_default_unlock_recursive): Define.
+ [_LIBC && SHARED] (__rtld_lock_lock_recursive,
+ __rtld_lock_unlock_recursive): Define using
+ GL(_dl_rtld_*lock_recursive).
+ * init.c (__pthread_initialize_minimal_internal): Initialize
+ _dl_rtld_lock_recursive and _dl_rtld_unlock_recursive.
+ Lock GL(_dl_load_lock) the same number of times as
+ GL(_dl_load_lock) using non-mt implementation was nested.
+
+ * pthreadP.h (__pthread_cleanup_upto): Add hidden_proto.
+ * pt-longjmp.c (__pthread_cleanup_upto): Add hidden_def.
+
+2003-08-06 Jakub Jelinek <jakub@redhat.com>
+
+ * tst-cancel17.c (do_test): Make len2 maximum of page size and
+ PIPE_BUF.
+
+2003-08-07 Jakub Jelinek <jakub@redhat.com>
+
+ * pthread_create.c (__pthread_create_2_0): Clear new_attr.cpuset.
+
+2003-08-03 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/pthread/createthread.c (do_clone): Move error handling
+ to first syscall error check. Move syscall error check for tkill
+ into __ASSUME_CLONE_STOPPED #ifdef.
+
+2003-08-02 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/createthread.c (do_clone): If __ASSUME_CLONE_STOPPED
+ is not defined, do explicit synchronization.
+ (create_thread): Do not lock pd->lock here. If __ASSUME_CLONE_STOPPED
+ is not defined also unlock pd->lock for non-debugging case in case
+ it is necessary.
+ * pthread_create.c (start_thread): Always get and release pd->lock
+ if __ASSUME_CLONE_STOPPED is not defined.
+ (start_thread_debug): Removed. Adjust users.
+ * allocatestack.c (allocate_stack): Always initialize lock if
+ __ASSUME_CLONE_STOPPED is not defined.
+ * Makefile (tests): Add tst-sched1.
+ * tst-sched1.c: New file.
+
+ * sysdeps/pthread/createthread.c (do_clone): Only use
+ sched_setschduler and pass correct parameters.
+
+2003-07-31 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/pthread/pthread.h (pthread_attr_setstackaddr,
+ pthread_attr_setstacksize): Change PTHREAD_STACK_SIZE to
+ PTHREAD_STACK_MIN in comments.
+
+2003-07-31 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/pthread/pthread_cond_timedwait.c (__pthread_cond_timedwait):
+ Shut up warnings if INTERNAL_SYSCALL_ERROR_P does not use its first
+ argument.
+ * sysdeps/unix/sysv/linux/timer_create.c (timer_create): Likewise.
+ * pthread_condattr_setclock.c (pthread_condattr_setclock): Likewise.
+ * sysdeps/unix/sysv/linux/s390/jmp-unwind.c: Include pthreaddef.h.
+ (__pthread_cleanup_upto): Fix prototype.
+ (_longjmp_unwind): Adjust caller.
+ * sysdeps/unix/sysv/linux/s390/lowlevellock.h (__lll_mutex_timedlock):
+ Change second argument to const struct pointer.
+ * tst-sem8.c (main): Remove unused s2 and s3 variables.
+ * tst-sem9.c (main): Likewise.
+ * unwind.c: Include string.h for strlen prototype.
+
+2003-07-31 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S
+ (__pthread_cond_timedwait): Don't use cmov unless HAVE_CMOV is defined.
+ * sysdeps/unix/sysv/linux/i386/i686/pthread_cond_timedwait.S:
+ Define HAVE_CMOV.
+ Patch by Nicholas Miell <nmiell@attbi.com>.
+
+2003-07-30 Jakub Jelinek <jakub@redhat.com>
+
+ * init.c (__pthread_initialize_minimal_internal): Initialize
+ GL(dl_init_static_tls).
+ * pthreadP.h (__pthread_init_static_tls): New prototype.
+ * allocatestack.c (init_one_static_tls, __pthread_init_static_tls):
+ New functions.
+ * Makefile (tests): Add tst-tls4.
+ (modules-names): Add tst-tls4moda and tst-tls4modb.
+ ($(objpfx)tst-tls4): Link against libdl and libpthread.
+ ($(objpfx)tst-tls4.out): Depend on tst-tls4moda.so and
+ tst-tls4modb.so.
+ * tst-tls4.c: New file.
+ * tst-tls4moda.c: New file.
+ * tst-tls4modb.c: New file.
+
+2003-06-19 Daniel Jacobowitz <drow@mvista.com>
+
+ * sysdeps/pthread/timer_create.c (timer_create): Call timer_delref
+ before __timer_dealloc.
+ * sysdeps/pthread/timer_routines.c (__timer_thread_find_matching):
+ Don't call list_unlink.
+
+2003-07-29 Roland McGrath <roland@redhat.com>
+
+ * Makefile [$(build-shared) = yes] (tests): Depend on $(test-modules).
+
+2003-07-25 Jakub Jelinek <jakub@redhat.com>
+
+ * tst-cancel17.c (do_test): Check if aio_cancel failed.
+ Don't reuse struct aiocb A if it failed.
+ Write fpathconf (fds[1], _PC_PIPE_BUF) + 2 bytes using aio_write,
+ not just one byte, as that does not block.
+
+2003-07-22 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/pthread/unwind-resume.c: New file.
+ * sysdeps/pthread/Makefile (routines, shared-only-routines): Add
+ unwind-resume in csu subdir.
+ (CFLAGS-unwind-resume.c, CFLAGS-rt-unwind-resume.c): Compile with
+ exceptions.
+ (librt-sysdep_routines, librt-shared-only-routines): Add
+ rt-unwind-resume.
+ * sysdeps/pthread/rt-unwind-resume.c: New file.
+ * unwind-forcedunwind.c: New file.
+ * Makefile (libpthread-routines): Add unwind-forcedunwind.
+ (libpthread-shared-only-routines): Likewise.
+ (CFLAGS-unwind-forcedunwind.c): Compile with exceptions.
+ * pthreadP.h (pthread_cancel_init): New prototype.
+ * pthread_cancel.c (pthread_cancel): Call pthread_cancel_init.
+
+ * sysdeps/pthread/createthread.c (do_thread, create_thread): Make
+ attr argument const struct pthread_attr *.
+
+ * res.c (__res_state): Return __resp.
+ * descr.h: Include resolv.h.
+ (struct pthread): Add res field.
+ * pthread_create.c: Include resolv.h.
+ (start_thread): Initialize __resp.
+ * Makefile (tests): Add tst-_res1.
+ (module-names): Add tst-_res1mod1, tst-_res1mod2.
+ ($(objpfx)tst-_res1mod2.so): Depend on $(objpfx)tst-_res1mod1.so.
+ ($(objpfx)tst-_res1): Depend on $(objpfx)tst-_res1mod2.so and
+ libpthread.
+ * tst-_res1.c: New file.
+ * tst-_res1mod1.c: New file.
+ * tst-_res1mod2.c: New file.
+
+2003-07-21 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/createthread.c: Don't define CLONE_STOPPED.
+
+ * Makefile: Define various *-no-z-defs variables for test DSOs
+ which has undefined symbols.
+
+2003-07-21 Steven Munroe <sjmunroe@us.ibm.com>
+
+ * sysdeps/unix/sysv/linux/powerpc/pthread_once.c (__pthread_once):
+ Retry if the stwcx fails to store once_control.
+
+2003-07-20 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (libpthread-routines): Add pthread_attr_getaffinity and
+ pthread_attr_setaffinity.
+ * Versions [libpthread] (GLIBC_2.3.3): Likewise.
+ * sysdeps/unix/sysv/linux/pthread_attr_getaffinity.c: New file.
+ * sysdeps/unix/sysv/linux/pthread_attr_setaffinity.c: New file.
+ * pthread_attr_destroy.c: Free cpuset element if allocated.
+ * pthread_create.c: Pass iattr as additional parameter to
+ create_thread.
+ * sysdeps/pthread/createthread.c: If attribute is provided and
+ a new thread is created with affinity set or scheduling parameters,
+ start thread with CLONE_STOPPED.
+ * sysdeps/pthread/pthread.h: Declare pthread_attr_getaffinity and
+ pthread_attr_setaffinity.
+ * sysdeps/unix/sysv/linux/internaltypes.h (struct pthread_attr): Add
+ cpuset element.
+
+2003-07-15 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-tcancel-wrappers.sh: lseek and llseek are not cancelation points.
+
+2003-07-14 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/configure.in: Require CFI directives also for
+ ppc and s390.
+
+2003-07-15 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h (PSEUDO):
+ Add cfi directives.
+
+2003-07-12 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/sh/tcb-offsets.sym: Add RESULT, TID, CANCELHANDLING and
+ CLEANUP_JMP_BUF.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_wait.S: Use more
+ registers as variables. Call __pthread_mutex_unlock_usercnt.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_rdlock.S: Store TID
+ not self pointer in __writer. Compare with TID to determine
+ deadlocks.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_wrlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedrdlock.S:
+ Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedwrlock.S:
+ Likewise.
+ * sysdeps/unix/sysv/linux/sh/sem_wait.S: Add cancellation support.
+ * sysdeps/unix/sysv/linux/sh/sem_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/sysdep-cancel.h: Define all the nice
+ macros also when compiling librt.
+
+2003-07-11 Jakub Jelinek <jakub@redhat.com>
+
+ * Makefile (CFLAGS-pthread_once.c): Add -fexceptions
+ -fasynchronous-unwind-tables.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h
+ (PSEUDO): Add cfi directives.
+ * sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h (PSEUDO):
+ Likewise.
+ * sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h (PSEUDO):
+ Likewise.
+
+2003-07-08 Jakub Jelinek <jakub@redhat.com>
+
+ * pthreadP.h (__pthread_unwind_next, __pthread_register_cancel,
+ __pthread_unregister_cancel): Add prototypes and hidden_proto.
+ * unwind.c (__pthread_unwind_next): Add hidden_def.
+ * cleanup.c (__pthread_register_cancel, __pthread_unregister_cancel):
+ Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/sem_wait.S (__new_sem_wait):
+ Use HIDDEN_JUMPTARGET to jump to __pthread_unwind.
+ * sysdeps/unix/sysv/linux/i386/i486/sem_timedwait.S (sem_timedwait):
+ Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/sem_wait.S (sem_wait): Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S (sem_timedwait):
+ Likewise.
+ * sysdeps/unix/sysv/linux/i386/pthread_once.S (__pthread_once): Use
+ HIDDEN_JUMPTARGET to call __pthread_register_cancel,
+ __pthread_unregister_cancel and __pthread_unwind_next.
+
+2003-07-04 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h (PSEUDO): Use
+ different symbol for the cancellation syscall wrapper and
+ non-cancellation syscall wrapper.
+ (PSEUDO_END): Define.
+
+2003-07-05 Richard Henderson <rth@redhat.com>
+
+ * sysdeps/alpha/elf/pt-initfini.c: Avoid .ent/.end.
+ * sysdeps/unix/sysv/linux/alpha/lowlevellock.h (lll_futex_wait,
+ lll_futex_timed_wait, lll_futex_wake, lll_futex_requeue): On success
+ return actual return value from the syscall, not 0.
+
+2003-07-07 Ulrich Drepper <drepper@redhat.com>
+
+ * descr.h (struct pthread): Add pid field.
+ * allocatestack.c (allocate_stack): Initialize pid field in descriptor.
+ (__reclaim_stacks): Likewise.
+ * init.c (sigcancel_handler): If __ASSUME_CORRECT_SI_PID is defined
+ also check for PID of the signal source.
+ (__pthread_initialize_minimal_internal): Also initialize pid field
+ of initial thread's descriptor.
+ * pthread_cancel.c: Use tgkill instead of tkill if possible.
+ * sysdeps/unix/sysv/linux/fork.c: Likewise.
+ * sysdeps/unix/sysv/linux/pt-raise.c: Likewise.
+ * sysdeps/unix/sysv/linux/pthread_kill.c: Likewise.
+ * sysdeps/unix/sysv/linux/raise.c: Likewise.
+
+2003-07-05 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/bits/libc-lock.h (__libc_cleanup_push): Renamed.
+ Fix use of parameter.
+ (__libc_cleanup_pop): Likewise.
+
+2003-07-04 Ulrich Drepper <drepper@redhat.com>
+
+ * init.c (sigcancel_handler): Change parameters to match handler
+ for SA_SIGACTION. Check signal number and code to recognize
+ invalid invocations.
+
+2003-07-03 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/ia64/td_ta_map_lwp2thr.c (td_ta_map_lwp2thr):
+ Apply sizeof (struct pthread) bias to r13 value.
+
+2003-07-03 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/configure.in: Require CFI directives.
+
+ * sysdeps/pthread/librt-cancellation.c (__pthread_unwind): Remove
+ definition.
+ * pthreadP.h (__pthread_unwind): Add hidden_proto if used in
+ libpthread compilation.
+ * unwind.c (__pthread_unwind): Add hidden_def.
+ * Versions (libpthread) [GLIBC_PRIVATE]: Add __pthread_unwind.
+
+2003-07-01 Ulrich Drepper <drepper@redhat.com>
+
+ * libc-cancellation.c (__libc_cleanup_routine): Define.
+ * sysdeps/pthread/bits/libc-lock.h (__pthread_cleanup_push): Define.
+ (__pthread_cleanup_pop): Define.
+
+2003-07-01 Richard Henderson <rth@redhat.com>
+
+ * sysdeps/alpha/elf/pt-initfini.c: New file.
+ * sysdeps/alpha/pthread_spin_lock.S: New file.
+ * sysdeps/alpha/pthread_spin_trylock.S: New file.
+ * sysdeps/alpha/pthreaddef.h: New file.
+ * sysdeps/alpha/td_ta_map_lwp2thr.c: New file.
+ * sysdeps/alpha/tls.h: New file.
+ * sysdeps/unix/sysv/linux/alpha/Makefile: New file.
+ * sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h: New file.
+ * sysdeps/unix/sysv/linux/alpha/bits/semaphore.h: New file.
+ * sysdeps/unix/sysv/linux/alpha/createthread.c: New file.
+ * sysdeps/unix/sysv/linux/alpha/fork.c: New file.
+ * sysdeps/unix/sysv/linux/alpha/lowlevellock.h: New file.
+ * sysdeps/unix/sysv/linux/alpha/pt-vfork.S: New file.
+ * sysdeps/unix/sysv/linux/alpha/pthread_once.c: New file.
+ * sysdeps/unix/sysv/linux/alpha/sem_post.c: New file.
+ * sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h: New file.
+
+2003-07-01 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/pthread_once.S: Add correct
+ cleanup support and unwind info.
+
+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.
+ * sysdeps/unix/sysv/linux/unwindbuf.sym: New file.
+ * sysdeps/unix/sysv/linux/Makefile: Add rule to build unwindbuf.h.
+ * 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.
+
+2003-06-27 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-cancel4.c (tf_msgrcv): Use IPC_PRIVATE in msgget call.
+ (tf_msgsnd): Likewise.
+
+ * tst-cancel4.c (tf_msgrcv): Strengthen test against valid
+ premature returns a bit more.
+
+2003-06-26 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/librt-cancellation.c: Move __pthread_unwind
+ definition to the front.
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Rename
+ the cleanup functions to make the names unique. Fix dwarf opcode
+ un unwind table.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S: Rename cleanup
+ functions to make the names unique. Fix CFA offset for two blocks.
+
+2003-06-25 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/pthread.h (class __pthread_cleanup_class): Add
+ missing closing braces.
+ Patch by Christophe Saout <christophe@saout.de>.
+
+2003-06-24 Roland McGrath <roland@redhat.com>
+
+ * pthread_mutex_trylock.c (__pthread_mutex_trylock): Typo fix.
+
+2003-06-24 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/ia64/bits/posix_opt.h: New file.
+ * sysdeps/unix/sysv/linux/x86_64/bits/posix_opt.h: New file.
+
+ * pthreadP.h: Declare __find_thread_by_id.
+ * allocatestack.c [HP_TIMING_AVAIL]: Define __find_thread_by_id.
+ * pthread_clock_gettime.c: Allow using other thread's clock.
+ * pthread_clock_settime.c: Likewise.
+ * sysdeps/pthread/pthread_getcpuclockid.c: Likewise.
+ * Makefile: Add rules to build and run tst-clock2.
+ * tst-clock2.c: New file.
+
+2003-06-23 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Rewrite
+ to use exception-based cleanup handler.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S: Likewise.
+
+ * tst-cond8.c (ch): Announce that we are done.
+
+ * pthreadP.h (__pthread_mutex_cond_lock): Mark with internal_function.
+
+ * tst-cancel17.c (tf): Retry aio_suspend in case of EINTR.
+ Also test aio_suspend with timeout value.
+
+2003-06-22 Ulrich Drepper <drepper@redhat.com>
+
+ * pthreadP.h: Mark __pthread_mutex_unlock_usercnt also hidden.
+ * pthread_mutex_unlock.c (__pthread_mutex_unlock_usercnt): Add
+ attribute_hidden.
+
+ * pthreadP.h (__pthread_mutex_init_internal): Mark hidden.
+ (__pthread_mutex_lock_internal): Likewise.
+ (__pthread_mutex_unlock_internal): Likewise.
+ (__pthread_mutex_unlock_usercnt): Declare.
+ * pthread_mutex_destroy.c: Always fail if used in any way.
+ * pthread_mutex_init.c: Update comment.
+ * pthread_mutex_lock.c: If NO_INCR is not defined adjust __nusers.
+ * pthread_mutex_timedlock.c: Adjust __nusers.
+ * pthread_mutex_trylock.c: Adjust __nusers.
+ * pthread_mutex_unlock.c: Old code is in __pthread_mutex_unlock_usercnt
+ and public interfaces are wrapper with pass additional parameter.
+ __pthread_mutex_unlock_usercnt does not adjust __nusers if second
+ parameter zero.
+ * tst-mutex8.c: New file.
+ * Makefile (tests): Add tst-mutex8.
+ * sysdeps/pthread/pthread_cond_timedwait.c: Call
+ __pthread_mutex_unlock_usercnt.
+ * sysdeps/pthread/pthread_cond_wait.c: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S: Likewise.
+ * sysdeps/unix/sysv/linux/pthread_mutex_cond_lock.c: Define NO_INCR.
+ * sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h (pthread_mutex_t):
+ Add __nusers.
+ * sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h: Likewise.
+
+ * pthread_mutex_lock.c: Don't store THREAD_ID in __owner, use TID.
+ * pthread_mutex_timedlock.c: Likewise.
+ * pthread_mutex_trylock.c: Adjust __nusers.
+ * pthread_mutex_unlock.c: Compare with TID not THREAD_ID.
+ * tst-mutex9.c: New file.
+ * Makefile (tests): Add tst-mutex9.
+ * sysdeps/i386/tls.h: Remove THREAD_ID definition.
+ * sysdeps/ia64/tls.h: Likewise.
+ * sysdeps/powerpc/tls.h: Likewise.
+ * sysdeps/s390/tls.h: Likewise.
+ * sysdeps/sh/tls.h: Likewise.
+ * sysdeps/x86_64/tls.h: Likewise.
+ * sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h (pthread_mutex_t):
+ Change type of __owner.
+ * sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h: Likewise.
+
+2003-06-19 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/ia64/sem_post.c: Move to...
+ * sysdeps/unix/sysv/linux/sem_post.c: ...here.
+
+ * sysdeps/unix/sysv/linux/sem_post.c: Move to...
+ * sysdeps/unix/sysv/linux/powerpc/sem_post.c: ... here. Pass nr + 1
+ instead of nr to lll_futex_wake. Only set errno and return -1
+ if err < 0.
+
+ * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h (lll_futex_wait,
+ lll_futex_timed_wait, lll_futex_wake, lll_futex_requeue): On success
+ return actual return value from the syscall, not 0.
+
+2003-06-18 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-cancel4.c (tf_msgsnd): Don't always use 100 as the type,
+ find a random value.
+ (tf_msgrcv): Likewise. Also don't report msgrcv returns if
+ errno==EIDRM.
+
+ * sysdeps/unix/sysv/linux/timer_settime.c: Add prototype for
+ compat_timer_settime.
+ * sysdeps/unix/sysv/linux/timer_gettime.c: Add prototype for
+ compat_timer_gettime.
+ * sysdeps/unix/sysv/linux/timer_getoverr.c: Add prototype for
+ compat_timer_getoverrun.
+ * sysdeps/unix/sysv/linux/timer_delete.c: Add prototype for
+ compat_timer_delete.
+
+ * pthread_mutex_destroy.c (__pthread_mutex_destroy): For
+ error-checking mutex detect busy mutexes.
+
+2003-06-17 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h (lll_mutex_lock):
+ Add ax to clobber list.
+ (lll_mutex_cond_lock): Likewise.
+ (lll_mutex_unlock): Likewise.
+ (lll_lock): Likewise.
+ (lll_unlock): Likewise.
+
+ * Makefile: Add rules to build and run tst-cancel18 and tst-cancelx18.
+ * tst-cancel18.c: New file.
+ * tst-cancelx18.c: New file.
+
+ * tst-cancel4.c: Test connect, creat, msgrcv, msgsnd, sendmsg, sendto,
+ and tcdrain.
+
+ * Makefile: Add rules to build and run tst-cancel17 and tst-cancel17x.
+ * tst-cancel17.c: New file.
+ * tst-cancelx17.c: New file.
+
+ * sysdeps/unix/sysv/linux/sigtimedwait.c: New file.
+ * sysdeps/unix/sysv/linux/sigwait.c: New file.
+ * sysdeps/unix/sysv/linux/sigwaitinfo.c: New file.
+
+ * tst-cancel4.c: Test open, close, pread, pwrite, fsync, and msync.
+
+2003-06-16 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/pthread/createthread.c (create_thread): Set
+ header.multiple_threads unconditionally.
+ * allocatestack.c (allocate_stack): Likewise.
+ * descr.h (struct pthread): Add header.multiple_threads
+ unconditionally.
+ * sysdeps/unix/sysv/linux/i386/sysdep-cancel.h (CENABLE, CDISABLE):
+ Define for librt. #error if neither libpthread, libc nor librt.
+ * sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h (CENABLE, CDISABLE):
+ Likewise.
+ * sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h (CENABLE,
+ CDISABLE): Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h (CENABLE,
+ CDISABLE): Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h (CENABLE,
+ CDISABLE): Likewise.
+ * sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h (CENABLE,
+ CDISABLE): Likewise. Access header.multiple_threads outside of
+ libc and libpthread.
+ * sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h (CENABLE, CDISABLE):
+ Likewise.
+ * sysdeps/x86_64/tls.h (tcbhead_t): Add multiple_threads.
+ * sysdeps/x86_64/tcb-offsets.sym (MULTIPLE_THREADS_OFFSET): Define.
+
+2003-06-17 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-cancel4.c: Add tests for the socket and signal functions, pause.
+ Also test early cancellation before the thread reaches the cancellation
+ point.
+
+ * Makefile: Compile forward.c with exceptions.
+
+ * sysdeps/unix/sysv/linux/sleep.c: New file.
+
+2003-06-16 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile: Add CFLAGS definition to compile function wrappers
+ duplicated from libc with exceptions.
+ * tst-cancel4.c: Also check cancellation handlers.
+
+ * Makefile: Add rules to build and run tst-cancel16 and
+ tst-cancelx16. Add missing CFLAGS definitions.
+ * tst-cancel16.c: New file.
+ * tst-cancelx16.c: New file.
+
+2003-06-15 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/dl-sysdep.h
+ (DL_SYSINFO_IMPLEMENTATION): Use CFI opcodes.
+ * sysdeps/unix/sysv/linux/i386/i686/dl-sysdep.h
+ (DL_SYSINFO_IMPLEMENTATION): Likewise.
+
+ * pthreadP.h (LIBC_CANCEL_ASYNC): Also define for librt.
+ (LIBC_CANCEL_RESET): Likewise.
+ Declare __librt_enable_asynccancel and __librt_disable_asynccancel.
+ * sysdeps/pthread/Makefile (librt-sysdep_routines): Add
+ librt-cancellation.
+ (CFLAGS-libcrt-cancellation.c): Define.
+ * sysdeps/pthread/librt-cancellation.c: New file.
+ * sysdeps/unix/sysv/linux/i386/sysdep-cancel.h: Define all the nice
+ macros also when compiling librt.
+ * sysdeps/unix/sysv/linux/ia64/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/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/sh/sysdep-cancel.h: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h: Likewise.
+
+ * sysdeps/unix/sysv/linux/timer_create.c: Add prototype for
+ compat_timer_create.
+
+2003-06-14 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/posix-timer.h (timespec_compare): Always inline.
+
+ * sysdeps/unix/sysv/linux/fork.h: Add libc_hidden_proto for
+ __register_atfork.
+ * sysdeps/unix/sysv/linux/register-atfork.c (__register_atfork):
+ Add libc_hidden_def.
+
+2003-06-13 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/x86_64/td_ta_map_lwp2thr.c (td_ta_map_lwp2thr): Pass FS
+ constant from <sys/reg.h> to ps_get_thread_area, not register contents.
+
+2003-06-11 Ulrich Drepper <drepper@redhat.com>
+
+ * allocatestack.c (queue_stack): Always inline.
+ * ptreadhP.h (__do_cancel): Likewise.
+
+2003-06-10 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/s390/sem_timedwait.c (sem_timedwait): Fix
+ a typo.
+
+2003-06-10 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_signal.S
+ (__pthread_cond_signal): Remove incorrect second addition for
+ cond_lock!=0.
+
+2003-06-09 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_signal.S
+ (__pthread_cond_signal): Use correct futex pointer in
+ __lll_mutex_lock_wait call.
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_signal.S
+ (__pthread_cond_signal): Some more tweaks to handle cond_lock!=0.
+
+2003-06-08 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/s390/sem_wait.c (__new_sem_wait): Make
+ cancelable.
+ * sysdeps/unix/sysv/linux/s390/sem_timedwait.c (sem_timedwait):
+ Likewise.
+
+ * sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h: Remove
+ hand-written CFI generation code. Since ENTRY/END also initiated
+ CFI frames this caused two CFI sets to be generated.
+
+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.
+
+2003-06-05 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h (pthread_rwlock_t):
+ Change type of __writer element to int.
+ * sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h: Likewise.
+ * sysdeps/i386/tcb-offsets.sym: Replace SELF entry with TID entry.
+ * sysdeps/x86_64/tcb-offsets.sym: Likewise.
+ * pthread_rwlock_trywrlock.c: Store TID not self pointer in __writer.
+ Compare with TID to determine deadlocks.
+ * sysdeps/pthread/pthread_rwlock_rdlock.c: Likewise.
+ * sysdeps/pthread/pthread_rwlock_timedrdlock.c: Likewise.
+ * sysdeps/pthread/pthread_rwlock_timedwrlock.: Likewise.
+ * sysdeps/pthread/pthread_rwlock_wrlock.c: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_rdlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S:
+ Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S:
+ Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_wrlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S:
+ Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S:
+ Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S: Likewise.
+ * Makefile (tests): Add tst-rwlock12.
+ * tst-rwlock12.c: New file.
+
+2003-06-05 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/lowlevellock.c (__lll_lock_wait,
+ __lll_timedlock_wait, lll_unlock_wake_cb, __lll_timedwait_tid):
+ Remove bogus hidden_proto.
+ * sysdeps/unix/sysv/linux/s390/libc-lowlevellock.c (___lll_lock):
+ Likewise.
+ * sysdeps/unix/sysv/linux/s390/lowlevellock.c (___lll_lock,
+ lll_unlock_wake_cb, ___lll_timedwait_tid): Likewise.
+ * sysdeps/unix/sysv/linux/s390/lowlevelmutex.c (___lll_mutex_lock,
+ ___lll_mutex_timedlock): Likewise.
+
+2003-06-04 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_signal.S
+ (__pthread_cond_signal): Add some code to eventually handle
+ cond_lock!=0.
+
+2003-06-01 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-exec4.
+ (tst-exec4-ARGS): Define.
+ * tst-exec4.c: New file.
+
+2003-05-31 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/lowlevellock.c (__lll_timedlock_wait):
+ Also fail if tv_nsec < 0.
+ (__lll_timedwait_tid): Likewise.
+ * sysdeps/unix/sysv/linux/sem_timedwait.c (sem_timedwait): Likewise.
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h (lll_timedwait_tid):
+ Likewise.
+ * sysdeps/unix/sysv/linux/s390/lowlevellock.c (___lll_timedwait_tid):
+ Likewise.
+ * sysdeps/unix/sysv/linux/s390/lowlevelmutex.c (__lll_mutex_timedlock):
+ Likewise.
+ * sysdeps/unix/sysv/linux/s390/sem_timedwait.c (sem_timedwait):
+ Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h (lll_timedwait_tid):
+ Likewise.
+ * sysdeps/unix/sysv/linux/sh/lowlevellock.h (lll_timedwait_tid):
+ Likewise.
+
+ * Makefile (tests): Add tst-sem8 and tst-sem9.
+ * tst-sem8.c: New file.
+ * tst-sem9.c: New file.
+ * sem_open.c: Fix creation of in_use record if the file exists but
+ no internal record.
+
+ * posix-timer.h: Remove old, unused timer_id2ptr and timer_ptr2id
+ definitions.
+
+ * sysdeps/pthread/timer_create.c (timer_create): In case
+ evp==NULL, assign timer ID to sival_ptr.
+
+ * descr.h (struct pthread_unwind_buf): Change type of prev element to
+ struct pthread_unwind_buf *.
+ (struct pthread): Likewise for cleanup_jmp_buf element.
+
+ * cleanup.c (__pthread_register_cancel): Add cast to avoid warning.
+ * cleanup_defer.c (__pthread_register_cancel_defer): Likewise.
+ * unwind.c (__pthread_unwind_next): Likewise.
+
+2003-05-30 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.h
+ (lll_futex_timed_wait): Use int for futex value parameter.
+ (lll_futex_wake): Likewise.
+ (lll_futex_requeue): Likewise.
+
+ * sysdeps/unix/sysv/linux/lowlevellock.c (__lll_lock_wait):
+ Replace one memory operation with one register operation.
+
+ * tst-join4.c (do_test): Fix error message.
+
+ * tst-rwlock6.c (do_test): Use correct format specifier.
+
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelmutex.S
+ (__lll_mutex_lock_wait): Replace one memory operation with one
+ register operation.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevelmutex.S
+ (__lll_mutex_lock_wait): Likewise.
+
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.h
+ (__lll_mutex_cond_lock): Add one to value parameter of
+ __lll_lock_wait to reflect reality in the futex syscall.
+ * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h
+ (lll_mutex_cond_lock): Likewise.
+
+2003-05-30 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/s390/lowlevellock.h (__lll_mutex_cond_lock):
+ New function.
+ (lll_mutex_cond_lock): Define.
+
+2003-05-29 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-signal6.
+ * tst-signal6.c: New file.
+
+ * sysdeps/unix/sysv/linux/s390/lowlevellock.h
+ (__lll_mutex_unlock_force): New function
+ (lll_mutex_unlock_force): Use __lll_mutex_unlock_force.
+
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.h
+ (__lll_mutex_unlock_force): New function.
+ (lll_mutex_unlock_force): Use __lll_mutex_unlock_force.
+
+ * tst-rwlock7.c (do_test): Use correct format specifier.
+
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.h (lll_futex_requeue):
+ Find break parameter in correct asm argument.
+
+2003-05-27 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.h (lll_futex_clobbers):
+ Remove out4.
+ (lll_futex_requeue): Fix __o3 constraint, return negative errno if
+ error occured.
+ * sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h (pthread_cond_t):
+ Add __mutex.
+ * sysdeps/unix/sysv/linux/s390/lowlevellock.h (FUTEX_REQUEUE,
+ lll_futex_requeue, lll_mutex_unlock_force): Define.
+
+2003-05-30 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h
+ (pthread_cond_t): Add __mutex.
+ * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h (FUTEX_REQUEUE,
+ lll_futex_requeue, lll_mutex_unlock_force): Define.
+
+2003-05-28 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/sh/tcb-offsets.sym: Define MUTEX_FUTEX.
+ * sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h (pthread_cond_t):
+ Add __mutex field.
+ * sysdeps/unix/sysv/linux/sh/lowlevellock.h (SYSCALL_WITH_INST_PAD):
+ Define.
+ (lll_futex_wait, lll_futex_wake): Define.
+ * sysdeps/unix/sysv/linux/sh/sh4/lowlevellock.h: New file.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_broadcast.S: Try using
+ FUTEX_REQUEUE instead of FUTEX_WAIT.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_signal.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_timedwait.S: Remember
+ mutex which was used in condvar structure. Call
+ __pthread_mutex_cond_lock instead of __pthread_mutex_lock_internal.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_wait.S: Likewise.
+
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_rdlock.S: Don't
+ include tcb-offsets.h. Read wakeup value in locked region.
+ Use the value of gbr register as THREAD_ID.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_wrlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedrdlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedwrlock.S: Likewise.
+
+ * sysdeps/unix/sysv/linux/sh/sem_trywait.S: Remove futex related
+ macros.
+
+2003-05-28 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/pthread_cond_broadcast.c
+ (__pthread_cond_broadcast): Fix typo: MAX_INT -> INT_MAX.
+
+2003-05-26 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S: Fix
+ typo in register name.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S: Use parameters
+ correctly. Actually use requeue. Little optimization.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: Store
+ mutex address early. Handle cancellation state as 32-bit value.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S: Likewise.
+ Remove unnecessary label.
+
+2003-05-25 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/pthread_cond_broadcast.c: Try using FUTEX_REQUEUE
+ instead of FUTEX_WAIT.
+ * sysdeps/pthread/pthread_cond_signal.c: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_broadcast.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_signal.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S: Likewise.
+ * sysdeps/pthread/pthread_cond_timedwait.c: Remember mutex which was
+ used in condvar structure. Call __pthread_mutex_cond_lock instead
+ of __pthread_mutex_lock_internal.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: Likewise.
+ * sysdeps/pthread/pthread_cond_wait.c: Likewise.
+ (__condvar_cleanup): Always call __pthread_mutex_cond_lock.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S: Likewise.
+ * sysdeps/unix/sysv/linux/Makefile (libpthread-sysdep_routines):
+ Add pthread_mutex_cond_lock.
+ * sysdeps/unix/sysv/linux/lowlevelcond.sym: Add dep_mutex.
+ * sysdeps/unix/sysv/linux/pthread_cond_mutex_lock.c: New file.
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h: Define
+ lll_mutex_cond_lock.
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.h: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h: Likewise.
+ * sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h (pthread_cond_t):
+ Add __mutex field.
+ * sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h: Likewise.
+
+ * sysdeps/i386/tcb-offsets.sym: Define MUTEX_FUTEX.
+ * sysdeps/x86_64/tcb-offsets.sym: Likewise.
+
+ * pthreadP.h: Declare __pthread_mutex_cond_lock.
+ * pthread_mutex_lock.c: Define LLL_MUTEX_LOCK if not already defined.
+ Use it instead of lll_mutex_lock. If __pthread_mutex_lock is a
+ macro don't define aliases.
+
+ * cancellation.c: Remove __pthread_enable_asynccancel_2.
+ * pthreadP.h: Remove declaration of __pthread_enable_asynccancel_2.
+ * sysdeps/pthread/pthread_cond_timedwait.c: Use
+ __pthread_enable_asynccancel instead of __pthread_enable_asynccancel_2.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: Likewise.
+ * sysdeps/pthread/pthread_cond_wait.c: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S: Likewise.
+
+2003-05-17 Ulrich Drepper <drepper@redhat.com>
+
+ * sem_open.c: Fix one endless loop. Implement correct semantics
+ wrt opening the same semaphore more then once.
+ * sem_close.c: Adjust for sem_open change.
+ * semaphoreP.h: Include <semaphore.h>. Define struct inuse_sem.
+ Declare __sem_mappings, __sem_mappings_lock, __sem_search.
+ * Makefile (tests): Add tst-sem7.
+ * tst-sem7.c: New file.
+
+2003-05-16 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/unix/sysv/linux/register-atfork.c (libc_freeres_fn): Fix
+ uninitialized variable braino.
+
+2003-05-16 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/timer_gettime.c (timer_gettime): Correct
+ test for syscall availability.
+
+ * sysdeps/unix/sysv/linux/timer_settime.c (timer_settime): Set
+ __no_posix_timers to -1 if the syscalls don't exist.
+
+ * pthread_join.c (pthread_join): Set tid field of the joined
+ thread to -1. This isn't necessary but helps to recognize some
+ error conditions with almost no cost.
+
+ * allocatestack.c (FREE_P): Also negative values indicate an
+ unused stack.
+
+ * unwind.c: Include <unistd.h>.
+
+2003-05-14 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile ($(objpfx)$(multidir)): Add rule to create the directory.
+
+2003-05-14 Jakub Jelinek <jakub@redhat.com>
+
+ * Makefile (crti-objs, crtn-objs): New variables.
+ (omit-deps, extra-objs): Add crtn.
+ ($(objpfx)libpthread.so): Depend on both crti and crtn
+ and links to them in multidir.
+ ($(objpfx)crtn.S, $(objpfx)crtn.o): New rules.
+
+2003-05-12 Steven Munroe <sjmunroe@us.ibm.com>
+
+ * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h
+ (lll_mutex_unlock): Use atomic_exchange_rel.
+
+2003-05-11 Ulrich Drepper <drepper@redhat.com>
+
+ * cond-perf.c (cons): Add missing locking around setting of alldone.
+
+2003-05-10 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/sem_trywait.S: Remove futex
+ related macros.
+ * sysdeps/unix/sysv/linux/x86_64/sem_trywait.S: Likewise.
+
+2003-05-09 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-sem6.c: New file.
+ * Makefile (tests): Add tst-sem6.
+
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.h (___lll_mutex_unlock):
+ Use atomic_exchange_rel instead of atomic_exchange.
+ * sysdeps/unix/sysv/linux/lowlevellock.c (lll_unlock_wake_cb):
+ Likewise.
+
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h: Improve quality of
+ code for lll_futex_wait and lll_futex_wake in static apps. Use
+ vsyscall is possible.
+
+ * sysdeps/unix/sysv/linux/pthread_getaffinity.c: New file.
+ * sysdeps/unix/sysv/linux/pthread_setaffinity.c: New file.
+ * sysdeps/pthread/pthread.h: Declare pthread_getaffinity_np and
+ pthread_setaffinity_np.
+ * Versions [libpthread] (GLIBC_2.3.3): Add pthread_getaffinity_np
+ and pthread_setaffinity_np.
+ * Makefile (libpthread-routines): Add pthread_getaffinity and
+ pthread_setaffinity.
+
+ * allocatestack.c (allocate_stack): If ARCH_RETRY_MMAP is defined,
+ use it in case mmap to allocate the stack fails.
+ * sysdeps/unix/sysv/linux/x86_64/Makefile: Don't define
+ ARCH_MAP_FLAGS here.
+ * sysdeps/x86_64/pthreaddef.h: Define ARCH_MAP_FLAGS and
+ ARCH_RETRY_MMAP.
+
+2003-05-08 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/fork.c: Complete rewrite of the atfork
+ handler implementation. It is now lockless in fork().
+ * sysdeps/unix/sysv/linux/register-atfork.c: Likewise.
+ * sysdeps/unix/sysv/linux/unregister-atfork.c: Likewise.
+ * sysdeps/unix/sysv/linux/fork.h: Don't include <link.h>. Don't
+ declare the __fork_*_lists.
+ (struct fork_handler): Include pointers to all three functions.
+ Add next, refcntr and need_signal elements.
+ (__fork_handlers): New declaration.
+ (__register_atfork_malloc): Remove declaration.
+ (HAVE_register_atfork_malloc): Remove definition.
+ * sysdeps/unix/sysv/linux/libc_pthread_init.c: Remove
+ __pthread_child_handler variable.
+ (__libc_pthread_init): Use __register_atfork instead of explicitly
+ adding to the list.
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h: Define lll_futex_wait
+ and lll_futex_wake.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h: Likewise.
+
+ * unwind.c (unwind_cleanup): Print error message and then abort. This
+ function must never be reached.
+
+ * cond-perf.c: New file.
+
+2003-05-05 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/i386/tls.h (TLS_INIT_TP): Include \n in error message.
+
+2003-05-04 Roland McGrath <roland@redhat.com>
+
+ * Makefile ($(objpfx)../libc.so): New target.
+
+2003-05-02 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h
+ (pthread_condattr_t): Size is only an int, don't use long for
+ alignment.
+ (pthread_mutexattr_t): Likewise.
+ * sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h: Likewise.
+
+2003-05-01 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/i386/tls.h: Define THREAD_ID.
+ * sysdeps/ia64/tls.h: Likewise.
+ * sysdeps/powerpc/tls.h: Likewise.
+ * sysdeps/s390/tls.h: Likewise.
+ * sysdeps/sh/tls.h: Likewise.
+ * sysdeps/x86_64/tls.h: Likewise.
+ * pthread_mutex_lock.c: Use THREAD_ID instead of THREAD_SELF to
+ record ownership.
+ * pthread_mutex_timedlock.c: Likewise.
+ * pthread_mutex_trylock.c: Likewise.
+ * pthread_mutex_unlock.c: Likewise.
+ * pthread_rwlock_trywrlock.c: Likewise.
+ * sysdeps/pthread/pthread_rwlocklock_rdlock.c: Likewise.
+ * sysdeps/pthread/pthread_rwlock_timedrdlock.c: Likewise.
+ * sysdeps/pthread/pthread_rwlock_timedwrlock.c: Likewise.
+ * sysdeps/pthread/pthread_rwlock_wrlock.c: Likewise.
+
+ * sysdeps/pthread/createthread.c (create_thread): Use CLONE_SYSVSEM
+ flag.
+
+2003-04-29 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h
+ (__SIZEOF_PTHREAD_COND_T): Define to 48.
+ (pthread_rwlock_t): Add 16 bytes of pad instead of 8 before __flags.
+ * sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h (pthread_cond_t):
+ Make __align long long instead of long.
+ (pthread_rwlock_t): Formatting.
+ * sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h
+ (pthread_rwlock_t): Formatting.
+ * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h
+ (pthread_cond_t): Make __align long long instead of long.
+ (pthread_rwlock_t): Move __flags field to the same position as in
+ linuxthreads.
+
+2003-04-30 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-rwlock6.c (do_test): Use correct printf format specifiers.
+ * tst-rwlock7.c (do_test): Likewise.
+
+2003-04-26 Roland McGrath <roland@redhat.com>
+
+ * Makefile ($(test-modules)): Depend on $(common-objpfx)shlib.lds.
+
+2003-04-22 Jakub Jelinek <jakub@redhat.com>
+
+ * allocatestack.c (TLS_TPADJ): Add TLS_PRE_TCB_SIZE instead of
+ sizeof (struct pthread).
+ (allocate_stack): Subtract TLS_PRE_TCB_SIZE bytes instead of
+ 1 struct pthread.
+ * sysdeps/powerpc/tls.h (TLS_INIT_TCB_SIZE, TLS_TCB_SIZE): Define
+ to 0.
+ (TLS_INIT_TCB_ALIGN, TLS_TCB_ALIGN): Define to alignment of
+ struct pthread.
+ (TLS_PRE_TCB_SIZE): Increase to cover tcbhead_t preceeded by pad
+ to 32-bit bytes.
+ (INSTALL_DTV, GET_DTV, THREAD_DTV): tcbhead_t is immediately before
+ tcbp.
+ (TLS_INIT_TP, THREAD_SELF, INIT_THREAD_SELF): Don't add TLS_TCB_SIZE
+ unneccessarily.
+ (NO_TLS_OFFSET): Define.
+ * sysdeps/unix/sysv/linux/powerpc/createthread.c (TLS_VALUE): Don't
+ add TLS_TCB_SIZE unnecessarily.
+
+2003-04-22 Roland McGrath <roland@redhat.com>
+
+ * Makeconfig (shared-thread-library): Reverse link order to work
+ around linker bug.
+
+2003-04-22 Ulrich Drepper <drepper@redhat.com>
+
+ * semaphore.h: Fix typo in comment.
+
+2003-04-21 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/sigfillset.c: New file.
+
+ * init.c (__pthread_initialize_minimal): Don't block SIGTIMER.
+ * pthreadP.h: Make SIGTIMER and SIGCANCEL the same.
+ * sysdeps/pthread/pthread_sigmask.c: Remove handling of SIGTIMER.
+ * sysdeps/pthread/sigaction.c: Likewise.
+ * sysdeps/pthread/sigprocmask.c: New file.
+ * sysdeps/unix/sysv/linux/allocrtsig.c (current_rtmin): Define as
+ __SIGRTMIN+1.
+ * sysdeps/unix/sysv/linux/timer_routines.c (timer_helper_thread):
+ Block SIGTIMER. Also handle SI_TKILL events and terminate thread
+ in this case.
+
+2003-04-19 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/dl-sysdep.h
+ (DL_SYSINFO_IMPLEMENTATION): Add .eh_frame information.
+
+ * sysdeps/unix/sysv/linux/unregister-atfork.c
+ (__unregister_atfork): Don't free memory not allocated dynamically.
+
+ * semaphore.h: Remove __THROW marker from cancellation points.
+ * nptl/sysdeps/pthread/pthread.h: Likewise.
+
+2003-04-18 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/pthread.h: Don't mark pthread_testcancel,
+ pthread_cancel, pthread_setcancelstate, and pthread_setcanceltype with
+ __THROW.
+
+2003-04-16 Jakub Jelinek <jakub@redhat.com>
+
+ * tst-cancel4.c (do_test): Use %zd instead of %d when printing cnt.
+
+2003-04-15 Roland McGrath <roland@redhat.com>
+
+ * forward.c (__pthread_unwind): Tweak to avoid warning.
+
+2003-04-15 Ulrich Drepper <drepper@redhat.com>
+
+ * pthreadP.h: Move THREAD_ATOMIC_* replacements to the top.
+
+2003-04-14 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S: Don't
+ overflow CFA advance instructions.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: Likewise.
+
+2003-04-14 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/i386/tls.h: Rename LOCK to LOCK_PREFIX.
+ * sysdeps/i386/pthread_spin_lock.c: Likewise.
+ * sysdeps/x86_64/tls.h: Likewise. Define LOCK_PREFIX if not already
+ defined.
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Use
+ DW_CFA_advance_loc2 for .Laddl-.Lsubl.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S: Use
+ DW_CFA_advance_loc for .Laddl-.Lsubl.
+
+2003-04-13 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/sysdep-cancel.h: Don't use
+ position-independent unwind data for static libraries.
+ Add missing unwind info. Add comments.
+
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S: Add unwind info.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Likewise.
+
+2003-04-12 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile: Make sure all cancellation points are compiled with
+ exception and asynchronous unwind tables.
+
+ * sysdeps/x86_64/tls.h (THREAD_SETMEM): Word around compiler bug
+ which mishandles loading of global object addresses in PIC.
+ (THREAD_SETMEM_NC): Likewise.
+
+2003-04-11 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread.h: Define new data structure for cleanup buffer. Declare
+ new cleanup handler interfaces.
+ * descr.h: Include <unwind.h> if necessary. Define pthread_unwind_buf.
+ (struct pthread): Add cleanup_jmp_buf pointer. Define
+ HAVE_CLEANUP_JMP_BUF and not HAVE_CANCELBUF.
+ * pthreadP.h: Declare __pthread_unwind. Define __do_cancel to use
+ it. Declare old cleanup handler installation functions.
+ * cleanup.c: Rewrite. Install handler for unwind-based cleanup
+ handling.
+ * cleanup_defer.c: Likewise.
+ * cleanup_compat.c: New file. Old cleanup code.
+ * cleanup_def_compat.c: New file. Old cleanup code.
+ * pthread_create.c (start_thread): Initialize cleanup_jmp_buf element
+ if own thread descriptor.
+ * unwind.c: New file.
+ * forward.c: Add __pthread_unwind.
+ * init.c (pthread_functions): Add __pthread_unwind.
+ * sysdeps/pthread/pthread-functions.s (struct pthread_functions):
+ Add ptr___pthread_unwind.
+ * Versions [GLIBC_2.3.3] (libpthread): Export new cleanup handling
+ and unwind function.
+ * Makefile (libpthread-routines): Add cleanup_compat,
+ cleanup_def_compat, and unwind. Define CFLAGS to enable unwind
+ table generation if necessary.
+ * version.c: Record whether unwind support is compiled in.
+ * sysdeps/pthread/configure.in: Add checks for unwind unterfaces.
+ * sysdeps/pthread/bits/libc-lock.h: Add prototypes of the old cleanup
+ handler interfaces.
+ * sysdeps/unix/sysv/linux/i386/sysdep-cancel.h: Add quite a bit of
+ complication to generate unwind information for syscall wrappers.
+ * sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h: Likewise.
+ * sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h: Define
+ __cleanup_fct_attribute.
+
+ * Makefile: Add rules to build and run tst-cleanup0.
+ * tst-cleanup0.c: New file.
+ * tst-cleanup0.expect: New file.
+
+ * pthread_create.c (deallocate_tsd): Don't take parameter. Adjust
+ caller. Optimize to avoid often unecessary local variable.
+
+2003-04-11 Roland McGrath <roland@redhat.com>
+
+ * Makefile ($(objpfx)multidir.mk): New target, generated makefile that
+ sets variable `multidir'; include that.
+ (generated): Add it.
+ ($(objpfx)$(multidir)/crti.o): New target.
+ [$(multidir) != .] (generated-dirs, extra-objs, omit-deps): Add it.
+
+2003-04-11 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-attr2.c (do_test): Add cast to avoid warning.
+ * tst-mutex4.c (do_test): Likewise.
+
+2003-04-10 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/fork.c (__libc_fork): Reset CPU clocks
+ in child.
+
+2003-04-09 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-detach1.
+ * tst-detach1.c: New file.
+
+2003-04-08 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/pthread.h: Remove duplicate
+ pthread_cleanup_{push,pop} definitions.
+
+ * tst-barrier2.c: Eliminate warnings.
+ * tst-cancel4.c: Likewise.
+ * tst-cond4.c: Likewise.
+ * tst-cond6.c: Likewise.
+ * tst-detach1.c: Likewise.
+ * tst-rwlock4.c: Likewise.
+ * tst-rwlock6.c: Likewise.
+ * tst-rwlock7.c: Likewise.
+ * tst-sem3.c: Likewise.
+ * tst-spin2.c: Likewise.
+ * tst-umask1.c: Likewise.
+
+2003-04-07 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread_detach.c (pthread_detach): Fix test for invalid TID.
+
+2003-04-06 Ulrich Drepper <drepper@redhat.com>
+
+ * descr.h (struct pthread): Move cancelhandling member to the front.
+
+2003-04-05 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/register-atfork.c: Define malloc_prepare,
+ malloc_parent, and malloc_child statically.
+ (__register_atfork_malloc): New function.
+ (free_mem): Don't free any of the malloc_* variables on the list.
+ * sysdeps/unix/sysv/linux/fork.h: Declare __register_atfork_malloc.
+ Define HAVE_register_atfork_malloc.
+
+2003-04-04 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/createthread.c (create_thread): Add some more
+ comments explaining when to set multiple_threads and when not.
+
+ * pthreadP.h: Define THREAD_ATOMIC_CMPXCHG_VAL and
+ THREAD_ATOMIC_BIT_SET if not already defined.
+ * sysdeps/i386/tls.h: Define THREAD_ATOMIC_CMPXCHG_VAL and
+ THREAD_ATOMIC_BIT_SET:
+ * sysdeps/x86_64/tls.h: Likewise.
+ * cleanup_defer.c (_pthread_cleanup_push_defer): Rewrite to use
+ THREAD_ATOMIC_CMPXCHG_VAL.
+ (_pthread_cleanup_pop_restore): Likewise.
+ * cancellation.c (__pthread_enable_asynccancel): Likewise.
+ (__pthread_enable_asynccancel_2): Likewise.
+ (__pthread_disable_asynccancel): Likewise.
+ * libc-cancellation.c (__libc_enable_asynccancel): Likewise.
+ (__libc_disable_asynccancel): Likewise.
+ * init.c (sigcancel_handler): Likewise.
+ * pthread_setcancelstate.c (__pthread_setcancelstate): Likewise.
+ * pthread_setcanceltype.c (__pthread_setcanceltype): Likewise.
+
+2003-04-03 Ulrich Drepper <drepper@redhat.com>
+
+ * init.c (sigcancel_handler): Don't set EXITING_BIT here.
+ * libc-cancellation.c (__libc_enable_asynccancel): Likewise.
+ * pthreadP.h (__do_cancel): Set EXITING_BIT here.
+ * Makefile (tests): Add tst-cancel11.
+ * tst-cancel11.c: New file.
+
+2003-04-01 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread_create.c (deallocate_tsd): Clear/free memory after the last
+ round, not the first. Use specific_used flag instead of local
+ found_nonzero variable. Use THREAD_[SG]ETMEM where possible.
+ (__free_tcb): Don't call deallocate_tsd here.
+ (start_thread): Call deallocate_tsd here.
+ * pthread_setspecific.c: Set specific_used flag really only when
+ needed.
+ * Makefile (tests): Add tst-tsd3.c and tst-tsd4.
+ * tst-tsd3.c: New file.
+ * tst-tsd4.c: New file.
+
+2003-03-31 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.h (__lll_mutex_lock):
+ Use atomic_exchange_and_add instead of __lll_add.
+ (__lll_mutex_timedlock): Likewise.
+ Patch by Ian Wienand.
+
+2003-03-24 Steven Munroe <sjmunroe@us.ibm.com>
+
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h
+ (SINGLE_THREAD_P): Fix typo.
+ * tst-cancel-wrappers.sh: Handle '.'ed symbols.
+
+2003-03-31 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-align.
+ * tst-align.c: New file.
+ * sysdeps/i386/Makefile: Define CFLAGS-tst-align.
+
+ * sysdeps/i386/tls.h (CALL_THREAD_FCT): Align stack of called
+ function correctly.
+
+ * tst-tsd2.c: Add casts to avoid warnings.
+
+2003-03-30 Ulrich Drepper <drepper@redhat.com>
+
+ * descr.h (struct pthread): Move most often used elements to the front.
+
+2003-03-29 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (libpthread-routines): Add pthread_atfork.
+ (libpthread-static-only-routines): Add pthread_atfork.
+
+2003-03-28 Kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/sh/tls.h: Include nptl/descr.h after the definition
+ of TLS_DTV_AT_TP.
+ (INSTALL_DTV): Add parens.
+ (THREAD_GETMEM, THREAD_GETMEM_NC, THREAD_SETMEM, THREAD_SETMEM_NC):
+ Use passed descr instead of THREAD_SELF.
+ * sysdeps/unix/sysv/linux/sh/lowlevelmutex.S
+ (__lll_mutex_timedlock_wait): Correct expected value after
+ spurious wakeup.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_broadcast.S:
+ Release lock before waking up the waiters.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_wait.S: Correct exit
+ criteria. Reorderstruct passed to cleanup handler. Fix
+ handling of cancellation and failung pthread_mutex_unlock call.
+ Use __pthread_enable_asynccancel_2 instead of
+ __pthread_enable_asynccancel.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_timedwait.S: Likewise.
+ Return result of lock re-get if it fails.
+ * sysdeps/unix/sysv/linux/sh/pthread_once.S: Fix wrong argument
+ for __pthread_cleanup_push.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_rdlock.S: Fix
+ completely broken rwlock implementation.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_wrlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedrdlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedwrlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_unlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_wrlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/sem_post.S: Fix error value. Use
+ versioned_symbol macro.
+ * sysdeps/unix/sysv/linux/sh/sem_trywait.S: Use versioned_symbol macro.
+ * sysdeps/unix/sysv/linux/sh/sem_wait.S: Likewise.
+
+2003-03-27 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/kernel-posix-timers.h: Don't declare
+ __timer_helper_thread. Declare __start_helper_thread, __helper_once,
+ and __helper_tid.
+ (struct timer): Remove th and bar field.
+ * sysdeps/unix/sysv/linux/timer_create.c (timer_create): Remove
+ debugging code. Create only one helper thread.
+ * sysdeps/unix/sysv/linux/timer_delete.c (timer_delete): Don't kill
+ helper thread.
+ * sysdeps/unix/sysv/linux/timer_routines.c (timer_helper_thread):
+ Renamed. Define statically. Use thread info from siginfo.
+ (__helper_once): New variable.
+ (__helper_tid): New variable.
+ (__reset_helper_control): New function.
+ (__start_helper_thread): New function.
+
+ * pthread_create.c (start_thread): Don't use setjmp inside
+ __builtin_expect to work around gcc bug.
+
+ * sysdeps/unix/sysv/linux/timer_delete.c (timer_delete): Even if
+ timer_delete syscall fails, but not with ENOSYS, set
+ __no_posix_timers.
+
+ * sysdeps/unix/sysv/linux/timer_settime.c [!__ASSUME_POSIX_TIMERS]
+ (timer_settime): Fix typo.
+ * sysdeps/unix/sysv/linux/timer_getoverr.c
+ [!__ASSUME_POSIX_TIMERS] (timer_getoverrun): Likewise.
+
+2003-03-27 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Fix
+ offset of cleanupbuf.__prev.
+
+2003-03-26 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/timer_getoverr.c: Fix typo in name
+ of included file.
+
+2003-03-26 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/timer_create.c (timer_create): If EVP ==
+ NULL provide default definition to syscall.
+
+2003-03-25 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/pthread/posix-timer.h (TIMER_MAX): Define if not defined.
+ (timer_id2ptr): Fix typo.
+
+2003-03-25 Ulrich Drepper <drepper@redhat.com>
+
+ * pthreadP.h: Define SIGCANCEL and SIGTIMER.
+ * sysdeps/i386/pthreaddef.h: Remove SIGCANCEL definition.
+ * sysdeps/ia64/pthreaddef.h: Likewise.
+ * sysdeps/powerpc/pthreaddef.h: Likewise.
+ * sysdeps/s390/pthreaddef.h: Likewise.
+ * sysdeps/sh/pthreaddef.h: Likewise.
+ * sysdeps/x86_64/pthreaddef.h: Likewise.
+ * init.c (__pthread_initialize_minimal): Block SIGTIMER.
+ * sysdeps/pthread/sigaction.c: Also prevent SIGTIMER handler from
+ being changed.
+ * sysdeps/pthread/pthread_sigmask.c (pthread_sigmask): Make sure
+ SIGTIMER is not unblocked.
+ * sysdeps/unix/sysv/linux/allocrtsig.c (current_rtmin): One more
+ RT signal taken.
+ * sysdeps/unix/sysv/linux/pthread_kill.c: Do not allow SIGTIMER to
+ be send.
+ * sysdeps/pthread/posix-timer.h (timer_id2ptr, timer_ptr2id): Just
+ pass pointer through as ID.
+ * sysdeps/unix/sysv/linux/bits/local_lim.h (TIMER_MAX): Removed.
+ * sysdeps/unix/sysv/linux/kernel-posix-timers.h: New file.
+ * sysdeps/unix/sysv/linux/timer_create.c: New file.
+ * sysdeps/unix/sysv/linux/timer_delete.c: New file.
+ * sysdeps/unix/sysv/linux/timer_getoverr.c: New file.
+ * sysdeps/unix/sysv/linux/timer_gettime.c: New file.
+ * sysdeps/unix/sysv/linux/timer_routines.c: New file.
+ * sysdeps/unix/sysv/linux/timer_settime.c: New file.
+ * sysdeps/unix/sysv/linux/ia64/Versions: New file.
+ * sysdeps/unix/sysv/linux/ia64/timer_create.c: New file.
+ * sysdeps/unix/sysv/linux/ia64/timer_delete.c: New file.
+ * sysdeps/unix/sysv/linux/ia64/timer_getoverr.c: New file.
+ * sysdeps/unix/sysv/linux/ia64/timer_gettime.c: New file.
+ * sysdeps/unix/sysv/linux/ia64/timer_settime.c: New file.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/Versions: New file.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_create.c: New file.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_delete.c: New file.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_getoverr.c: New file.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_gettime.c: New file.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_settime.c: New file.
+ * sysdeps/unix/sysv/linux/s390/s390-64/Versions: New file.
+ * sysdeps/unix/sysv/linux/s390/s390-64/timer_create.c: New file.
+ * sysdeps/unix/sysv/linux/s390/s390-64/timer_delete.c: New file.
+ * sysdeps/unix/sysv/linux/s390/s390-64/timer_getoverr.c: New file.
+ * sysdeps/unix/sysv/linux/s390/s390-64/timer_gettime.c: New file.
+ * sysdeps/unix/sysv/linux/s390/s390-64/timer_settime.c: New file.
+ * sysdeps/unix/sysv/linux/x86_64/Versions: New file.
+ * sysdeps/unix/sysv/linux/x86_64/compat-timer.h: New file.
+ * sysdeps/unix/sysv/linux/x86_64/timer_create.c: New file.
+ * sysdeps/unix/sysv/linux/x86_64/timer_delete.c: New file.
+ * sysdeps/unix/sysv/linux/x86_64/timer_getoverr.c: New file.
+ * sysdeps/unix/sysv/linux/x86_64/timer_gettime.c: New file.
+ * sysdeps/unix/sysv/linux/x86_64/timer_settime.c: New file.
+
+ * pthreadP.h: Remove FRAME_LEFT definition.
+ * cleanup.c (_pthread_cleanup_push): Don't check for reference to
+ already left frame. Programs which have this problem are not POSIX
+ compliant.
+ * cleanup_defer.c (_pthread_cleanup_push_defer): Likewise.
+
+2003-03-24 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/tst-timer.c: Check return values of the
+ functions we test.
+
+2003-03-23 Roland McGrath <roland@redhat.com>
+
+ * tst-tls3.c (do_test) [! HAVE___THREAD]: Don't test anything.
+ * tst-tls3mod.c: Likewise.
+ * tst-tls1.c: Likewise.
+ * tst-tls2.c: Likewise.
+
+ * tst-mutex5.c (do_test): Unlock before destroy, otherwise we invoke
+ undefined behavior.
+
+ * tst-join5.c (tf1, tf2): Add a cast.
+
+ * Makeconfig (includes): Append -I$(..)nptl to this variable.
+
+ * tst-barrier2.c (do_test) [! _POSIX_THREAD_PROCESS_SHARED]:
+ Don't test anything.
+ * tst-cond4.c: Likewise.
+ * tst-cond6.c: Likewise.
+ * tst-flock2.c: Likewise.
+ * tst-mutex4.c: Likewise.
+ * tst-rwlock4.c: Likewise.
+ * tst-signal1.c: Likewise.
+ * tst-spin2.c: Likewise.
+ * tst-cond11.c [! _POSIX_CLOCK_SELECTION]: Likewise.
+
+ * tst-mutex4.c: Use test-skeleton.c.
+ * tst-spin2.c: Likewise.
+ * tst-sysconf.c: Likewise.
+ * tst-barrier2.c: Likewise.
+ * tst-cond4.c: Likewise.
+ * tst-cond6.c: Likewise.
+ * tst-rwlock4.c: Likewise.
+ * tst-unload.c: Likewise.
+ * tst-flock2.c (do_test): Use return instead of exit.
+
+2003-03-22 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/fork.c (__fork): Add libc_hidden_def.
+
+2003-03-21 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.h
+ (__lll_mutex_trylock): Use atomic_compare_and_exchange_val_acq
+ instead of __lll_compare_and_swap.
+ * sysdeps/unix/sysv/linux/ia64/pthread_once.c (__pthread_once):
+ Likewise.
+ Removed definition if __lll_compare_and_swap.
+
+ * cancellation.c: Adjust for new form of compare&exchange macros.
+ * cleanup_defer.c: Likewise.
+ * init.c: Likewise.
+ * libc-cancellation.c: Likewise.
+ * old_pthread_cond_broadcast.c: Likewise.
+ * old_pthread_cond_signal.c: Likewise.
+ * old_pthread_cond_timedwait.c: Likewise.
+ * old_pthread_cond_wait.c: Likewise.
+ * pthread_cancel.c: Likewise.
+ * pthread_create.c: Likewise.
+ * pthread_detach.c: Likewise.
+ * pthread_join.c: Likewise.
+ * pthread_key_delete.c: Likewise.
+ * pthread_setcancelstate.c: Likewise.
+ * pthread_setcanceltype.c: Likewise.
+ * pthread_timedjoin.c: Likewise.
+ * pthread_tryjoin.c: Likewise.
+ * sysdeps/pthread/createthread.c: Likewise.
+
+2003-03-20 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.h: Include <atomic.h>.
+ Remove __lll_add, __lll_dec_if_positive, and __lll_test_and_set
+ definitions. Replace uses with calls to atomic_* functions.
+ * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h: Likewise.
+ * sysdeps/unix/sysv/linux/lowlevellock.c: Replace __lll_add and
+ __lll_test_and_set calls with atomic_exchange_and_add and
+ atomic_exchange calls respectively.
+ * sysdeps/unix/sysv/linux/sem_post.c: Likewise.
+ * sysdeps/unix/sysv/linux/sem_timedwait.c: Likewise.
+ * sysdeps/unix/sysv/linux/sem_trywait.c: Likewise.
+ * sysdeps/unix/sysv/linux/sem_wait.c: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/pthread_once.c: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/sem_port.c: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/pthread_once.c: Likewise.
+
+ * allocatestack.c (allocate_stack): Assume atomic_exchange_and_add
+ returns the old value.
+
+2003-03-20 Martin Schwidefsky <sky@mschwid3.boeblingen.de.ibm.com>
+
+ * sysdeps/s390/pthread_spin_lock.c (pthread_spin_lock): Use type
+ int for variable OLDVAL and correct inline assembler contraint.
+ * sysdeps/s390/pthread_spin_trylock.c (pthread_spin_trylock): Use
+ type int for variable OLD.
+
+ * sysdeps/s390/tls.h (TLS_MULTIPLE_THREADS_IN_TCB): Define it
+ only for s390-32.
+ * sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h
+ (SINGLE_THREAD_P): Use global variable __local_multiple_threads
+ instead of multiple_threads field in the TCB.
+
+2003-03-19 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/i386/i686/bits/atomic.h: Removed.
+ * sysdeps/i386/i586/bits/atomic.h: Removed.
+ * sysdeps/i386/i486/bits/atomic.h: Removed. Moved to glibc.
+ * sysdeps/x86_64/bits/atomic.h: Removed. Moved to glibc.
+ * sysdeps/s390/bits/atomic.h: Removed. Moved to glibc.
+ * sysdeps/sh/bits/atomic.h: Removed. Moved to glibc.
+ * sysdeps/ia64/bits/atomic.h: Removed. Moved to glibc.
+ * sysdeps/powerpc/bits/atomic.h: Removed. Moved to glibc.
+ * atomic.h: Removed. Moved to glibc.
+
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: Add
+ support for clock selection.
+
+ * sysdeps/pthread/pthread_cond_broadcast.c: Release lock before
+ signalling waiters.
+
+2003-03-18 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h (__lll_test_and_set):
+ Add __lll_rel_instr first. Add memory clobber.
+ (lll_mutex_unlock): Use __lll_test_and_set.
+ From Paul Mackerras <paulus@samba.org>.
+
+ * sysdeps/powerpc/tls.h (TLS_MULTIPLE_THREADS_IN_TCB): Define
+ unconditionally.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h
+ (SINGLE_THREAD_P): Add `header.' prefix.
+ From Paul Mackerras <paulus@samba.org>.
+
+ * Versions (libpthread: GLIBC_2.3.2): Move pthread_tryjoin_np and
+ pthread_timedjoin_np to ...
+ (libpthread: GLIBC_2.3.3): ... here.
+ (libpthread: GLIBC_2.2): Move pthread_barrierattr_getpshared there too.
+
+ * sysdeps/pthread/pthread_cond_timedwait.c (__pthread_cond_timedwait):
+ Avoid shadowing VAL variable.
+
+ * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h (__lll_test_and_set):
+ New macro.
+
+2003-03-18 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-cond11.
+ * tst-cond11.c: New file.
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S: Reorder
+ struct passed to cleanup handler to eliminate one more
+ instruction.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Likewise.
+
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h
+ (pthrad_cond_t): Replace __unused field with __clock.
+
+ * sysdeps/pthread/pthread_cond_wait.c: Release condvar lock before
+ waken all waiters in cleanup handler.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S: Likewise.
+
+ * pthread_condattr_getclock.c: New file.
+ * pthread_condattr_setclock.c: New file.
+ * sysdeps/pthread/pthread.h: Declare these new functions.
+ * Versions [GLIBC_2.3.3] (libpthread): Add the new functions.
+ * Makefile (libpthread-routines): Add the new functions.
+ * sysdeps/unix/sysv/linux/internaltypes.h (struct pthread_condattr):
+ Renamed field to value. Document use of the bits.
+ * pthread_condattr_getpshared.c: Adjust for struct pthread_condattr
+ change.
+ * pthread_condattr_setpshared.c: Likewise.
+ * pthread_cond_init.c (__pthread_cond_init): Initialized __clock field.
+ * sysdeps/unix/sysv/linux/lowlevelcond.sym: Add cond_clock symbol.
+ * sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h (pthread_cond_t):
+ Add __clock field.
+ * sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S:
+ Implement clock selection.
+ * sysdeps/pthread/pthread_cond_timedwait.c: Likewise.
+ * pthread-errnos.sym: Add ENOSYS.
+ * sysdeps/unix/sysv/linux/bits/posix_opt.h: Define
+ _POSIX_CLOCK_SELECTION.
+ * sysdeps/unix/sysv/linux/i386/bits/posix_opt.h: Likewise.
+
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: Remove
+ invalid .size directive.
+
+2003-03-17 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/unix/sysv/linux/lowlevellock.c (__lll_lock_wait):
+ Formatting tweaks.
+
+2003-03-17 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/ia64/pthread_once.c: Use __builtin_expect.
+ Use __lll_add instead of spelling it out. Use protected symbol names.
+ * sysdeps/unix/sysv/linux/ia64/sem_post.c: Use __builtin_expect.
+ Use __lll_add.
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.h (__lll_compare_and_swap):
+ Renamed from lll_compare_and_swap. Use new name where necessary.
+ (__lll_add): Defined.
+ (__lll_dec_if_positive): Defined.
+ (__lll_test_and_set): Defined.
+ * sysdeps/ia64/pthread_spin_init.c: Removed.
+ * sysdeps/unix/sysv/linux/ia64/lowlevelmutex.c: Removed.
+ * sysdeps/unix/sysv/linux/ia64/sem_trywait.c: Removed.
+ * sysdeps/unix/sysv/linux/ia64/sem_wait.c: Removed.
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.c: Removed.
+ * sysdeps/unix/sysv/linux/ia64/libc-lowlevellock.c: Removed.
+ * sysdeps/unix/sysv/linux/ia64/libc-lowlevelmutex.c: Removed.
+ * sysdeps/unix/sysv/linux/ia64/sem_timedwait.c: Removed.
+ * sysdeps/ia64/bits/atomic.h: Add __builtin_expect where appropriate.
+ * sysdeps/ia64/pthread_spin_unlock.c (pthread_spin_unlock): Use
+ __sync_lock_release_si.
+ Patch by Jakub Jelinek.
+
+ * sysdeps/unix/sysv/linux/lowlevellock.c (__lll_timedlock_wait):
+ Fix timeout handling.
+ (__lll_timedwait_tid): Likewise.
+ (lll_unlock_wake_cb): Wake up other waiters if necessary.
+ Patch by Jakub Jelinek.
+
+ * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h: Pretty printing.
+
+2003-03-17 Roland McGrath <roland@redhat.com>
+
+ PowerPC port contributed by Paul Mackerras <paulus@samba.org>.
+ * sysdeps/pthread/pthread_spin_init.c: New file.
+ * sysdeps/pthread/pthread_spin_unlock.c: New file.
+ * sysdeps/powerpc/Makefile: New file.
+ * sysdeps/powerpc/pthread_spin_lock.c: New file.
+ * sysdeps/powerpc/pthread_spin_trylock.c: New file.
+ * sysdeps/powerpc/pthreaddef.h: New file.
+ * sysdeps/powerpc/tcb-offsets.sym: New file.
+ * sysdeps/powerpc/td_ta_map_lwp2thr.c: New file.
+ * sysdeps/powerpc/tls.h: New file.
+ * sysdeps/powerpc/bits/atomic.h: New file.
+ * sysdeps/unix/sysv/linux/libc-lowlevelmutex.c: New file.
+ * sysdeps/unix/sysv/linux/libc-lowlevellock.c: New file.
+ * sysdeps/unix/sysv/linux/lowlevellock.c: New file.
+
+ * sysdeps/unix/sysv/linux/lowlevelmutex.c: New file.
+ * sysdeps/unix/sysv/linux/sem_post.c: New file.
+ * sysdeps/unix/sysv/linux/sem_timedwait.c: New file.
+ * sysdeps/unix/sysv/linux/sem_trywait.c: New file.
+ * sysdeps/unix/sysv/linux/sem_wait.c: New file.
+ * sysdeps/unix/sysv/linux/powerpc/Makefile: New file.
+ * sysdeps/unix/sysv/linux/powerpc/createthread.c: New file.
+ * sysdeps/unix/sysv/linux/powerpc/fork.c: New file.
+ * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h: New file.
+ * sysdeps/unix/sysv/linux/powerpc/pt-vfork.S: New file.
+ * sysdeps/unix/sysv/linux/powerpc/pthread_once.c: New file.
+ * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h: New file.
+ * sysdeps/unix/sysv/linux/powerpc/bits/semaphore.h: New file.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h: New file.
+ * sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h: New file.
+
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.c: Use __gettimeofday,
+ not gettimeofday.
+ * sysdeps/unix/sysv/linux/ia64/lowlevelmutex.c: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/sem_timedwait.c: Likewise.
+ * sysdeps/unix/sysv/linux/s390/lowlevellock.c: Likewise.
+ * sysdeps/unix/sysv/linux/s390/lowlevelmutex.c: Likewise.
+ * sysdeps/unix/sysv/linux/s390/sem_timedwait.c: Likewise.
+
+2003-03-17 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/pthread_cond_wait.c: Correct exit criteria.
+ * sysdeps/pthread/pthread_cond_timedwait.c: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S: Likewise.
+ Patch by Ewald Snel <ewald@rambo.its.tudelft.nl>.
+
+2003-03-16 Roland McGrath <roland@redhat.com>
+
+ * tst-fork4.c: Include <string.h>.
+ * tst-signal2.c: Likewise.
+ * tst-mutex5.c (do_test): exit -> return.
+ * tst-mutex2.c: Include <stdlib.h>.
+
+2003-03-16 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelmutex.S
+ (__lll_mutex_timedlock_wait): Correct expected value after
+ spurious wakeup. Otherwise we would never wait again.
+
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h: Work around red
+ zone versus inline asm stupidity. Use correct instructions.
+
+ * tst-rwlock6.c: Add some more status output.
+
+2003-03-15 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/pthread/configure.in: New file.
+ * sysdeps/pthread/configure: New file (generated).
+
+2003-03-15 Ulrich Drepper <drepper@redhat.com>
+
+ * allocatestack.c (allocate_stack): Store the exact stack size of
+ user allocated stacks.
+
+2003-03-15 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h
+ (SINGLE_THREAD): Use `header' prefix instead of `header.data'.
+ * sysdeps/sh/tcb-offsets.sym (MULTIPLE_THREADS_OFFSET): Likewise.
+ * sysdeps/sh/tls.h (TLS_MULTIPLE_THREADS_IN_TCB): Define.
+ * sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h (SINGLE_THREAD_P):
+ Use `header.' prefix.
+ * sysdeps/ia64/tcb-offsets.sym (MULTIPLE_THREADS_OFFSET): Likewise.
+
+2003-03-15 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/x86_64/pthreaddef.h (CURRENT_STACK_FRAME): Don't use
+ __builtin_frame_address, use stack pointer.
+
+ * sysdeps/unix/sysv/linux/jmp-unwind.c: Use CURRENT_STACK_FRAME
+ instead of __builtin_frame_pointer.
+
+2003-03-14 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-basic1.c (do_test): Add cast to avoid warning.
+ * tst-basic2.c (do_test): Likewise.
+
+ * sysdeps/unix/sysv/linux/x86_64/pthread_once.S: Use correct
+ amount of stack correction.
+
+ * tst-fork4.c: Use test-skeleton.c.
+
+2003-03-14 Roland McGrath <roland@redhat.com>
+
+ * init.c: Fix typo "#eli" for "#else".
+
+2003-03-14 Steven Munroe <sjmunroe@us.ibm.com>
+
+ * allocatestack.c (__stack_user): Use hidden_data_def.
+ * pthread_create.c (__pthread_keys): Likewise.
+
+ * init.c [__powerpc__] (__NR_set_tid_address): Define it.
+
+2003-03-14 Roland McGrath <roland@redhat.com>
+
+ * tst-fork4.c: New file.
+ * Makefile (tests): Add it.
+
+ * descr.h (struct pthread): Move the union out of [!TLS_DTV_AT_TP], so
+ we always define the padding space.
+ [!TLS_DTV_AT_TP]: Give tcbhead_t field a name, `header', since GCC
+ stopped supporting its own extensions fully.
+ [TLS_MULTIPLE_THREADS_IN_TCB]: Put `multiple_threads' inside a wrapper
+ struct also called `header', so `header.multiple_threads' is the field
+ name to use on all machines.
+ * allocatestack.c (allocate_stack): Use `header.' prefix.
+ * sysdeps/pthread/createthread.c (create_thread): Likewise.
+ * pthread_create.c (__pthread_create_2_1): Likewise.
+ * sysdeps/i386/tls.h (INSTALL_NEW_DTV, THREAD_DTV): Likewise.
+ (THREAD_SELF): Likewise.
+ * sysdeps/x86_64/tls.h: Likewise.
+ * sysdeps/unix/sysv/linux/i386/sysdep-cancel.h
+ (SINGLE_THREAD_P): Likewise.
+ * sysdeps/unix/sysv/linux/sh/sysdep-cancel.h
+ (SINGLE_THREAD_P): Likewise.
+ * sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h
+ (SINGLE_THREAD_P): Likewise.
+
+ * sysdeps/s390/td_ta_map_lwp2thr.c (td_ta_map_lwp2thr): Use REGS[18]
+ value directly.
+
+2003-03-14 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread_create.c (start_thread): Use CALL_THREAD_FCT if defined.
+ * sysdeps/i386/tls.h: Define CALL_THREAD_FCT.
+
+ * pthread_create.c (start_thread): setjmp is expected to return 0.
+
+ * sysdeps/x86_64/tls.h (THREAD_GETMEM): Mark asms volatile.
+ (THREAD_GETMEM_NC): Likewise.
+
+2003-03-13 Ulrich Drepper <drepper@redhat.com>
+
+ * allocatestack.c (allocate_stack): If MULTI_PAGE_ALIASING is defined
+ and the size of the stack which must be allocated is a multiple,
+ allocate one more page.
+ * sysdeps/i386/i686/Makefile: Don't define COLORING_INCREMENT, but
+ MULTI_PAGE_ALIASING.
+
+2003-03-13 Roland McGrath <roland@redhat.com>
+
+ * pthread_create.c (start_thread): Set EXITING_BIT after the
+ event-reporting (and destructors), not before.
+
+2003-03-13 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.h (lll_futex_timed_wait,
+ lll_futex_wake): Declare register variables as long int instead of
+ unsigned long int. Patch by Ian Wienand <ianw@gelato.unsw.edu.au>.
+ Make syscall arguments clobbered by the syscall.
+ (lll_futex_wait): Define using lll_futex_timed_wait.
+
+ * sysdeps/ia64/td_ta_map_lwp2thr.c (td_ta_map_lwp2thr): Cast regs[13]
+ to void *.
+
+ * sysdeps/unix/sysv/linux/fork.c (__libc_fork): Only declare and set
+ PPID if [! NDEBUG].
+
+ * allocatestack.c (nptl_ncreated): Only declare if
+ COLORING_INCREMENT != 0.
+
+ * pthreadP.h (__pthread_enable_asynccancel_2): New prototype.
+ (__libc_enable_asynccancel_2): Remove prototype.
+
+ * sysdeps/unix/sysv/linux/ia64/fork.c (ARCH_FORK): Swap ptid and
+ ctid to match kernel.
+
+2003-03-12 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Add
+ libc_multiple_threads.
+ * sysdeps/unix/sysv/linux/libc_pthread_init.c: Move definition of
+ __libc_multiple_threads to...
+ * sysdeps/unix/sysv/linux/libc_multiple_threads.c: ...here. New file.
+
+ * sysdeps/unix/sysv/linux/x86_64/sem_post.S: Remove unnecessary
+ versioning.
+ * sysdeps/unix/sysv/linux/x86_64/sem_trywait.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/sem_wait.S: Likewise.
+
+ * sysdeps/unix/sysv/linux/x86_64/pthread_once.S
+ (__pthread_once_internal): Define.
+
+ * sysdeps/unix/sysv/linux/i386/i486/sem_post.S: Use shlib-compat.h
+ macros instead of .symver directly.
+ * sysdeps/unix/sysv/linux/i386/i486/sem_trywait.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/sem_wait.S: Likewise.
+
+ * sysdeps/x86_64/tls.h [__ASSEMBLER__]: Include tcb-offsets.h.
+ * sysdeps/x86_64/tcb-offsets.sym: New file.
+ * sysdeps/x86_64/Makefile: New file.
+
+ * sysdeps/i386/tcb-offsets.sym: Add SELF.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_rdlock.S: Use SELF
+ to access own pthread_t in TCB.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S:
+ Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S:
+ Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_wrlock.S: Likewise.
+
+2003-03-12 Roland McGrath <roland@redhat.com>
+
+ * pthread-errnos.sym: New file.
+ * Makefile (gen-as-const-headers): New variable, list that file.
+ * sysdeps/unix/sysv/linux/i386/i486/sem_wait.S: Include generated
+ header <pthread-errnos.h> instead of defining errno values here.
+ * sysdeps/unix/sysv/linux/i386/i486/sem_trywait.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/sem_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/sem_post.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_wrlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S:
+ Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S:
+ Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_rdlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelmutex.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/sem_wait.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/sem_trywait.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/sem_post.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevelmutex.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/sem_trywait.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/sem_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/sem_post.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/sem_wait.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_wrlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedwrlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedrdlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_rdlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/lowlevellock.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/lowlevelmutex.S: Likewise.
+ * sysdeps/i386/i486/pthread_spin_trylock.S: Likewise.
+ * sysdeps/x86_64/pthread_spin_trylock.S: Likewise.
+ * sysdeps/sh/pthread_spin_trylock.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S: Likewise.
+
+ * sysdeps/unix/sysv/linux/fork.c: Add an assert to check that
+ CLONE_CHILD_SETTID worked.
+
+2003-03-12 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S: New
+ file.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S: New
+ file.
+
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h
+ (pthread_cond_t): Add padding.
+
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S: New file.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S: New file.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S: New file.
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S
+ (__pthread_rwlock_timedwrlock): Add missing opcode suffix.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S
+ (__pthread_rwlock_timedrdlock): Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_wrlock.S
+ (__pthread_rwlock_wrlock): Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_rdlock.S
+ (__pthread_rwlock_rdlock): Likewise.
+
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: New file.
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Return
+ result of lock re-get if it fails.
+
+2003-03-11 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.S: Fix asm syntax.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevelmutex.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_once.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/sem_post.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/sem_trywait.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/sem_wait.S: Likewise.
+
+ * sysdeps/x86_64/tls.h (THREAD_SELF, THREAD_GETMEM, THREAD_GETMEM_NC,
+ THREAD_SETMEM, THREAD_SETMEM_NC): Correct asm syntax.
+
+ * allocatestack.c [! TLS_MULTIPLE_THREADS_IN_TCB] (allocate_stack):
+ Initialize *__libc_multiple_threads_ptr not __libc_multiple_threads.
+ * sysdeps/pthread/createthread.c [! TLS_MULTIPLE_THREADS_IN_TCB]
+ (create_thread): Likewise.
+ Define __pthread_multiple_threads and __libc_multiple_threads_ptr.
+ * init.c (__pthread_initialize_minimal_internal): Initialize
+ __libc_multiple_threads_ptr if necessary.
+ * pthreadP.h: Adjust prototype for __libc_pthread_init. Declare
+ __pthread_multiple_threads and __libc_multiple_threads_ptr.
+ * sysdeps/unix/sysv/linux/libc_pthread_init.c: Define
+ __libc_multiple_threads.
+ (__libc_pthread_init): Return pointer to __libc_pthread_init if
+ necessary.
+
+ * sysdeps/i386/tls.h (THREAD_SETMEM): Fix one-byte variant.
+ (THREAD_SETMEM_NC): Likewise.
+
+ * sysdeps/x86_64/pthread_spin_trylock.c: Removed.
+ * sysdeps/x86_64/pthread_spin_trylock.S: New file.
+ * sysdeps/x86_64/pthread_spin_unlock.c: Removed.
+ * sysdeps/x86_64/pthread_spin_unlock.S: New file.
+
+ * sysdeps/i386/i486/pthread_spin_trylock.S (pthread_spin_trylock):
+ Eliminate one entire instruction.
+
+ * cancellation.c (__pthread_enable_asynccancel_2): New function.
+ * pthreadP.h: Declare __pthread_enable_asynccancel_2.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S
+ (__pthread_cond_timedwait): Use __pthread_enable_asynccancel_2
+ instead of __pthread_enable_asynccancel.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S
+ (__pthread_cond_wait): Likewise.
+ * sysdeps/pthread/pthread_cond_timedwait.c
+ (__pthread_cond_timedwait): Likewise.
+ * sysdeps/pthread/pthread_cond_wait.c (__pthread_cond_wait): Likewise.
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S
+ (__condvar_cleanup): Wake up all waiters in case we got signaled
+ after being woken up but before disabling asynchronous
+ cancellation.
+ * sysdeps/pthread/pthread_cond_wait.c (__condvar_cleanup): Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
+ (__condvar_cleanup): Likewise.
+
+ * init.c (__NR_set_tid_address): If already defined, don't redefine.
+ Make it an error if architecture has no #if case. Add x86-64.
+
+ * sysdeps/unix/sysv/linux/x86_64/Makefile: Add flags for
+ pt-initfini.s generation.
+
+ * sysdeps/x86_64/tls.h: Include <asm/prctl.h>.
+ (TLS_INIT_TP): Fix typo.
+
+2003-03-11 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/ia64/bits/atomic.h (atomic_exchange_and_add): Swap 2nd and
+ 3rd argument of __arch_compare_and_exchange_{32,64}_val_acq.
+
+ * sysdeps/unix/sysv/linux/ia64/sem_post.c: Include semaphore.h.
+ * sysdeps/unix/sysv/linux/ia64/sem_timedwait.c: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/sem_trywait.c: Likewise.
+ * sysdeps/unix/sysv/linux/ia64/sem_wait.c: Likewise.
+ * sysdeps/unix/sysv/linux/s390/sem_post.c: Likewise.
+ * sysdeps/unix/sysv/linux/s390/sem_timedwait.c: Likewise.
+ * sysdeps/unix/sysv/linux/s390/sem_trywait.c: Likewise.
+ * sysdeps/unix/sysv/linux/s390/sem_wait.c: Likewise.
+
+2003-03-11 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/pthread_cond_timedwait.c
+ (__pthread_cond_timedwait): Return the result of the final
+ locking. If it succeeds, the regular function return value.
+
+ * sysdeps/pthread/pthread_cond_wait.c (__pthread_cond_wait):
+ Return result of the final locking.
+ * version.c (__nptl_main): Work around problems with the strange
+ INTERNAL_SYSCALL macro on ppc32.
+ * init.c (__pthread_initialize_minimal_internal): Unblock
+ SIGCANCEL in case the parent blocked it.
+ Reported by Paul Mackerras <paulus@samba.org>.
+
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S: New file.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S: New file.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S: New file.
+
+2003-03-11 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/pthread/pthread_cond_timedwait.c
+ (__pthread_cond_timedwait): Unlock and fail if
+ __pthread_mutex_unlock_internal failed.
+
+ * sysdeps/pthread/createthread.c (ARCH_CLONE): Define if not defined.
+ (create_thread): Only assert PD->tcb != NULL under [TLS_TCB_AT_TP].
+ Use ARCH_CLONE.
+ * allocatestack.c (ALLOCATE_STACK_PARMS): New macro.
+ [NEED_SEPARATE_REGISTER_STACK] (STACK_VARIABLES,
+ STACK_VARIABLES_ARGS, STACK_VARIABLES_PARMS, ALLOCATE_STACK_PARMS,
+ ALLOCATE_STACK): New macros.
+ (TLS_TPADJ): New macro.
+ (get_cached_stack, queue_stack, __deallocate_stack): Use TLS_TPADJ.
+ (allocate_stack): Handle TLS_DTV_AT_TP and
+ NEED_SEPARATE_REGISTER_STACK. Use TLS_TPADJ.
+ * pthread_create.c (__pthread_create_2_1) [! TLS_TCB_AT_TP]:
+ Don't set PD->self.
+ * init.c [__ia64__] (__NR_set_tid_address): Define.
+
+ * sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h: New file.
+ * sysdeps/unix/sysv/linux/ia64/bits/semaphore.h: New file.
+ * sysdeps/unix/sysv/linux/ia64/fork.c: New file.
+ * sysdeps/unix/sysv/linux/ia64/createthread.c: New file.
+ * sysdeps/unix/sysv/linux/ia64/libc-lowlevellock.c: New file.
+ * sysdeps/unix/sysv/linux/ia64/libc-lowlevelmutex.c: New file.
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.c: New file.
+ * sysdeps/unix/sysv/linux/ia64/lowlevellock.h: New file.
+ * sysdeps/unix/sysv/linux/ia64/lowlevelmutex.c: New file.
+ * sysdeps/unix/sysv/linux/ia64/pt-initfini.c: New file.
+ * sysdeps/unix/sysv/linux/ia64/pt-vfork.S: New file.
+ * sysdeps/unix/sysv/linux/ia64/pthread_once.c: New file.
+ * sysdeps/unix/sysv/linux/ia64/sem_post.c: New file.
+ * sysdeps/unix/sysv/linux/ia64/sem_timedwait.c: New file.
+ * sysdeps/unix/sysv/linux/ia64/sem_trywait.c: New file.
+ * sysdeps/unix/sysv/linux/ia64/sem_wait.c: New file.
+ * sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h: New file.
+ * sysdeps/ia64/bits/atomic.h: New file.
+ * sysdeps/ia64/Makefile: New file.
+ * sysdeps/ia64/pthread_spin_init.c: New file.
+ * sysdeps/ia64/pthread_spin_lock.c: New file.
+ * sysdeps/ia64/pthread_spin_trylock.c: New file.
+ * sysdeps/ia64/pthread_spin_unlock.c: New file.
+ * sysdeps/ia64/pthreaddef.h: New file.
+ * sysdeps/ia64/tcb-offsets.sym: New file.
+ * sysdeps/ia64/td_ta_map_lwp2thr.c: New file.
+ * sysdeps/ia64/tls.h: New file.
+
+ * sysdeps/s390/pthreaddef.h (__exit_thread_inline): Pass 1 argument
+ to syscall instead of no arguments.
+
+2003-03-10 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/sem_post.S: New file.
+ * sysdeps/unix/sysv/linux/x86_64/sem_trywait.S: New file.
+ * sysdeps/unix/sysv/linux/x86_64/sem_wait.S: New file.
+ * sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S: New file.
+
+ * sysdeps/unix/sysv/linux/i386/i486/sem_post.S: Fix error value in
+ unused code.
+
+ * sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S: New file
+
+ * sysdeps/unix/sysv/linux/Makefile (gen-as-const-headers): Add
+ lowlevelbarrier.sym.
+ * sysdeps/unix/sysv/linux/lowlevelbarrier.sym: New file.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_barrier_wait.S:
+ Include lowlevelbarrier.h and don't define offsets locally.
+ * sysdeps/unix/sysv/linux/sh/pthread_barrier_wait.S: Likewise.
+
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
+ (__lll_mutex_lock_wait): Reverse order of first two parameters.
+ (__lll_mutex_timedlock_wait): Likewise.
+ (lll_mutex_lock): Adjust asm for that.
+ (lll_mutex_timedlock): Likewise. Mark cx, cc, r10 as clobbered.
+ (lll_lock): Adjust asm for operand order change.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevelmutex.S: New file.
+ * sysdeps/unix/sysv/linux/x86_64/libc-lowlevelmutex.S: New file.
+
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h (__lll_lock_wait):
+ Reverse order of parameters.
+ (__lll_timedwait_tid): Remove regparms attribute.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.S: New file.
+ * sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S: New file.
+
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S
+ (__lll_timedwait_tid): Remove one unnecessary instruction.
+
+ * sysdeps/unix/sysv/linux/sh/lowlevelmutex.S: Define
+ __lll_mutex_timedlock_wait only for NOT_IN_libc.
+ * sysdeps/unix/sysv/linux/sh/libc-lowlevelmutex.S: Include
+ lowlevelmutex.S.
+
+ * sysdeps/unix/sysv/linux/sh/lowlevellock.S: Define
+ lll_unlock_wake_cb, __lll_wait_tid, and __lll_timedwait_tid only
+ for NOT_IN_libc.
+ * sysdeps/unix/sysv/linux/sh/libc-lowlevellock.S: Include
+ lowlevellock.S.
+
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelmutex.S: Don't define
+ LOCK is already defined. Don't define __lll_mutex_timedlock_wait
+ for libc.so.
+ * sysdeps/unix/sysv/linux/i386/i486/libc-lowlevelmutex.S: Only
+ define LOCK here (if UP is not defined). The actual code is in
+ lowlevelmutex.S.
+
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S: Don't define
+ LOCK is already defined. Don't define lll_unlock_wake_cb and
+ __lll_timedwait_tid for libc.so.
+ * sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S: Only
+ define LOCK here (if UP is not defined). The actual code is in
+ lowlevellock.S.
+
+ * sysdeps/unix/sysv/linux/i386/lowlevelsem.h: Not needed anymore.
+ * sysdeps/unix/sysv/linux/s390/lowlevelsem.h: Likewise.
+ * sysdeps/unix/sysv/linux/s390/sem_post.c: Include lowlevellock.h
+ instead of lowlevelsem.h.
+ * sysdeps/unix/sysv/linux/s390/sem_timedwait.c: Likewise.
+ * sysdeps/unix/sysv/linux/s390/sem_trywait.c: Likewise.
+ * sysdeps/unix/sysv/linux/s390/sem_wait.c: Likewise.
+
+ * sysdeps/unix/sysv/linux/Makefile (gen-as-const-headers): Add
+ lowlevelrwlock.sym.
+ * sysdeps/unix/sysv/linux/lowlevelrwlock.sym: New file.
+ * sysdeps/unix/sysv/linux/i386/lowlevelrwlock.h: Removed.
+ * sysdeps/unix/sysv/linux/sh/lowlevelrwlock.h: Removed.
+
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h (lll_trylock): Fix
+ register loading.
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h (lll_trylock): Undo
+ last changed. D'oh.
+
+ * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h: New file.
+
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h: Remove declaration
+ of __libc_locking_needed.
+ (lll_trylock): Initialize %eax to zero.
+
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h: Update
+ pthread_cond_t definition.
+
+2003-03-10 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/unix/sysv/linux/lowlevelcond.sym: New file.
+ * sysdeps/unix/sysv/linux/Makefile (gen-as-const-headers): Add it.
+ * sysdeps/unix/sysv/linux/sh/lowlevelcond.h: File removed.
+ * sysdeps/unix/sysv/linux/i386/lowlevelcond.h: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/lowlevelcond.h: Likewise.
+
+ * allocatestack.c (allocate_stack) [!TLS_MULTIPLE_THREADS_IN_TCB]:
+ Instead of setting PD->multiple_threads, set globals
+ __pthread_multiple_threads and __libc_multiple_threads.
+ * sysdeps/pthread/createthread.c (create_thread): Likewise.
+ * sysdeps/i386/tls.h (TLS_MULTIPLE_THREADS_IN_TCB): Define it.
+ * sysdeps/s390/tls.h (TLS_MULTIPLE_THREADS_IN_TCB): Likewise.
+
+ * descr.h (struct pthread): Conditionalize first member on
+ [!TLS_DTV_AT_TP]. Replace the `header' member with an anonymous union
+ containing an anonymous tcbhead_t. Move `list' member out.
+ [TLS_MULTIPLE_THREADS_IN_TCB]: Define a `multiple_threads' member.
+ * allocatestack.c: Remove use of `header.data.' prefix.
+ * pthread_create.c: Likewise.
+ * init.c (__pthread_initialize_minimal_internal): Likewise.
+ * sysdeps/pthread/createthread.c (create_thread): Likewise.
+ * sysdeps/i386/tls.h (INSTALL_DTV): Add parens.
+ (THREAD_SELF, THREAD_DTV, INSTALL_NEW_DTV): No `header.data.' prefix.
+ * sysdeps/x86_64/tls.h: Likewise.
+ * sysdeps/unix/sysv/linux/i386/sysdep-cancel.h
+ (SINGLE_THREAD_P): Likewise.
+ * sysdeps/unix/sysv/linux/sh/sysdep-cancel.h
+ (SINGLE_THREAD_P): Likewise.
+ * sysdeps/i386/tls.h (tcbhead_t): Remove `list' member.
+ * sysdeps/s390/tls.h (tcbhead_t): Likewise.
+
+2003-03-09 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/lowlevelcond.h: New file.
+
+ * sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h: New file.
+ * sysdeps/unix/sysv/linux/x86_64/fork.c: New file.
+
+ * sysdeps/unix/sysv/linux/x86_64/pthread_once.S: Fix many
+ leftovers from the ia32 code.
+
+ * sysdeps/unix/sysv/linux/i386/pthread_once.S: Remove unneccessary
+ memory load.
+ (clear_once_control): Don't load %esi.
+
+ * sysdeps/x86_64/tls.h: Remove all traces of segment descriptor
+ handling.
+
+ * sysdeps/unix/sysv/linux/x86_64/fork.c: New file.
+
+ * sysdeps/unix/sysv/linux/s390/createthread.c: Moved to...
+ * sysdeps/unix/sysv/linux/createthread.c: ...here.
+
+ * Makefile (tests): Add tst-cond10.
+ * tst-cond10.c: New file.
+
+2003-03-08 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-tls2.c (do_test): Add TEMP_FAILURE_RETRY around sem_wait call.
+ * tst-signal3.c (do_test): Likewise.
+ * tst-sem5.c (do_test): Likewise.
+ * tst-kill6.c (do_test): Likewise.
+ * tst-tls3.c (do_test): Likewise. Include <errno.h>.
+
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h: Use add/sub instead
+ of inc/dec.
+ * sysdeps/unix/sysv/linux/i386/lowlevelsem.h: Likewise.
+ * sysdeps/unix/sysv/linux/i386/pthread_once.S: Likewise
+ * sysdeps/unix/sysv/linux/i386/i486/sem_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/sem_post.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_wrlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_unlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S:
+ Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S:
+ Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_rdlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_signal.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_broadcast.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_barrier_wait.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelmutex.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S: Likewise.
+
+ * allocatestack.c (allocate_stack): If mprotect() fails free the
+ TLS memory.
+
+2003-03-07 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/i386/i486/bits/atomic.h: Fix a few unused definitions.
+
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h: Remove all trace of
+ lll_wake_tid. This was used only to work around kernel limits in
+ the early days.
+ * sysdeps/unix/sysv/linux/s390/lowlevellock.h: Likewise.
+ * sysdeps/unix/sysv/linux/sh/libc-lowlevellock.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/lowlevellock.S: Likewise.
+ * sysdeps/unix/sysv/linux/sh/lowlevellock.h: Likewise.
+
+ * init.c (__static_tls_align_m1): Renamed from __static_tls_align.
+ (__pthread_initialize_minimal_internal): Change initialization of
+ __static_tls_align_m1 appropriately.
+ * pthreadP.h (__static_tls_align_m1): Renamed from
+ __static_tls_align.
+ * allocatestack.c (allocate_stack): Use __static_tls_align_m1
+ instead of __static_tls_align-1.
+
+2003-03-04 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/Makefile: New file.
+
+ * pthread_create.c: Define __pthread_keys using nocommon
+ attribute, not by placing it explicitly in bss.
+ Remove DEFINE_DEALLOC definition. Not needed anymore.
+
+ * allocatestack.c: Define ARCH_MAP_FLAGS if not already defined.
+ Use it in mmap call to allocate stacks.
+
+ * sysdeps/pthread/createthread.c (create_thread): Fix comment.
+
+ * pthread_create.c (start_thread): Use THREAD_SETMEM to store
+ result of the thread function.
+
+2003-03-03 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/s390/dl-sysdep.h: Removed. The generic
+ version is just fine.
+
+ * sysdeps/unix/sysv/linux/libc_pthread_init.c
+ (__pthread_child_handler): Renamed from pthread_child_handler,
+ exported, and marked hidden. Change all users.
+ * sysdeps/unix/sysv/linux/register-atfork.c (free_mem): Do not
+ free __pthread_child_handler from child list.
+
+2003-03-03 Martin Schwidefsky <schwidefsky@de.ibm.com>
+
+ * atomic.h (atomic_exchange_and_add): Return newval, not oldval.
+
+ * sysdeps/pthread/pthread_cond_timedwait.c (__pthread_cond_timedwait):
+ Fix handling of cancellation and failing pthread_mutex_unlock call.
+ * sysdeps/pthread/pthread_cond_wait.c (__condvar_cleanup): Likewise.
+ (__pthread_cond_wait): Likewise.
+
+ * sysdeps/pthread/pthread_rwlock_timedrdlock.c
+ (pthread_rwlock_timedrdlock): Fix clobber of result variable by
+ lll_futex_timed_wait call.
+ * sysdeps/pthread/pthread_rwlock_timedwrlock.c
+ (pthread_rwlock_timedwrlock): Likewise.
+
+ * sysdeps/unix/sysv/linux/s390/libc-lowlevellock.c (___lll_lock):
+ Don't define lll_unlock_wake_cb and ___lll_timedwait_tid in libc.so.
+ * sysdeps/unix/sysv/linux/s390/lowlevellock.c: Remove XXX comments.
+
+ * sysdeps/unix/sysv/linux/s390/sem_post.c (__new_sem_post): Fix
+ check of lll_futex_wake return value.
+
+2003-03-03 Roland McGrath <roland@redhat.com>
+
+ * forward.c: Fix typo in __pthread_attr_init_2_0 compat_symbol decl.
+
+ * sysdeps/pthread/pthread-functions.h (struct pthread_functions):
+ Argument to ptr___pthread_cleanup_upto is __jmp_buf, not jmp_buf.
+ * sysdeps/unix/sysv/linux/jmp-unwind.c: Likewise.
+
+2003-03-02 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/timer_create.c (timer_create): Return correct
+ error for CPU clocks.
+
+ * sysdeps/unix/sysv/linux/bits/posix_opt.h: Define
+ _POSIX_MONOTONIC_CLOCK.
+ * sysdeps/unix/sysv/linux/i386/bits/posix_opt.h: Likewise.
+
+ * tst-cancel4.c (tf_sleep): Lower sleep time a bit to not upset
+ recent kernels.
+
+2003-03-01 Ulrich Drepper <drepper@redhat.com>
+
+ * descr.h (struct pthread): Move cleanup field to the front.
+
+2003-03-01 Roland McGrath <roland@redhat.com>
+
+ * sem_open.c (sem_open): Braino fix.
+
+2003-03-01 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/i386/tcb-offsets.sym: Add CLEANUP and CLEANUP_PREV.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S: Inline
+ __pthread_cleanup_pop functionality.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Likewise.
+
+ * descr.h (struct pthread): Move tid field to the front now that
+ it is often used.
+
+ * sysdeps/unix/sysv/linux/i386/i486/libc-lowlevelmutex.S
+ (__lll_mutex_timedlock_wait): Remove.
+ (__lll_mutex_unlock_wake): Don't save, load, and restore %esi.
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelmutex.S
+ (__lll_mutex_unlock_wake): Don't save, load, and restore %esi.
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S
+ (lll_unlock_wake_cb): Don't save and restore %esi.
+ (__lll_unlock_wake): Add alignment. Don't save, load, and restore
+ %esi.
+ (__lll_timedwait_tid): Add alignment.
+ * sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S
+ (__lll_unlock_wake): Add alignment. Don't save, load, and restore
+ %esi.
+ (__lll_timedwait_tid): Removed.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_broadcast.S
+ (__pthread_cond_broadcast): Don't save, load, and restore %esi.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_barrier_wait.S
+ (pthread_barrier_wait): Don't save, load, and restore %esi for
+ last thread.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_signal.S
+ (__pthread_cond_signal): Don't save, load, and restore %esi.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_unlock.S
+ (__pthread_rwlock_unlock): Don't save, load, and restore %esi.
+ * sysdeps/unix/sysv/linux/i386/i486/sem_post.S (__new_sem_post):
+ Don't save, load, and restore %esi.
+
+2003-02-27 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_broadcast.S:
+ Release lock before waking up the waiters.
+
+ * tst-exit1.c (do_test): Don't start more than one thread in parallel.
+
+ * tst-rwlock9.c (writer_thread): Correct adding TIMEOUT.
+ (reader_thread): Likewise.
+
+ * sysdeps/pthread/pthread_rwlock_unlock.c
+ (__pthread_rwlock_unlock): Release internal lock early. Don't try
+ to wake up readers if there are none.
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_unlock.S:
+ Release internal lock before wake threads.
+
+2003-02-26 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-rwlock10 and tst-rwlock11.
+ * tst-rwlock8.c: Initialize lock with INIT. Allow INIT to be
+ predefined.
+ * tst-rwlock9.c: Likewise.
+ * tst-rwlock10.c: New file.
+ * tst-rwlock11.c: New file.
+
+ * Makefile (tests): Add tst-dlsym1.
+ * tst-dlsym1.c: New file.
+
+ * init.c (__pthread_initialize_minimal_internal): Set
+ GL(dl_error_catch_tsd) to __libc_dl_error_tsd.
+ * Versions (libc:GLIBC_PRIVATE): Export __libc_dl_error_tsd.
+
+2003-02-24 Ulrich Drepper <drepper@redhat.com>
+
+ * sem_open.c (sem_open): Fix handling of O_CREAT without O_EXCL.
+
+ * tst-cond2.c: Fix sychronization with child.
+
+ * tst-rwlock8.c (reader_thread): Remove unused variable.
+
+ * Makefile: Add rules to build and run tst-tls3.
+ * tst-tls3.c: New file.
+ * tst-tls3mod.c: New file.
+
+ * Makefile (tests): Add tst-rwlock8 and tst-rwlock9.
+ * tst-rwlock8.c: New file.
+ * tst-rwlock9.c: New file.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_rdlock.S: Fix
+ complete broken rwlock implementation.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S:
+ Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S:
+ Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_unlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_wrlock.S: Likewise.
+ * sysdeps/pthread/pthread_rwlock_rdlock.c: Likewise.
+ * sysdeps/pthread/pthread_rwlock_timedrdlock.c: Likewise.
+ * sysdeps/pthread/pthread_rwlock_timedwrlock.c: Likewise.
+ * sysdeps/pthread/pthread_rwlock_unlock.c: Likewise.
+ * sysdeps/pthread/pthread_rwlock_wrlock.c: Likewise.
+
+2003-02-23 Roland McGrath <roland@redhat.com>
+
+ * Makefile (nptl-version): Change regexp so case sensitivity is ok.
+
+2003-02-23 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-context1.
+ * tst-context1.c: New file.
+
+ * Makefile (tests): Add tst-tls1 and tst-tls2.
+ * tst-tls1.c: New file.
+ * tst-tls2.c: New file.
+
+ * libc-cancellation.c (__libc_enable_asynccancel): Correct test
+ for failed cmpxchg.
+
+ * pthread_create.c (start_thread): Set EXITING_BIT early.
+
+ * sysdeps/i386/tls.h (THREAD_GETMEM): Mark asm as volatile.
+ (THREAD_GETMEM_NC): Likewise.
+
+2003-02-22 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_barrier_wait.S: Shave
+ off 3 more bytes by using offset-less instructions when possible.
+
+ * Makefile: Add dependency for $(objpfx)version.d.
+
+ * eintr.c (eintr_source): Add unnecessary return but the compiler
+ insists.
+
+ * tst-kill3.c: Include <unistd.h>.
+
+2003-02-21 Roland McGrath <roland@redhat.com>
+
+ * pthread_create.c (start_thread): Call __libc_thread_freeres.
+
+2003-02-21 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-eintr1.
+ (distribute): Add eintr.c.
+ * tst-eintr1.c: New file.
+ * eintr.c: New file.
+
+ * pthread_cancel.c (pthread_cancel): Use tkill directly.
+
+ * sysdeps/unix/sysv/linux/pthread_kill.c (__pthread_kill):
+ Disallow sending SIGCANCEL.
+
+ * Makefile (tests): Remove tst-basic7. Add tst-kill1, tst-kill2,
+ tst-kill3, tst-kill4, tst-kill5, tst-kill6.
+ * tst-kill1.c: New file.
+ * tst-kill2.c: New file.
+ * tst-kill3.c: New file.
+ * tst-kill5.c: New file.
+ * tst-kill6.c: New file.
+ * tst-basic7.c: Renamed to...
+ * tst-kill4.c: ...this.
+
+2003-02-21 Roland McGrath <roland@redhat.com>
+
+ * Makefile (install-lib-ldscripts): New variable.
+
+2003-02-21 Ulrich Drepper <drepper@redhat.com>
+
+ * pthreadP.h: Define INVALID_TD_P and INVALID_NOT_TERMINATED_TD_P.
+ * pthread_cancel.c: Use INVALID_TD_P.
+ * pthread_detach.c: Likewise.
+ * pthread_getschedparam.c: Likewise.
+ * pthread_setschedparam.c: Likewise.
+ * sysdeps/pthread/pthread_getcpuclockid.c: Likewise.
+ * sysdeps/unix/sysv/linux/pthread_kill.c: Likewise.
+ * pthread_join.c: Use INVALID_NOT_TERMINATED_TD_P.
+ * pthread_timedjoin.c: Likewise.
+
+ * tst-basic7.c: Include <signal.h>.
+
+ * pthread_join.c (pthread_join): Limited checking for invalid
+ descriptors.
+ * pthread_timedjoin.c (pthread_timedjoin_np): Likewise.
+
+2003-02-20 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread_create.c (deallocate_tsd): Reset found_nonzero at the
+ beginning of the loop. Clear the entire first block of TSD.
+ * Makefile (tests): Add tst-key4.
+ * tst-key4.c: New file.
+
+2003-02-18 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-basic7.
+ * tst-basic7.c: New file.
+
+ * pthread_create.c (deallocate_tsd): Mark as internal_function.
+ Add some more __builtin_expect.
+
+ * pthreadP.h: Define dummy version of DEBUGGING_P.
+
+2003-02-17 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/bits/posix_opt.h: Remnove
+ _POSIX_THREAD_PRIORITY_SCHEDULING.
+ * sysdeps/unix/sysv/linux/i386/bits/posix_opt.h: Remove
+ _XOPEN_REALTIME_THREADS.
+ * sysdeps/unix/sysv/linux/bits/posix_opt.h: Likewise.
+
+ * sysdeps/unix/sysv/linux/pthread_kill.c (__pthread_kill): The
+ kernel returns EINVAL for PID <= 0, work around it.
+
+ * Makefile (tests): Add tst-signal5.
+ * tst-signal5.c: New file.
+
+ * sysdeps/unix/sysv/linux/bits/local_lim.h: Define TTY_NAME_MAX
+ and LOGIN_NAME_MAX.
+
+ * tst-cancel1.c (tf): Block all signals.
+
+ * Makefile (tests): Add tst-basic6.
+ * tst-basic6.c: New file.
+
+ * tst-basic1.c: Add test for process ID.
+
+ * Makefile (tests): Add tst-cancel10.
+ * tst-cancel10.c: New file.
+
+ * Makefile (tests): Add tst-signal4.
+ * tst-signal4.c: New file.
+
+ * sysdeps/pthread/pthread_sigmask.c (pthread_sigmask): Use
+ __sigismember instead of sigismember. Add __builtin_expect.
+
+2003-02-16 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-attr1.c (do_test): Add tests for pthread_setcanceltype,
+ pthread_setcancelstate, and pthread_rwlock_setpshared.
+
+ * tst-cancel7.c (do_test): Make sure the pid file exists before
+ canceling the thread.
+
+ * tst-rwlock6.c: More pthread_rwlock_timedwrlock and
+ pthread_rwlock_timedrdlock tests.
+ * tst-rwlock7.c: More pthread_rwlock_timedwrlock tests.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S:
+ Check for invalid tv_nsec field.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S:
+ Likewise.
+
+ * pthread_mutex_trylock.c (__pthread_mutex_trylock): Protect
+ recursive mutex of overflow.
+
+ * tst-attr1.c (do_test): Add test for pthread_mutexattr_setpshared.
+
+ * libc-cancellation.c (__libc_enable_asynccancel): Rewrite to avoid
+ going into an endless loop.
+ * Makefile (tests): Add tst-cancel9.
+ * tst-cancel9.c: New file.
+
+ * pthread_cancel.c (pthread_cancel): Use the result of __pthread_kill.
+
+2003-02-15 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-mutex5.c (do_test): Add more timedlock tests.
+
+ * tst-mutex2.c: Tests of trylock and unlock with ERROR mutexes.
+ * tst-mutex3.c (do_test): Add tests for trylock with RECURSIVE mutexes.
+
+ * sysdeps/unix/sysv/linux/pthread_kill.c (__pthread_kill): Don't
+ use INLINE_SYSCALL. Error number is returned, not -1.
+
+ * pthreadP.h: Mark declarations of __find_in_stack_list, __free_tcb,
+ and __deallocate_stack with internal_function.
+ * pthread_create.c: Adjust definitions appropriately.
+ * allocatestack.c: Likewise.
+
+ * pthread_join.c: Add one more __builtin_expect.
+ * pthread_timedjoin.c: Likewise.
+
+ * pthread_getspecific.c (__pthread_getspecific): Clear data->data
+ not data of sequence number does not match.
+ Add one __builtin_expect.
+
+ * Makefile (tests): Add tst-clock1.
+ * tst-clock1.c: New file.
+
+ * pthread_setconcurrency.c (pthread_setconcurrency): Fail for
+ negative arguments.
+ * Makefile (tests): Add tst-basic5.
+ * tst-basic5.c: New file.
+
+2003-02-14 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-basic4.
+ * tst-basic4.c: New file.
+
+ * pthreadP.h: Add declaraction for __nptl_nthreads.
+ * pthread_create.c: Define __nptl_nthreads
+ (start_thread): Increment __nptl_nthreads at beginning. Decrement
+ after thread is done. If then zero, call exit(0).
+ * sysdeps/pthread/pthread-functions.h (struct pthread_functions):
+ Add ptr_nthreads. Define HAVE_PTR_NTHREADS.
+ * init.c (pthread_functions): Initialize ptr_nthreads.
+ * allocatestack.c (nptl_nthreads): Remove definition and all uses.
+ (__reclaim_stacks): Decrement __nptl_nthreads.
+ * sysdeps/pthread/Makefile [$(subdir)==csu] (CFLAGS-libc-start.c):
+ Define.
+ * Makefile (tests): Add tst-basic3.
+ * tst-basic3.c: New file.
+
+ * descr.h: Define CANCELING_BIT and CANCELING_BITMASK. Introduce
+ after CANCELTYPE_BIT, move the other bits up. Update CANCEL_RESTMASK.
+ * init.c (sigcancel_handler): Also set CANCELING_BITMASK bit in newval.
+ * pthread_cancel.c (pthread_cancel): Likewise. Also set CANCELING_BIT
+ if asynchronous canceling is enabled.
+ * pthread_join.c (pthread_join): When recognizing circular joins,
+ take into account the other thread might be already canceled.
+ * Makefile (tests): Add tst-join5.
+ * tst-join5.c: New file.
+
+ * Makefile (tests): Add tst-join4.
+ * tst-join4.c: New file.
+
+2003-02-13 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-cond4.c (main): Add test of pthread_attr_getpshared.
+
+2003-02-13 Martin Schwidefsky <schwidefsky@de.ibm.com>
+
+ * sysdeps/s390/tls.h (THREAD_GETMEM, THREAD_GETMEM_NC, THREAD_SETMEM,
+ THREAD_SETMEM_NC): Use passed descr instead of THREAD_SELF.
+ * sysdeps/unix/sysv/linux/s390/jmp-unwind.c (_longjmp_unwind): Avoid
+ warning.
+ * sysdeps/unix/sysv/linux/s390/lowlevellock.c: Include <sys/time.h>
+ to avoid warning.
+ * sysdeps/unix/sysv/linux/s390/sem_post.c (__new_sem_post): Return
+ error if lll_futex_wake failed.
+
+2003-02-13 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S: Fix
+ handling of cancellation and failung pthread_mutex_unlock call.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Likewise.
+ * Makefile (tests): Add tst-cond8 and tst-cond9.
+ * tst-cond8.c: New file.
+ * tst-cond9.c: New file.
+
+ * tst-cond7.c (do_test): Unlock the mutex before canceling the thread.
+
+ * sysdeps/pthread/pthread.h: Add missing initializers. Protect
+ non-standard initializers with __USE_GNU.
+
+ * Makefile (tests): Add tst-cleanup3.
+ * tst-cleanup3.c: New file.
+
+2003-02-12 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-attr1 and tst-attr2.
+ * tst-attr1.c: New file.
+ * tst-attr2.c: New file.
+
+ * Makefile: Add rules to build and run tst-atfork2 test.
+ * tst-atfork2.c: New file.
+ * tst-atfork2mod.c: New file.
+
+ * sysdeps/unix/sysv/linux/unregister-atfork.c
+ (__unregister_atfork): Free the memory allocated for the handlers
+ after removing them from the lists.
+
+ * sysdeps/unix/sysv/linux/register-atfork.c: Define memeory
+ cleanup function.
+
+ * tst-atfork1.c (do_test): Wait for the child we forked.
+ Report error in child.
+
+ * sysdeps/unix/sysv/linux/fork.c (__libc_fork): Fix comment.
+
+ * sysdeps/pthread/Makefile: Define CFLAGS-confstr.c.
+
+2003-02-10 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-cancel8.
+ * tst-cancel8.c: New file.
+
+ * sysdeps/unix/sysv/linux/i386/pthread_once.S (clear_once_control): Fix
+ clearing of control variable.
+ * Makefile (tests): Add tst-once3 and tst-once4.
+ * tst-once3.c: New file.
+ * tst-once4.c: New file.
+
+2003-02-08 kaz Kojima <kkojima@rr.iij4u.or.jp>
+
+ * sysdeps/sh/Makefile: New file.
+ * sysdeps/sh/bits/atomic.h: New file.
+ * sysdeps/sh/pthread_spin_init.c: New file.
+ * sysdeps/sh/pthread_spin_lock.c: New file.
+ * sysdeps/sh/pthread_spin_trylock.S: New file.
+ * sysdeps/sh/pthread_spin_unlock.S: New file.
+ * sysdeps/sh/pthreaddef.h: New file.
+ * sysdeps/sh/tcb-offsets.sym: New file.
+ * sysdeps/sh/td_ta_map_lwp2thr.c: New file.
+ * sysdeps/sh/tls.h: New file.
+ * sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h: New file.
+ * sysdeps/unix/sysv/linux/sh/bits/semaphore.h: New file.
+ * sysdeps/unix/sysv/linux/sh/createthread.c: New file.
+ * sysdeps/unix/sysv/linux/sh/fork.c: New file.
+ * sysdeps/unix/sysv/linux/sh/libc-lowlevellock.S: New file.
+ * sysdeps/unix/sysv/linux/sh/libc-lowlevelmutex.S: New file.
+ * sysdeps/unix/sysv/linux/sh/lowlevel-atomic.h: New file.
+ * sysdeps/unix/sysv/linux/sh/lowlevelcond.h: New file.
+ * sysdeps/unix/sysv/linux/sh/lowlevellock.S: New file.
+ * sysdeps/unix/sysv/linux/sh/lowlevellock.h: New file.
+ * sysdeps/unix/sysv/linux/sh/lowlevelmutex.S: New file.
+ * sysdeps/unix/sysv/linux/sh/lowlevelrwlock.h: New file.
+ * sysdeps/unix/sysv/linux/sh/pt-initfini.c: New file.
+ * sysdeps/unix/sysv/linux/sh/pt-vfork.S: New file.
+ * sysdeps/unix/sysv/linux/sh/pthread_barrier_wait.S: New file.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_broadcast.S: New file.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_signal.S: New file.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_timedwait.S: New file.
+ * sysdeps/unix/sysv/linux/sh/pthread_cond_wait.S: New file.
+ * sysdeps/unix/sysv/linux/sh/pthread_once.S: New file.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_rdlock.S: New file.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedrdlock.S: New file.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedwrlock.S: New file.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_unlock.S: New file.
+ * sysdeps/unix/sysv/linux/sh/pthread_rwlock_wrlock.S: New file.
+ * sysdeps/unix/sysv/linux/sh/sem_post.S: New file.
+ * sysdeps/unix/sysv/linux/sh/sem_timedwait.S: New file.
+ * sysdeps/unix/sysv/linux/sh/sem_trywait.S: New file.
+ * sysdeps/unix/sysv/linux/sh/sem_wait.S: New file.
+ * sysdeps/unix/sysv/linux/sh/sysdep-cancel.h: New file.
+
+2003-02-08 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-cond2.c: Rearrange code to not rely on behavior undefined
+ according to POSIX.
+
+ * tst-basic2.c (do_test): Lock mutex before creating the thread.
+
+2003-02-07 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/x86_64/tls.h: Remove unnecessary macros, left over from x86.
+ (TLS_GET_FS): New #define.
+ (TLS_SET_FS): New #define.
+ Correct value of __NR_set_thread_area.
+
+ * sysdeps/x86_64/td_ta_map_lwp2thr.c: New file.
+
+2003-02-06 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-popen1.
+ * tst-popen1.c: New file.
+
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S: Remove wrong
+ but inactive generalization.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_signal.S: Likewise.
+ Minor optimization, remove one instruction.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_broadcast.S: Likewise.
+
+2003-02-04 Martin Schwidefsky <schwidefsky@de.ibm.com>
+
+ * sysdeps/unix/sysv/linux/s390/fork.c: Correct order of parameters.
+
+2003-01-31 Martin Schwidefsky <schwidefsky@de.ibm.com>
+
+ * init.c (__NR_set_tid_address): Add #ifdef for s390.
+ * sysdeps/pthread/pthread_barrier_wait.c: New file.
+ * sysdeps/pthread/pthread_cond_broadcast.c: New file.
+ * sysdeps/pthread/pthread_cond_signal.c: New file.
+ * sysdeps/pthread/pthread_cond_timedwait.c: New file.
+ * sysdeps/pthread/pthread_cond_wait.c: New file.
+ * sysdeps/pthread/pthread_rwlock_rdlock.c: New file.
+ * sysdeps/pthread/pthread_rwlock_timedrdlock.c: New file.
+ * sysdeps/pthread/pthread_rwlock_timedwrlock.c: New file.
+ * sysdeps/pthread/pthread_rwlock_unlock.c: New file.
+ * sysdeps/pthread/pthread_rwlock_wrlock.c: New file.
+ * sysdeps/s390/Makefile: New file.
+ * sysdeps/s390/bits/atomic.h: New file.
+ * sysdeps/s390/pthread_spin_init.c: New file.
+ * sysdeps/s390/pthread_spin_lock.c: New file.
+ * sysdeps/s390/pthread_spin_trylock.c: New file.
+ * sysdeps/s390/pthread_spin_unlock.c: New file.
+ * sysdeps/s390/pthreaddef.h: New file.
+ * sysdeps/s390/tcb-offsets.sym: New file.
+ * sysdeps/s390/td_ta_map_lwp2thr.c: New file.
+ * sysdeps/s390/tls.h: New file.
+ * sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h: New file.
+ * sysdeps/unix/sysv/linux/s390/bits/semaphore.h: New file.
+ * sysdeps/unix/sysv/linux/s390/createthread.c: New file.
+ * sysdeps/unix/sysv/linux/s390/dl-sysdep.h: New file.
+ * sysdeps/unix/sysv/linux/s390/fork.c: New file.
+ * sysdeps/unix/sysv/linux/s390/jmp-unwind.c: New file.
+ * sysdeps/unix/sysv/linux/s390/libc-lowlevellock.c: New file.
+ * sysdeps/unix/sysv/linux/s390/libc-lowlevelmutex.c: New file.
+ * sysdeps/unix/sysv/linux/s390/lowlevellock.c: New file.
+ * sysdeps/unix/sysv/linux/s390/lowlevellock.h: New file.
+ * sysdeps/unix/sysv/linux/s390/lowlevelmutex.c: New file.
+ * sysdeps/unix/sysv/linux/s390/lowlevelsem.h: New file.
+ * sysdeps/unix/sysv/linux/s390/pthread_once.c: New file.
+ * sysdeps/unix/sysv/linux/s390/s390-32/pt-initfini.c: New file.
+ * sysdeps/unix/sysv/linux/s390/s390-32/pt-vfork.S: New file.
+ * sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h: New file.
+ * sysdeps/unix/sysv/linux/s390/s390-64/pt-initfini.c: New file.
+ * sysdeps/unix/sysv/linux/s390/s390-64/pt-vfork.S: New file.
+ * sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h: New file.
+ * sysdeps/unix/sysv/linux/s390/sem_post.c: New file.
+ * sysdeps/unix/sysv/linux/s390/sem_timedwait.c: New file.
+ * sysdeps/unix/sysv/linux/s390/libc-lowlevellock.c: New file.
+ * sysdeps/unix/sysv/linux/s390/sem_wait.c: New file.
+
+2003-02-04 Ulrich Drepper <drepper@redhat.com>
+
+ * atomic.h: Add a couple more default implementations.
+ (atomic_compare_and_exchange_acq): Use
+ __arch_compare_and_exchange_32_acq in return value definition. It
+ always exists.
+ (atomic_bit_set): Renamed from atomic_set_bit.
+ Add missing atomic_ prefixes.
+
+ * sysdeps/pthread/bits/libc-lock.h (__libc_once): In case no
+ thread library is available, use correct value to mark initialized
+ once variable.
+
+2003-02-03 Ulrich Drepper <drepper@redhat.com>
+
+ * allocatestack.c (allocate_stack): Use __getpagesize instead of
+ __sysconf to determine pagesize.
+
+ * pthread_create.c: Include <atomic.h>.
+ * allocatestack.c (allocate_stack): Implement coloring of the
+ allocated stack memory. Rename pagesize to pagesize_m1. It's the
+ size minus one. Adjust users.
+ * sysdeps/i386/i686/Makefile: New file.
+
+2003-02-02 Ulrich Drepper <drepper@redhat.com>
+
+ * allocatestack.c: Improve comment throughout the file.
+
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S
+ (__lll_lock_wait): Add branch prediction.
+ * sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S
+ (__lll_lock_wait): Likewise.
+ (lll_unlock_wake_cb): Removed.
+
+2003-01-31 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/bits/posix_opt.h: Remove
+ _POSIX_THREAD_PRIORITY_SCHEDULING.
+
+2003-01-30 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/pthread/pthread-functions.h (struct pthread_functions):
+ Fix return type of ptr___pthread_getspecific.
+
+2003-01-29 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-umask1.
+ (tst-umask1-ARGS): Define.
+ * tst-umask1.c: New file.
+
+2003-01-28 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (libpthread-routines): Remove lowlevelrwlock. Add
+ pthread_rwlock_rdlock, pthread_rwlock_timedrdlock,
+ pthread_rwlock_wrlock, pthread_rwlock_timedwrlock, and
+ pthread_rwlock_unlock.
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelrwlock.S: Removed
+ * sysdeps/unix/sysv/linux/i386/i586/lowlevelrwlock.S: Removed
+ * sysdeps/unix/sysv/linux/i386/i686/lowlevelrwlock.S: Removed
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_rdlock.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S:
+ New file.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_wrlock.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S:
+ New file.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_unlock.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_rdlock.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_timedrdlock.S:
+ New file.
+ * sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_wrlock.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_timedwrlock.S:
+ New file.
+ * sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_unlock.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_rdlock.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_timedrdlock.S:
+ New file.
+ * sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_wrlock.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_timedwrlock.S:
+ New file.
+ * sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_unlock.S: New file.
+
+ * Makefile (libpthread-routines): Remove lowlevelcond and
+ lowlevelsem. Add sem_wait, sem_trywait, sem_timedwait, sem_post,
+ pthread_cond_wait, pthread_cond_timedwait, pthread_cond_signal,
+ and pthread_cond_broadcast.
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelsem.S: Removed
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelcond.S: Removed
+ * sysdeps/unix/sysv/linux/i386/i586/lowlevelsem.S: Removed
+ * sysdeps/unix/sysv/linux/i386/i586/lowlevelcond.S: Removed
+ * sysdeps/unix/sysv/linux/i386/i686/lowlevelsem.S: Removed
+ * sysdeps/unix/sysv/linux/i386/i686/lowlevelcond.S: Removed
+ * sysdeps/unix/sysv/linux/i386/i486/sem_wait.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i486/sem_trywait.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i486/sem_timedwait.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i486/sem_post.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_signal.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_broadcast.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i586/sem_wait.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i586/sem_trywait.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i586/sem_timedwait.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i586/sem_post.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i586/pthread_cond_wait.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i586/pthread_cond_timedwait.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i586/pthread_cond_signal.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i586/pthread_cond_broadcast.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i686/sem_wait.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i686/sem_trywait.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i686/sem_timedwait.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i686/sem_post.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i686/pthread_cond_wait.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i686/pthread_cond_timedwait.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i686/pthread_cond_signal.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i686/pthread_cond_broadcast.S: New file.
+ * sysdeps/unix/sysv/linux/i386/lowlevelcond.h: New file.
+
+ * sysdeps/unix/sysv/linux/i386/createthread.c: Define
+ PREPARE_CREATE and TLS_VALUE with x86-specific bits. All the rest
+ of the code is moved to ...
+ * sysdeps/pthread/createthread.c: ...here. New file.
+
+2003-01-27 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelsem.S
+ (__new_sem_post): Clear %eax before returning.
+ Reported by MAEDA Naoaki <maeda.naoaki@jp.fujitsu.com>.
+
+ * Makefile (tests): Add tst-cleanup2.
+ * tst-cleanup2.c: New file.
+
+ * sysdeps/pthread/bits/libc-lock.h (__libc_cleanup_region_start):
+ Interpret first parameter correctly.
+
+2003-01-17 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (headers): Add bits/semaphore.h.
+
+2003-01-16 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/i386/tls.h (INIT_SYSINFO): Initialize _head->sysinfo even
+ if not SHARED.
+
+2003-01-14 Ulrich Drepper <drepper@redhat.com>
+
+ * sem_open.c (sem_open): Return SEM_FAILED if existing semaphore
+ must be used and mapping failed.
+ Reported by Luke Elliott <luke.elliott@activfinancial.com>.
+
+ * Makefile (CFLAGS-pthread_self.os): Define this, not
+ CFLAGS-pthread_self.c.
+
+2003-01-13 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S: Don't export
+ lll_unlock_wake_cb.
+
+ * Makefile (libpthread-routines): Add version. Add rules to build
+ version.os and banner.h.
+ * version.c: New file.
+
+2003-01-13 Jakub Jelinek <jakub@redhat.com>
+
+ * pthread_mutex_lock.c (__pthread_mutex_lock_internal): Make
+ the alias unconditional.
+ * pthread_mutex_unlock.c (__pthread_mutex_unlock_internal): Likewise.
+
+2003-01-13 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (CFLAGS-pthread_self.c): New definition.
+
+2003-01-06 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/pthread/pthread_sigmask.c (pthread_sigmask): Add
+ INTERNAL_SYSCALL_DECL, add err argument to INTERNAL_SYSCALL* macros.
+ * sysdeps/unix/sysv/linux/raise.c (raise): Likewise.
+ * init.c (__pthread_initialize_minimal_internal): Likewise.
+
+2003-01-07 Jakub Jelinek <jakub@redhat.com>
+
+ * pthreadP.h (__pthread_cond_timedwait): Add prototype.
+
+ * sysdeps/unix/sysv/linux/i386/dl-sysdep.h
+ (RTLD_CORRECT_DYNAMIC_WEAK): Remove.
+ (DL_SYSINFO_IMPLEMENTATION): Change into .text section and back.
+ * sysdeps/unix/sysv/linux/i386/i686/dl-sysdep.h
+ (RTLD_CORRECT_DYNAMIC_WEAK): Remove.
+ (DL_SYSINFO_IMPLEMENTATION): Change into .text section and back.
+
+2003-01-06 Jakub Jelinek <jakub@redhat.com>
+
+ * pthreadP.h (LIBC_CANCEL_HANDLED): Define.
+ * pt-system.c (LIBC_CANCEL_HANDLED): Add.
+ * tst-cancel-wrappers.sh: Remove all exceptions.
+
+2003-01-05 Ulrich Drepper <drepper@redhat.com>
+
+ * tst-cancel-wrappers.sh: Invoke gawk not awk since we use GNU awk
+ features. Reported by Marijn Ros <marijn@mad.scientist.com>.
+
+ * sysdeps/unix/sysv/linux/jmp-unwind.c: Include <pthread-functions.h>.
+ Use __libc_pthread_functions array if SHARED.
+
+ * pthreadP.h: Move pthread_cond_2_0_t definition to...
+ * sysdeps/unix/sysv/linux/internaltypes.h: ...here.
+
+ * sysdeps/pthread/bits/libc-lock.h (__libc_ptf_call): New #define.
+ (__libc_rwlock_rdlock, __libc_rwlock_wrlock, __libc_rwlock_unlock,
+ __libc_key_create, __libc_getspecific, __libc_setspecific): Use
+ __libc_ptf_call instead of __libc_maybe_call.
+ (PTF): New #define.
+ (__libc_cleanup_region_start): Wrap function name with PTF call.
+ (__libc_cleanup_region_end): Likewise.
+ (__libc_cleanup_end): Likewise.
+
+ * pthread_getspecific.c: Add __pthread_getspecific_internal alias.
+ * pthread_setspecific.c: Add __pthread_setspecific_internal alias.
+ * pthread_key_create.c: Add __pthread_key_create_internal alias.
+ * pthreadP.h: Add prototypes.
+
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelrwlock.S: Add
+ __pthread_rwlock_rdlock, __pthread_rwlock_wrlock, and
+ __pthread_rwlock_unlock aliases.
+ * pthreadP.h: Add prototypes for new aliases.
+
+ * pthreadP.h (struct pthead_functions): Moved to...
+ * sysdeps/pthread/pthread-functions.h: ...here. New file.
+ * init.c (pthread_functions): Add initializers for new elements.
+
+ * cleanup_defer.c: Add __pthread_cleanup_push_defer and
+ __pthread_cleanup_pop_restore aliases.
+ * pthreadP.h: Add prototypes.
+
+ * cleanup.c: Rename _GI_pthread_cleanup_push to __pthread_cleanup_push
+ and _GI_pthread_cleanup_pop to __pthread_cleanup_pop.
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelcond.S: Adjust caller.
+ * sysdeps/unix/sysv/linux/i386/pthread_once.S: Likewise.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_once.S: Likewise.
+ * pthreadP.h: Adjust prototypes and callers.
+
+2003-01-04 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-cancel7.
+ (tst-cancel7-ARGS): New variable.
+ * tst-cancel7.c: New file.
+
+ * old_pthread_cond_broadcast.c: Optimize initialization a bit to work
+ around gcc defficiencies.
+ * old_pthread_cond_signal.c: Likewise.
+ * old_pthread_cond_timedwait.c: Likewise.
+ * old_pthread_cond_wait.c: Likewise.
+
+ * pthreadP.h (pthread_cond_2_0_t): Remove unneeded lock element.
+
+2003-01-03 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-cond7.
+ * tst-cond7.c: New file.
+
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelcond.S
+ (condvar_cleanup): Get condvar address from the right place.
+
+ * atomic.h: Correct definitions of atomic_full_barrier,
+ atomic_read_barrier, atomic_write_barrier.
+
+ * old_pthread_cond_broadcast.c: Make memory allocate and initialization
+ race-free.
+ * old_pthread_cond_signal.c: Likewise.
+ * old_pthread_cond_timedwait.c: Likewise.
+ * old_pthread_cond_wait.c: Likewise.
+
+2003-01-03 Jakub Jelinek <jakub@redhat.com>
+
+ * Makefile ($(objpfx)libpthread.so): Depend on ld.so.
+
+2003-01-03 Ulrich Drepper <drepper@redhat.com>
+
+ * pthreadP.h (pthread_cond_2_0_t): New type.
+ (struct pthread_functions): Use new type for 2.0 condvar callbacks.
+ Use new type for the 2.0 condvar function prototypes.
+ * forward.c: Use pthread_cond_2_0_t for 2.0 condvar functions.
+ * old_pthread_cond_init.c: Use pthread_cond_2_0_t for condvar
+ parameter.
+ * old_pthread_cond_destroy.c: Likewise.
+ * old_pthread_cond_broadcast.c: Likewise. Lock appropriately.
+ * old_pthread_cond_signal.c: Likewise.
+ * old_pthread_cond_timedwait.c: Likewise.
+ * old_pthread_cond_wait.c: Likewise.
+
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelcond.S
+ (__pthread_cond_wait): Don't save cancellation mode and seq value
+ in same location.
+
+ * herrno.c (__h_errno_location): Don't define as weak.
+
+2003-01-02 Jakub Jelinek <jakub@redhat.com>
+
+ * Versions [libc] (GLIBC_2.3.2): Export pthread_cond_broadcast,
+ pthread_cond_destroy, pthread_cond_init, pthread_cond_signal
+ and pthread_cond_wait.
+ * old_pthread_cond_broadcast.c (__old_pthread_cond_broadcast):
+ Renamed to...
+ (__pthread_cond_broadcast_2_0): ... this.
+ * old_pthread_cond_destroy.c (__old_pthread_cond_destroy):
+ Renamed to...
+ (__pthread_cond_destroy_2_0): ... this.
+ * old_pthread_cond_init.c (__old_pthread_cond_init):
+ Renamed to...
+ (__pthread_cond_init_2_0): ... this.
+ * old_pthread_cond_signal.c (__old_pthread_cond_signal):
+ Renamed to...
+ (__pthread_cond_signal_2_0): ... this.
+ * old_pthread_cond_wait.c (__old_pthread_cond_wait):
+ Renamed to...
+ (__pthread_cond_wait_2_0): ... this.
+ * pthread_cond_destroy.c: Include shlib-compat.h.
+ (pthread_cond_destroy): Change strong_alias into versioned_symbol.
+ * pthread_cond_init.c: Include shlib-compat.h.
+ (pthread_cond_init): Change strong_alias into versioned_symbol.
+ * pthreadP.h (struct pthread_functions): Rename ptr_pthread_cond_*
+ fields to ptr___pthread_cond_* and add ptr___pthread_cond_*_2_0
+ fields.
+ (__pthread_cond_broadcast_2_0, __pthread_cond_destroy_2_0,
+ __pthread_cond_init_2_0, __pthread_cond_signal_2_0,
+ __pthread_cond_wait_2_0): New prototypes.
+ (__old_pthread_cond_broadcast, __old_pthread_cond_destroy,
+ __old_pthread_cond_init, __old_pthread_cond_signal,
+ __old_pthread_cond_wait): Removed.
+ * init.c: Include shlib-compat.h.
+ (pthread_functions): Guard ptr___pthread_attr_init_2_0
+ initialization with SHLIB_COMPAT (GLIBC_2_0, GLIBC_2_1).
+ Rename ptr_pthread_cond_* to ptr___pthread_cond_*, initialize
+ ptr___pthread_cond_*_2_0 fields.
+ * forward.c: Export both pthread_cond_*@@GLIBC_2.3.2 and
+ pthread_cond_*@GLIBC_2.0 compatibility symbols.
+
+ * sysdeps/pthread/sigaction.c (SIGCANCEL): Only define if
+ LIBC_SIGACTION was not yet defined.
+ [!defined LIBC_SIGACTION]: Define LIBC_SIGACTION, #include self.
+ [!defined LIBC_SIGACTION] (__sigaction): New function and
+ libc_hidden_weak.
+ [!defined LIBC_SIGACTION] (sigaction): New weak_alias.
+ [defined LIBC_SIGACTION]: #include_next <sigaction.c>.
+
+2003-01-02 Jakub Jelinek <jakub@redhat.com>
+
+ * Makefile (CFLAGS-pthread_atfork.c): Add -DNOT_IN_libc.
+
+2003-01-02 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h (pthread_cond_t):
+ New, larger type definition.
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelcond.S: New condvar
+ implementation.
+ * Versions [libpthread]: Add definitions for new pthread_cond_*
+ interfaces for version GLIBC_2.3.2.
+ * pthread_cond_init.c: Update initialization for new type definition.
+ * Makefile (libpthread-routines): Remove pthread_cond_wait,
+ pthread_cond_timedwait, pthread_cond_signal, and
+ pthread_cond_broadcast. Add old_pthread_cond_init,
+ old_pthread_cond_destroy, old_pthread_cond_wait,
+ old_pthread_cond_timedwait, old_pthread_cond_signal, and
+ old_pthread_cond_broadcast.
+ * old_pthread_cond_broadcast.c: New file.
+ * old_pthread_cond_destroy.c: New file.
+ * old_pthread_cond_init.c: New file.
+ * old_pthread_cond_signal.c: New file.
+ * old_pthread_cond_timedwait.c: New file.
+ * old_pthread_cond_wait.c: New file.
+ * pthreadP.h: Add prototypes for the compatibility interfaces.
+
+ * pthread_cond_destroy.c: Don't include <errno.h>.
+
+2003-01-01 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelrwlock.S: Avoid
+ unnecessary zero offset when addressing MUTEX.
+
+2002-12-31 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/fork.h: Add libc_hidden_proto for
+ __register_atfork.
+ * sysdeps/unix/sysv/linux/register-atfork.c: Add libc_hidden_def
+ for __register_atfork.
+
+2002-12-31 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/sysdep-cancel.h: Use __ASSEMBLER__
+ instead of ASSEMBLER test macro.
+
+ * sysdeps/unix/sysv/linux/allocrtsig.c (__libc_current_sigrtmin,
+ __libc_current_sigrtmax): Add libc_hidden_def.
+
+ * sysdeps/pthread/list.h: Remove assert.h include.
+
+2002-12-31 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/pt-initfini.c (call_initialize_minimal): Use
+ __pthread_initialize_minimal_internal not
+ __pthread_initialize_minimal.
+
+2002-12-30 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/pt-initfini.c (call_initialize_minimal): Mark
+ __pthread_initialize_minimal as hidden.
+
+ * init.c (__pthread_initialize_minimal_internal): Don't mark as
+ constructor.
+
+2002-12-31 Jakub Jelinek <jakub@redhat.com>
+
+ * Makefile ($(inst_libdir)/libpthread.so): Depend on
+ $(common-objpfx)format.lds, include that into the output script.
+ Fix comment.
+ (extra-B-pthread.so): Change linuxthreads/ into nptl/.
+
+2002-12-28 Andreas Jaeger <aj@suse.de>
+
+ * sysdeps/unix/sysv/linux/xstatconv.c (xstat_conv): Adjust for
+ nsec resolution changes.
+ (xstat64_conv): Likewise.
+ (xstat32_conv): Likewise.
+ * sysdeps/unix/sysv/linux/kernel_stat.h: Add nsec resolution for
+ struct kernel_stat.
+ * sysdeps/unix/sysv/linux/bits/stat.h: Add nsec resolution for
+ structs stat and stat64.
+ * time/time.h (__timespec_defined): Define for __USE_MISC.
+ * io/sys/stat.h [__USE_MISC]: Define __need_timespec for struct stat.
+
+2002-12-30 Jakub Jelinek <jakub@redhat.com>
+
+ * forward.c (FORWARD2): Renamed from FORWARD3. Remove unused export
+ argument.
+ (pthread_attr_init_2_0, pthread_attr_init_2_1): Use FORWARD macro.
+ (pthread_exit): Use strong_alias to avoid warnings.
+ * pthreadP.h (struct pthread_functions): Rename ptr_pthread_exit
+ and ptr_pthread_attr_init_2_* to ptr___pthread_exit and
+ ptr___pthread_attr_init_2_*.
+ * init.c (pthread_functions): Adjust.
+
+2002-12-29 Ulrich Drepper <drepper@redhat.com>
+
+ * forward.c: Make all functions available by default again. It
+ caused too much trouble.
+
+ * pt-siglongjmp.c: Removed.
+
+2002-12-28 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/i386/tls.h: Include tcb-offsets.h in assembler.
+ (SYSINFO_OFFSET, MULTIPLE_THREADS_OFFSET): Remove.
+ * sysdeps/i386/Makefile: New file.
+ * sysdeps/i386/tcb-offsets.sym: New file.
+ * sysdeps/pthread/tcb-offsets.h: New file.
+ * sysdeps/unix/sysv/linux/libc_pthread_init.c (__libc_pthread_init):
+ Remove MULTIPLE_THREADS_OFFSET and SYSINFO_OFFSET checks.
+
+ * sysdeps/unix/sysv/linux/Versions [libc] (GLIBC_PRIVATE): Move
+ __register_atfork...
+ (GLIBC_2.3.2): ...here.
+
+2002-12-28 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/pthread.h: Mark pthread_attr_getstackaddr and
+ pthread_attr_setstackaddr with __attribute_deprecated__.
+
+2002-12-27 Jakub Jelinek <jakub@redhat.com>
+
+ * pt-system.c (system): Remove cancellation handling.
+ * tst-cancel-wrappers.sh: Allow pt-system.o* to not use the
+ cancellation routines.
+
+2002-12-28 Ulrich Drepper <drepper@redhat.com>
+
+ * descr.h: Include <dl-sysdep.h>.
+ (struct pthread): Move header.data.list to the back of the struct.
+ * sysdeps/i386/tls.h (tcbhead_t): Move list to the back of the struct.
+ (MULTIPLE_THREADS_OFFSET): Adjust offset.
+ (SYSINFO_OFFSEET): Likewise.
+
+2002-12-27 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i686/dl-sysdep.h (USE_DL_SYSINFO):
+ Define.
+ (DL_SYSINFO_DEFAULT): Cast to uintptr_t to avoid warnings.
+ * sysdeps/unix/sysv/linux/i386/dl-sysdep.h (NEED_DL_SYSINFO,
+ DL_SYSINFO_DEFAULT, DL_SYSINFO_IMPLEMENTATION): Define.
+ (USE_DL_SYSINFO): Undef.
+
+2002-12-22 Jakub Jelinek <jakub@redhat.com>
+
+ * Makefile (tests-reverse): Use $(objpfx)../libc.so instead of
+ $(common-objpfx)libc.so.
+ * tst-cancel4.c (tf_write, tf_writev): Increase buf sizes so that
+ it is bigger than pipe buffer size even on arches with bigger
+ page size.
+ (tf_usleep): Cast usleep argument to useconds_t to avoid warnings.
+
+2002-12-25 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelsem.S: Implement
+ correct errno access for case that USE___THREAD is not defined.
+
+2002-12-24 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/dl-sysdep.h: Add missing #endif.
+ Patch by Marijn Ros <marijn@mad.scientist.com>.
+
+2002-12-22 Roland McGrath <roland@redhat.com>
+
+ * Makefile (omit-deps): Add $(unix-syscalls:%=ptw-%).
+
+2002-12-20 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/bits/stdio-lock.h (_IO_lock_inexpensive): Define.
+
+2002-12-19 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/dl-sysdep.h: Don't define
+ NEED_DL_SYSINFO since no processor < i686 had the sysenter opcode.
+ * sysdeps/unix/sysv/linux/i386/i686/dl-sysdep.h: New file.
+
+ * sysdeps/unix/sysv/linux/i386/pthread_once.S: Use ENTER_KERNEL instead
+ of int $0x80.
+ * sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/libc-lowlevelmutex.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelcond.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelmutex.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelrwlock.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelsem.S: Likewise.
+ * sysdeps/unix/sysv/linux/i386/i486/pthread_barrier_wait.S: Likewise.
+
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h: Add support for using
+ sysenter.
+ * sysdeps/unix/sysv/linux/i386/lowlevelsem.h: Likewise.
+
+ * sysdeps/i386/tls.h: Unconditionally include <dl-sysdep.h>.
+
+ * allocatestack.c (allocate_stack) [NEED_DL_SYSINFO]: Set sysinfo
+ in new TCB.
+ * sysdeps/unix/sysv/linux/i386/createthread.c (create_thread): Check
+ that sysinfo is properly initialized.
+ * sysdeps/unix/sysv/linux/i386/dl-sysdep.h: Define RTLD_PRIVATE_ERRNO
+ to 1 only for ld.so.
+
+ * sysdeps/unix/sysv/linux/i386/dl-sysdep.h: Define
+ RTLD_CORRECT_DYNAMIC_WEAK.
+
+2002-12-19 Jakub Jelinek <jakub@redhat.com>
+
+ * forward.c (pthread_attr_init_2_0, pthread_attr_init_2_1):
+ Use return 0 as 6th argument to FORWARD4.
+ * pthread_equal.c: Include pthreadP.h instead of pthread.h.
+
+2002-12-18 Ulrich Drepper <drepper@redhat.com>
+
+ * descr.h (struct pthread) [NEED_DL_SYSINFO]: Add sysinfo member.
+ * sysdeps/i386/tls.h (tcbhead_t): Add sysinfo member.
+ Define SYSINFO_OFFSEET if NEED_DL_SYSINFO is defined.
+ (INIT_SYSINFO): New #define.
+ (TLS_TP_INIT): Use INIT_SYSINFO.
+ * sysdeps/unix/sysv/linux/libc_pthread_init.c (__libc_pthread_init):
+ At test to make sure SYSINFO_OFFSET value is correct.
+ * sysdeps/unix/sysv/linux/i386/dl-sysdep.h: New file.
+
+2002-12-18 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/pthread/flockfile.c (flockfile): Change into weak alias.
+ * sysdeps/unix/sysv/linux/raise.c (gsignal): Add weak alias to raise.
+ * Versions [libc: GLIBC_2.0]: Add pthread_attr_init.
+ [libpthread: GLIBC_2.1]: Remove __pthread_rwlock_init,
+ __pthread_rwlock_destroy, __pthread_rwlock_rdlock,
+ __pthread_rwlock_wrlock, __pthread_rwlock_unlock,
+ __pthread_rwlock_tryrdlock and __pthread_rwlock_trywrlock.
+
+2002-12-18 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/sysdep-cancel.h: Use ENTER_KERNEL
+ macro instead of using int $0x80 directly.
+
+ * sysdeps/pthread/bits/stdio-lock.h: New file.
+ * sysdeps/unix/sysv/linux/i386/i486/libc-lowlevelmutex.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i586/libc-lowlevelmutex.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i686/libc-lowlevelmutex.S: New file.
+ * Makefile (routines): Add libc-lowlevelmutex.
+
+ * sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S: Remove
+ __i686.get_pc_thunk.dx.
+
+2002-12-17 Jakub Jelinek <jakub@redhat.com>
+
+ * Makefile (libpthread-shared-only-routines): Add pt-allocrtsig.
+ (tests): Depend on $(objpfx)tst-cancel-wrappers.out.
+ ($(objpfx)tst-cancel-wrappers.out): New rule.
+ * tst-cancel-wrappers.sh: New test.
+ * tst-locale1.c: Include signal.h.
+ (uselocale): Test static linking of __libc_current_sigrt*.
+
+2002-12-17 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-cancel6.
+ * tst-cancel6.c: New file
+
+2002-12-17 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/sysdep-cancel.h (SINGLE_THREAD_P):
+ Define meaningfully for assembler as well.
+ * pthreadP.h (struct pthread_functions): Remove
+ ptr_pthread_attr_init field. Add ptr_pthread_attr_init_2_0
+ and ptr_pthread_attr_init_2_1 fields.
+ * init.c (pthread_functions): Initialize ptr_pthread_attr_init_2_0
+ and ptr_pthread_attr_init_2_1 instead of ptr_pthread_attr_init.
+ * forward.c (FORWARD4): Renamed from FORWARD3. Add export argument.
+ (FORWARD3): Define using FORWARD4.
+ (pthread_attr_init): Provide both @GLIBC_2.0 and @@GLIBC_2.1
+ versions.
+ * pt-system.c: Remove duplicate stdlib.h include.
+
+2002-12-16 Ulrich Drepper <drepper@redhat.com>
+
+ * sem_init.c: Define sem_init@GLIBC_2.0.
+ * sem_destroy.c: Define sem_destroy@GLIBC_2.0.
+ * sem_getvalue.c: Define sem_getvalue@GLIBC_2.0.
+
+ * flockfile.c: Moved to...
+ * sysdeps/pthread/flockfile.c: ...here. New file.
+ * funlockfile.c: Moved to...
+ * sysdeps/pthread/funlockfile.c: ...here. New file.
+ * ftrylockfile.c: Moved to...
+ * sysdeps/pthread/ftrylockfile.c: ...here. New file.
+
+2002-12-16 Jakub Jelinek <jakub@redhat.com>
+
+ * libc-cancellation.c: Guard both function with
+ #if !defined NOT_IN_libc.
+ * Makefile (libpthread-routines): Use ptw-, not pt- prefix for the
+ automatically provided pthread wrappers.
+ * pthreadP.h (LIBC_CANCEL_ASYNC, LIBC_CANCEL_RESET): Define to
+ CANCEL_* if IS_IN_libpthread and to dummy versions if not in libc
+ nor in libpthread.
+ * pt-open.c: Removed.
+ * pt-fcntl.c: Removed.
+ * pt-fsync.c: Removed.
+ * pt-lseek.c: Removed.
+ * pt-msgrcv.c: Removed.
+ * pt-msgsnd.c: Removed.
+ * pt-msync.c: Removed.
+ * pt-nanosleep.c: Removed.
+ * pt-open64.c: Removed.
+ * pt-pause.c: Removed.
+ * pt-pread.c: Removed.
+ * pt-pread64.c: Removed.
+ * pt-pwrite.c: Removed.
+ * pt-pwrite64.c: Removed.
+ * pt-read.c: Removed.
+ * pt-recv.c: Removed.
+ * pt-recvfrom.c: Removed.
+ * pt-recvmsg.c: Removed.
+ * pt-send.c: Removed.
+ * pt-sendto.c: Removed.
+ * pt-sigtimedwait.c: Removed.
+ * pt-sigwait.c: Removed.
+ * pt-wait.c: Removed.
+ * pt-waitpid.c: Removed.
+ * pt-write.c: Removed.
+ * pt-accept.c: Removed.
+ * pt-close.c: Removed.
+ * pt-connect.c: Removed.
+ * pt-lseek64.c: Removed.
+ * pt-sendmsg.c: Removed.
+ * pt-tcdrain.c: Removed.
+
+2002-12-15 Ulrich Drepper <drepper@redhat.com>
+
+ * init.c (__pthread_initialize_minimal_internal): Renamed from
+ __pthread_initialize_minimal. Make old name an alias. This
+ converts a normal relocation into a relative relocation.
+
+ * pt-fcntl.c (__fcntl): Use fcntl64 syscall, not fcntl.
+
+ * Versions [libpthread: GLIBC_2.3.2]: Remove creat, poll, pselect,
+ readv, select, sigpause, sigsuspend, sigwaitinfo, waitid, writev.
+ * Makefile (libpthread-routines): Remove pt-creat, pt-poll,
+ pt-pselect, pt-readv, pt-select, pt-sigpause, pt-sigsuspend,
+ pt-sigwaitinfo, pt-waitid, and pt-writev.
+ * pt-creat.c: Removed.
+ * pt-poll.c: Removed.
+ * pt-pselect.c: Removed.
+ * pt-readv.c: Removed.
+ * pt-select.c: Removed.
+ * pt-sigpause.c: Removed.
+ * pt-sigsuspend.c: Removed.
+ * pt-sigwaitinfo.c: Removed.
+ * pt-waitid.c: Removed.
+ * pt-writev.c: Removed.
+
+ * init.c (pthread_functions): New variable.
+ (__pthread_initialize_minimal): Pass pointer to pthread_functions
+ (or NULL) to __libc_pthread_init.
+ * forward.c: Rewrite to use __libc:pthread_functions array to get
+ function addresses.
+ * sysdeps/unix/sysv/linux/fork.h: Remove __libc_pthread_init
+ prototype.
+ * sysdeps/unix/sysv/linux/libc_pthread_init.c (__libc_pthread_init):
+ Take new parameter. Copy content of variable pointed to by it
+ to __libc_pthread_init.
+
+ * pthreadP.h (struct pthread_functions): New type.
+ (__libc_pthread_init): Declare.
+
+ * pthread_attr_destroy.c: Add namespace protected alias.
+ * pthread_attr_getdetachstate.c: Likewise.
+ * pthread_attr_getinheritsched.c: Likewise.
+ * pthread_attr_getschedparam.c: Likewise.
+ * pthread_attr_getschedpolicy.c: Likewise.
+ * pthread_attr_getscope.c: Likewise.
+ * pthread_attr_setdetachstate.c: Likewise.
+ * pthread_attr_setinheritsched.c: Likewise.
+ * pthread_attr_setschedparam.c: Likewise.
+ * pthread_attr_setschedpolicy.c: Likewise.
+ * pthread_attr_setscope.c: Likewise.
+ * pthread_cond_broadcast.c: Likewise.
+ * pthread_cond_destroy.c: Likewise.
+ * pthread_cond_init.c: Likewise.
+ * pthread_cond_signal.c: Likewise.
+ * pthread_cond_wait.c: Likewise.
+ * pthread_condattr_destroy.c: Likewise.
+ * pthread_condattr_init.c: Likewise.
+ * pthread_equal.c: Likewise.
+ * pthread_exit.c: Likewise.
+ * pthread_getschedparam.c: Likewise.
+ * pthread_self.c: Likewise.
+ * pthread_setcancelstate.c: Likewise.
+ * pthread_setschedparam.c: Likewise.
+ * pthread_mutex_destroy.c: Likewise.
+ * pthread_mutex_init.c: Likewise.
+ * pthreadP.h: Add prototypes for the aliases.
+
+ * sysdeps/unix/sysv/linux/i386/createthread.c (create_thread): Set
+ multiple_threads member in correct TCB to 1.
+
+ * sysdeps/unix/sysv/linux/i386/sysdep-cancel.h: Define
+ SINGLE_THREAD_P. If in libc or libpthread examine multiple_thread
+ member of thread decriptor, otherwise return unconditionally 1.
+
+2002-12-14 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/pt-socket.S: Changes folded into the
+ regular Linux version. Remove file.
+ * sysdeps/unix/sysv/linux/connect.S: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/llseek.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/msgrcv.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/msgsnd.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/open64.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/poll.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/pread.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/pread64.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/pselect.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/pwrite.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/pwrite64.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/readv.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/recv.S: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/recvfrom.S: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/recvmsg.S: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/send.S: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/sendmsg.S: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/sendto.S: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/sigpause.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/sigsuspend.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/sigtimedwait.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/sigwait.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/sigwaitinfo.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/system.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/tcdrain.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/wait.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/waitid.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/waitpid.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/writev.c: Likewise. Remove file.
+ * sysdeps/unix/sysv/linux/i386/fcntl.c: Likewise. Remove file.
+
+2002-12-14 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/sysdep-cancel.h: New file.
+ * sysdeps/unix/sysv/linux/open.c: Removed.
+ * sysdeps/unix/sysv/linux/fsync.c: Removed.
+ * sysdeps/unix/sysv/linux/lseek.c: Removed.
+ * sysdeps/unix/sysv/linux/msync.c: Removed.
+ * sysdeps/unix/sysv/linux/read.c: Removed.
+ * sysdeps/unix/sysv/linux/close.c: Removed.
+ * sysdeps/unix/sysv/linux/creat.c: Removed.
+ * sysdeps/unix/sysv/linux/nanosleep.c: Removed.
+ * sysdeps/unix/sysv/linux/pause.c: Removed.
+ * sysdeps/unix/sysv/linux/select.c: Removed.
+ * sysdeps/unix/sysv/linux/write.c: Removed.
+
+2002-12-14 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/pt-socket.S: Check multiple_threads
+ element in TCB to see whether locking is needed.
+
+ * sysdeps/unix/sysv/linux/libc_pthread_init.c: Check that
+ MULTIPLE_THREADS_OFFSET value is correct.
+
+ * sysdeps/unix/sysv/linux/close.c: New file.
+ * sysdeps/unix/sysv/linux/connect.S: New file.
+ * sysdeps/unix/sysv/linux/creat.c: New file.
+ * sysdeps/unix/sysv/linux/fsync.c: New file.
+ * sysdeps/unix/sysv/linux/llseek.c: New file.
+ * sysdeps/unix/sysv/linux/lseek.c: New file.
+ * sysdeps/unix/sysv/linux/msgrcv.c: New file.
+ * sysdeps/unix/sysv/linux/msgsnd.c: New file.
+ * sysdeps/unix/sysv/linux/msync.c: New file.
+ * sysdeps/unix/sysv/linux/nanosleep.c: New file.
+ * sysdeps/unix/sysv/linux/open.c: New file.
+ * sysdeps/unix/sysv/linux/open64.c: New file.
+ * sysdeps/unix/sysv/linux/pause.c: New file.
+ * sysdeps/unix/sysv/linux/poll.c: New file.
+ * sysdeps/unix/sysv/linux/pread.c: New file.
+ * sysdeps/unix/sysv/linux/pread64.c: New file.
+ * sysdeps/unix/sysv/linux/pselect.c: New file.
+ * sysdeps/unix/sysv/linux/pwrite.c: New file.
+ * sysdeps/unix/sysv/linux/pwrite64.c: New file.
+ * sysdeps/unix/sysv/linux/readv.c: New file.
+ * sysdeps/unix/sysv/linux/recv.S: New file.
+ * sysdeps/unix/sysv/linux/recvfrom.S: New file.
+ * sysdeps/unix/sysv/linux/recvmsg.S: New file.
+ * sysdeps/unix/sysv/linux/select.c: New file.
+ * sysdeps/unix/sysv/linux/send.S: New file.
+ * sysdeps/unix/sysv/linux/sendmsg.S: New file.
+ * sysdeps/unix/sysv/linux/sendto.S: New file.
+ * sysdeps/unix/sysv/linux/sigpause.c: New file.
+ * sysdeps/unix/sysv/linux/sigsuspend.c: New file.
+ * sysdeps/unix/sysv/linux/sigtimedwait.c: New file.
+ * sysdeps/unix/sysv/linux/sigwait.c: New file.
+ * sysdeps/unix/sysv/linux/sigwaitinfo.c: New file.
+ * sysdeps/unix/sysv/linux/system.c: New file.
+ * sysdeps/unix/sysv/linux/tcdrain.c: New file.
+ * sysdeps/unix/sysv/linux/wait.c: New file.
+ * sysdeps/unix/sysv/linux/waitid.c: New file.
+ * sysdeps/unix/sysv/linux/waitpid.c: New file.
+ * sysdeps/unix/sysv/linux/writev.c: New file.
+ * sysdeps/unix/sysv/linux/i386/fcntl.c: New file.
+
+ * pt-readv.c: Fix comment.
+
+2002-12-14 Jakub Jelinek <jakub@redhat.com>
+
+ * tst-cleanup1.c: Include stdlib.h.
+
+ * tst-cancel5.c: New test.
+ * Makefile (tests): Add tst-cancel5.
+ (tst-cancel5): Link against libc.so libpthread.so in that order.
+
+2002-12-13 Ulrich Drepper <drepper@redhat.com>
+
+ * forward.c (test_loaded): Prevent recursive calls.
+
+ * Makefile (routines): Add libc-cancellation.
+ * libc-cancellation.c: New file.
+ * descr.h (struct pthread): Add multiple_threads field.
+ * allocatestack.c (allocate_stack): Initialize multiple_header field of
+ new thread descriptor to 1.
+ * sysdeps/unix/sysv/linux/i386/createthread.c (create_thread):
+ Initialize multiple_thread field after successful thread creation.
+ * cancellation.c (__do_cancel): Move to pthreadP.h.
+ (__pthread_enable_asynccancel): Remove parameter from __do_cancel call.
+ (__pthread_disable_asynccancel): Add internal_function attribute.
+ * init.c (sigcancel_handler): Remove parameter from __do_cancel call.
+ * pthread_setcancelstate.c: Likewise.
+ * pthread_setcanceltype.c: Likewise.
+ * pthread_exit.c: Likewise.
+ * pthreadP.h (CANCELLATION_P): Likewise.
+ (__do_cancel): Define as static inline.
+ (LIBC_CANCEL_ASYNC, LIBC_CANCEL_RESET): New #defines.
+ (__libc_enable_asynccancel, __libc_disable_asynccancel): New
+ declarations.
+ * sysdeps/i386/tls.h (tcbhead_t): Add list and multiple_threads
+ fields. Define MULTIPLE_THREADS_OFFSET.
+ * sysdeps/pthread/bits/libc-lock.h: Remove __libc_locking_needed
+ declaration.
+ * sysdeps/unix/sysv/linux/accept.S: New file.
+ * sysdeps/unix/sysv/linux/read.c: New file.
+ * sysdeps/unix/sysv/linux/write.c: New file.
+ * sysdeps/unix/sysv/linux/i386/pt-socket.S: New file.
+ * sysdeps/unix/sysv/linux/libc_pthread_init.c: Remove definition and
+ initialization of __libc_locking_needed.
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h: Don't use
+ __libc_locking_needed, use multiple_threads field in TCB.
+ * sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S: Likewise.
+
+2002-12-12 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i686/libc-lowlevellock.S: Use i486
+ version.
+ * sysdeps/unix/sysv/linux/i386/i586/libc-lowlevellock.S: Likewise.
+
+ * sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S: Correct
+ access to __libc_locking_needed for PIC.
+
+2002-12-12 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/pthread/bits/libc-lock.h (__libc_locking_needed): Only
+ declare for libc.so.
+ (__libc_lock_init, __libc_lock_init_recursive): Change into comma
+ expression.
+ (__libc_lock_lock): Put into statement expression.
+ (__libc_lock_unlock): Remove trailing semicolon.
+ * sysdeps/unix/sysv/linux/fork.h (__libc_pthread_init): Fix typo.
+
+2002-12-12 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h: Use asm operand with
+ "m" constraint to refer to __libc_locking_needed. Declare it here.
+
+2002-12-12 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/fork-gen.c: Renamed to...
+ * sysdeps/unix/sysv/linux/libc_pthread_init.c: ...this.
+ Initialize __libc_locking_needed.
+ * init.c (__pthread_initialize_minimal): Call __libc_pthread_init
+ instead of __register_pthread_fork_handler.
+ * sysdeps/pthread/bits/libc-lock.h: Declare __libc_locking_needed.
+ * sysdeps/unix/sysv/linux/Makefile (sysdep_routimes): Replace
+ fork-gen with libc_pthread_init.
+ * sysdeps/unix/sysv/linux/Versions: Use __libc_pthread_init instead
+ of __register_pthread_fork_handler.
+ * sysdeps/unix/sysv/linux/fork.h: Declare __libc_pthread_init instead
+ of __register_pthread_fork_handler.
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h: Use
+ __libc_locking_needed to determine whether lock prefix can be avoided.
+ * sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S: Likewise.
+
+2002-12-11 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-cleanup1.
+ * tst-cleanup1.c: New file.
+ * cancellation.c (__cleanup_thread): Removed.
+ (__do_cancel): Remove call to __cleanup_thread.
+ * pthreadP.h: Remove __cleanup_thread prorotype.
+
+ * sysdeps/pthread/bits/libc-lock.h (__libc_cleanup_region_start):
+ Remember function and argument even if cancellation handler
+ function is not available.
+ (__libc_cleanup_region_end): Execute registered function directly if
+ pthread functions are not available.
+ (__libc_cleanup_end): Likewise.
+
+ * init.c (__pthread_initialize_minimal): Fix initialization in
+ static lib by preventing gcc from being too clever.
+
+2002-12-10 Ulrich Drepper <drepper@redhat.com>
+
+ * init.c (__pthread_initialize_minimal): Remove unneccesary
+ sigaddset call.
+
+ * Makefile (tests): We can run tst-locale2 now.
+
+2002-12-09 Ulrich Drepper <drepper@redhat.com>
+
+ * Versions: Remove duplicated sigwait entry.
+
+2002-12-08 Ulrich Drepper <drepper@redhat.com>
+
+ * pthreadP.h: Enable pthread_cleanup_{push,pop} optimizations only
+ inside libpthread.
+
+ * pt-fcntl.c (__fcntl): Initialize oldtype to avoid warning.
+
+ * pthreadP.h: Declare __pthread_enable_asynccancel and
+ __pthread_disable_asynccancel.
+ (CANCEL_ASYNC): Use __pthread_enable_asynccancel.
+ (CANCEL_RESET): Use __pthread_disable_asynccancel.
+ * cancellation.c (__pthread_enable_asynccancel): New function.
+ (__pthread_disable_asynccancel): New function.
+ * pt-accept.c: Adjust for CANCEL_ASYNC and CANCEL_RESET change.
+ * pt-close.c: Likewise.
+ * pt-connect.c: Likewise.
+ * pt-creat.c: Likewise.
+ * pt-fcntl.c: Likewise.
+ * pt-fsync.c: Likewise.
+ * pt-lseek.c: Likewise.
+ * pt-lseek64.c: Likewise.
+ * pt-msgrcv.c: Likewise.
+ * pt-msgsnd.c: Likewise.
+ * pt-msync.c: Likewise.
+ * pt-nanosleep.c: Likewise.
+ * pt-open.c: Likewise.
+ * pt-open64.c: Likewise.
+ * pt-pause.c: Likewise.
+ * pt-poll.c: Likewise.
+ * pt-pread.c: Likewise.
+ * pt-pread64.c: Likewise.
+ * pt-pselect.c: Likewise.
+ * pt-pwrite.c: Likewise.
+ * pt-pwrite64.c: Likewise.
+ * pt-read.c: Likewise.
+ * pt-readv.c: Likewise.
+ * pt-recv.c: Likewise.
+ * pt-recvfrom.c: Likewise.
+ * pt-recvmsg.c: Likewise.
+ * pt-select.c: Likewise.
+ * pt-send.c: Likewise.
+ * pt-sendmsg.c: Likewise.
+ * pt-sendto.c: Likewise.
+ * pt-sigpause.c: Likewise.
+ * pt-sigsuspend.c: Likewise.
+ * pt-sigtimedwait.c: Likewise.
+ * pt-sigwait.c: Likewise.
+ * pt-sigwaitinfo.c: Likewise.
+ * pt-system.c: Likewise.
+ * pt-tcdrain.c: Likewise.
+ * pt-wait.c: Likewise.
+ * pt-waitid.c: Likewise.
+ * pt-waitpid.c: Likewise.
+ * pt-write.c: Likewise.
+ * pt-writev.c: Likewise.
+ * pthread_join.c: Likewise.
+ * pthread_timedjoin.c: Likewise.
+
+ * pt-sigpause.c (sigsuspend): Call __sigsuspend.
+ (__xpg_sigpause): New function.
+ * Versions (libpthread:GLIBC_2.3.2): Add __xpg_sigpause.
+
+2002-12-07 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (CFLAGS-ftrylockfile.c): Add -D_IO_MTSAFE_IO.
+
+ * cleanup.c: Move declarations of _GI_pthread_cleanup_push and
+ _GI_pthread_cleanup_pop to pthreadP.h.
+
+ * ftrylockfile.c: Use _IO_lock_trylock instead of
+ pthread_mutex_trylock.
+
+ * pthreadP.h (CANCEL_ASYNC): Use __pthread_setcanceltype.
+ (CANCEL_RESET): Likewise.
+ (__pthread_setcanceltype_): Declare.
+ (__pthread_mutex_lock_internal): Declare.
+ (__pthread_mutex_unlock_internal): Declare.
+ (__pthread_once_internal): Declare.
+ (pthread_cleanup_push): Redefine using _GI_pthread_cleanup_push.
+ (pthread_cleanup_pop): Redefine using _GI_pthread_cleanup_pop.
+
+ * pthread_cond_timedwait.c: Use INTUSE is calls to pthread_mutex_lock
+ and pthread_mutex_unlock.
+ * pthread_cond_wait.c: Likewise.
+ * pthread_mutex_lock.c: Use INTDEF to define alias if needed.
+ * pthread_mutex_unlock.c: Likewise.
+
+ * pthread_setcanceltype.c: Add additional alias
+ __pthread_setcanceltype.
+
+ * sem_unlink.c (sem_unlink): Use __pthread_once with INTDEF.
+ * sem_open.c (sem_open): Likewise.
+ Use __libc_open, __libc_write, and __libc_close instead of
+ open, write, and close respectively.
+
+ * sysdeps/pthread/bits/libc-lock.h (__libc_lock_trylock_internal):
+ Rewrite as statement expression since it must return a value.
+
+ * pthread_cancel.c: Use __pthread_kill instead of pthread_kill.
+ * sysdeps/unix/sysv/linux/pthread_kill.c: Define additional alias
+ __pthread_kill.
+
+ * sysdeps/unix/sysv/linux/i386/pthread_once.S: Define additional
+ alias __pthread_once_internal.
+
+ * sysdeps/unix/sysv/linux/raise.c: Use libc_hidden_def for raise.
+
+2002-12-06 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-stdio1 and tst-stdio2.
+ * tst-stdio1.c: New file.
+ * tst-stdio2.c: New file.
+
+ * init.c (__pthread_initialize_minimal): Correct INIT_LIST_HEAD use.
+
+ * Makefile (tests): Comment out tst-locale2 for now.
+ (CFLAGS-flockfile.c, CFLAGS-funlockfile.c): Define to -D_IO_MTSAFE_IO.
+
+ * sysdeps/unix/sysv/linux/Makefile: Define CFLAGS-fork.c to
+ -D_IO_MTSAFE_IO.
+ * sysdeps/unix/sysv/linux/fork.c: Include <bits/stdio-lock.h>.
+ Use _IO_lock_init instead of explicit assignment.
+
+ * sysdeps/pthread/bits/libc-lock.h: Define __rtld_lock_* macros.
+ Define __libc_lock_* and __libc_lock_recursive macros with
+ lowlevellock macros, not pthread mutexes.
+
+ * flockfile.c: Include <bits/stdio-lock.h>. Use _IO_lock_lock instead
+ of pthread_mutex_lock.
+ * funlockfile.c: Include <bits/stdio-lock.h>. Use _IO_lock_unlock
+ instead of pthread_mutex_unlock.
+
+2002-12-06 Roland McGrath <roland@redhat.com>
+
+ * allocatestack.c (__stack_user): Use uninitialized defn.
+ * init.c (__pthread_initialize_minimal): Initialize it here.
+
+2002-12-05 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/i386/tls.h (TLS_INIT_TP): Make it return zero or an error
+ string.
+ * sysdeps/x86_64/tls.h (TLS_INIT_TP): Likewise.
+
+ * sysdeps/unix/sysv/linux/i386/createthread.c (create_thread): Add
+ missing & here too.
+
+2002-12-05 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
+ lowlevellock.
+ * sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i586/libc-lowlevellock.S: New file.
+ * sysdeps/unix/sysv/linux/i386/i686/libc-lowlevellock.S: New file.
+ * sysdeps/pthread/bits/libc-lock.h: Use lowlevellock implementation
+ for __libc_lock_* macros.
+ * Makefile (routines): Add libc-lowlevellock.
+
+2002-10-09 Roland McGrath <roland@redhat.com>
+
+ * sysdeps/pthread/bits/libc-lock.h (__libc_maybe_call): New macro.
+ Under [__PIC__], call the function via the pointer fetched for
+ comparison rather than a call by name that uses the PLT.
+ (__libc_lock_init, __libc_rwlock_init, __libc_lock_fini)
+ (__libc_rwlock_fini, __libc_lock_lock, __libc_rwlock_rdlock)
+ (__libc_rwlock_wrlock, __libc_lock_trylock, __libc_rwlock_tryrdlock)
+ (__libc_rwlock_trywrlock, __libc_lock_unlock, __libc_rwlock_unlock)
+ (__libc_key_create, __libc_getspecific, __libc_setspecific): Use it.
+
+2002-12-04 Roland McGrath <roland@redhat.com>
+
+ * forward.c (pthread_self): Use FORWARD3 macro to correct return type.
+
+ * sysdeps/i386/td_ta_map_lwp2thr.c: Moved from ../nptl_db.
+ * sysdeps/generic/td_ta_map_lwp2thr.c: New file.
+
+ * pthread_create.c (start_thread): Add missing & on __nptl_last_event.
+
+2002-12-04 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h: Make pthread_t
+ a completely opaque, non-integer type.
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h: Likewise.
+
+2002-12-05 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/i386/tls.h: Include stdlib.h.
+ * sysdeps/x86_64/tls.h: Likewise.
+
+2002-12-04 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-locale2.
+ (tests-static): Likewise.
+ * tst-locale2.c: New file.
+
+ * sysdeps/unix/sysv/linux/i386/lowlevellock.h: Mark asms as
+ volatile and add memory clobbers to lock operations.
+
+2002-12-03 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/i386/i686/bits/atomic.h: Use i486 version.
+ * sysdeps/i386/i486/bits/atomic.h: New file.
+ * sysdeps/i386/i586/bits/atomic.h: New file.
+ * sysdeps/i386/i686/pthread_spin_trylock.S: Define HAVE_CMOV and
+ include i486 version.
+ * sysdeps/i386/i486/pthread_spin_trylock.S: New file.
+ * sysdeps/i386/i586/pthread_spin_trylock.S: New file.
+ Patch by Marijn Ros <marijn@mad.scientist.com>.
+
+ * allocatestack.c (get_cached_stack): Don't crash if we first
+ found a stack with a larger size then needed.
+ Reported by Hui Huang <hui.huang@sun.com>.
+
+ * Makefile (tests): Add tst-sysconf.
+ * tst-sysconf.c: New file.
+
+ * sysdeps/unix/sysv/linux/bits/local_lim.h: Undefine
+ PTHREAD_THREADS_MAX.
+
+2002-12-02 Roland McGrath <roland@redhat.com>
+
+ * pthreadP.h (__stack_user, __nptl_create_event, __nptl_death_event):
+ Declare using hidden_proto instead of attribute_hidden, so there are
+ non-.hidden static symbols for gdb to find.
+ (__pthread_keys): Likewise.
+ * events.c (__nptl_create_event, __nptl_death_event): Add hidden_def.
+ * allocatestack.c (__stack_user): Likewise.
+ * pthread_create.c (__pthread_keys): Likewise.
+ (__nptl_threads_events, __nptl_last_event): Make these static instead
+ of hidden.
+ * pthread_key_create.c (__pthread_pthread_keys_max,
+ __pthread_pthread_key_2ndlevel_size): Renamed from __linuxthreads_*.
+
+2002-12-02 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-locale1. If buid-static is yes link
+ statically.
+ * tst-locale1.c: New file.
+
+ * pthread_cond_timedwait.c: Include <stdlib.h>.
+
+ * Makefile (tests): Add tst-fork2 and tst-fork3.
+ * tst-fork2.c: New file.
+ * tst-fork3.c: New file.
+
+2002-11-28 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/bits/posix_opt.h: New file.
+
+ * sysdeps/unix/sysv/linux/bits/posix_opt.h: Define macros which
+ require it to 200112L.
+
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelrwlock.S: Use cmov
+ instruction only if HAVE_CMOV is defined.
+ * sysdeps/unix/sysv/linux/i386/i686/lowlevelrwlock.S: Define HAVE_CMOV.
+
+ * sysdeps/unix/sysv/linux/x86_64/bits/semaphore.h: New file.
+
+ * sysdeps/unix/sysv/linux/x86_64/pthread_once.S: New file.
+
+ * sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h: New file.
+
+ * sysdeps/unix/sysv/linux/x86_64/pt-vfork.S: New file.
+
+2002-11-27 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/x86_64/bits/atomic.h: New file.
+
+ * sysdeps/i386/i686/bits/atomic.h: Fix asm syntax for 8- and
+ 16-bit operations.
+
+ * sysdeps/unix/sysv/linux/raise.c (raise): Use INTERNAL_SYSCALL if
+ possible since gettid cannot fail.
+
+ * sysdeps/x86_64/pthreaddef.h: New file.
+
+ * sysdeps/i386/pthreaddef.h (gettid): Removed.
+
+ * sysdeps/x86_64/pthread_spin_init.c: New file.
+ * sysdeps/x86_64/pthread_spin_lock.c: New file.
+ * sysdeps/x86_64/pthread_spin_trylock.c: New file.
+ * sysdeps/x86_64/pthread_spin_unlock.c: New file.
+
+ * sysdeps/i386/i686/pthread_spin_trylock.S (pthread_spin_trylock):
+ Add missing lock prefix. Minute optimization.
+
+ * tst-spin2.c (main): Also check successful trylock call.
+
+ * sysdeps/pthread/pthread_sigmask.c (pthread_sigmask): Use correct
+ syscall. Fix typo in case INTERNAL_SYSCALL is not used.
+
+ * sysdeps/i386/pthread_spin_destroy.c: Moved to...
+ * sysdeps/pthread/pthread_spin_destroy.c: ...here. New file.
+
+ * sysdeps/i386/pthread_sigmask.c: Removed. Use the generic code.
+ * sysdeps/pthread/pthread_sigmask.c (pthread_sigmask): Return correct
+ value in case of an error. Add support for INTERNAL_SYSCALL.
+
+ * sysdeps/i386/pthread_sigmask.c (pthread_sigmask): Return correct
+ value in case of an error.
+
+ * sysdeps/x86_64/tls.h: New file.
+
+2002-11-26 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/i386/tls.h (THREAD_GETMEM_NC): Change interface. It now
+ takes the array member name and the index as parameters.
+ (THREAD_SETMEM_NC): Likewise.
+ * pthread_getspecific.c: Use new THREAD_GETMEM_NC interface.
+ * pthread_setspecific.c: Use new THREAD_GETMEM_NC and THREAD_SETMEM_NC
+ interfaces.
+
+ * sysdeps/i386/tls.h (THREAD_SETMEM): Use size of member element
+ to decide which code to use.
+ (THREAD_SETMEM_NC): Likewise.
+
+ * allocatestack.c (queue_stack): Don't remove stack from list here.
+ Do it in the caller. Correct condition to prematurely terminate
+ loop to free stacks.
+ (__deallocate_stack): Remove stack from list here.
+
+2002-11-26 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-stack1.
+ * tst-stack1.c: New file.
+
+ * allocatestack.c (allocate_stack): Initialize the TCB on a user
+ provided stack.
+
+ * pthread_attr_getstack.c: Return bottom of the thread area.
+
+2002-11-25 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (libpthread-routines): Add pt-allocrtsig and
+ pthread_kill_other_threads.
+ * pt-allocrtsig.c: New file.
+ * pthread_kill_other_threads.c: New file.
+ * sysdeps/unix/sysv/linux/allocrtsig.c: Add additional aliases for
+ all three functions.
+ * sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
+ allocrtsig.
+ * sysdeps/unix/sysv/linux/Versions (libc:GLIBC_PRIVATE): Export
+ __libc_current_sigrtmin_private, __libc_current_sigrtmax_private,
+ and __libc_allocate_rtsig_private.
+ * Versions (libpthread): Export pthread_kill_other_threads_np,
+ __libc_current_sigrtmin, and __libc_current_sigrtmax.
+
+2002-11-24 Ulrich Drepper <drepper@redhat.com>
+
+ * allocatestack.c (allocate_stack): stackaddr in attribute points to
+ the end of the stack. Adjust computations.
+ When mprotect call fails dequeue stack and free it.
+ * pthread_attr_setstack.c: Store top of the stack in stackaddr
+ attribute.
+ * pthread_getattr_np.c: Likewise.
+
+ * descr.h (IS_DETACHED): Add some more parenthesis to prevent
+ surprises.
+
+2002-11-23 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/pthread/pthread.h (pthread_self): __THROW must come before
+ attribute definitions. Patch by Luca Barbieri <ldb@ldb.ods.org>.
+
+2002-11-22 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread_getspecific.c: Optimize access to first 2nd-level array.
+ * pthread_setspecific.c: Likewise.
+
+2002-11-21 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/createthread.c: Remove CLONE_ flags
+ definitions. Get them from the official place.
+ * sysdeps/unix/sysv/linux/i386/fork.c: Likewise.
+
+ * sysdeps/unix/sysv/linux/i386/createthread.c: Update CLONE_* flags.
+ Use new CLONE_ flags in clone() calls.
+
+ * sysdeps/unix/sysv/linux/fork.c: Use ARCH_FORK to actually fork.
+ * sysdeps/unix/sysv/linux/i386/fork.c: New file.
+
+ * Versions: Add pthread_* functions for libc.
+ * forward.c: New file.
+
+ * sysdeps/pthread/Makefile (libpthread-sysdeps_routines): Add
+ errno-loc.
+ * herrno.c: New file.
+ * res.c: New file.
+
+ * Makefile (libpthread-routines): Remove sem_post, sem_wait,
+ sem_trywait, and sem_timedwait. Add herrno and res.
+ * sem_init.c: Don't initialize lock and waiters members.
+ * sem_open.c: Likewise.
+ * sem_post.c: Removed.
+ * sem_wait.c: Removed.
+ * sem_trywait.c: Removed.
+ * sem_timedwait.c: Removed.
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelsem.S: Complete rewrite.
+ Includes full implementations of sem_post, sem_wait, sem_trywait,
+ and sem_timedwait.
+ * sysdeps/unix/sysv/linux/i386/lowlevelsem.h (lll_sem_post): Adjust
+ for new implementation.
+ * sysdeps/unix/sysv/linux/internaltypes.h (struct sem): Remove lock
+ and waiters fields.
+
+ * tst-sem3.c: Improve error message.
+ * tst-signal3.c: Likewise.
+
+ * init.c (__pthread_initialize_minimal): Use set_tid_address syscall
+ to tell the kernel about the termination futex and to initialize tid
+ member. Don't initialize main_thread.
+ * descr.h (struct pthread): Remove main_thread member.
+ * cancelllation.c (__do_cancel): Remove code handling main thread.
+ The main thread is not special anymore.
+
+ * allocatestack.c (__reclaim_stacks): Mark stacks as unused. Add
+ size of the stacks to stack_cache_actsize.
+
+ * pt-readv.c: Add missing "defined".
+ * pt-sigwait.c: Likewise.
+ * pt-writev.c: Likewise.
+
+2002-11-09 Ulrich Drepper <drepper@redhat.com>
+
+ * Versions: Export __connect from libpthread.
+ Patch by Luca Barbieri <ldb@ldb.ods.org>.
+
+ * Makefile (libpthread-routines): Add pt-raise.
+ * sysdeps/unix/sysv/linux/raise.c: New file.
+ * sysdeps/unix/sysv/linux/pt-raise.c: New file.
+ * sysdeps/generic/pt-raise.c: New file.
+
+ * pthread_cond_init.c: Initialize all data elements of the condvar
+ structure. Patch by Luca Barbieri <ldb@ldb.ods.org>.
+
+ * pthread_attr_init.c: Actually implement 2.0 compatibility version.
+ * pthread_create.c: Likewise.
+
+ * Makefile (tests): Add tst-key1, tst-key2, tst-key3.
+ * tst-key1.c: New file.
+ * tst-key2.c: New file.
+ * tst-key3.c: New file.
+
+ * Versions: Export pthread_detach for version GLIBC_2.0.
+ Reported by Saurabh Desai <sdesai@austin.ibm.com>.
+
+2002-11-08 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread_key_create.c: Terminate search after an unused key was found.
+ Patch by Luca Barbieri <ldb@ldb.ods.org>.
+
+ * sysdeps/unix/sysv/linux/i386/pthread_once.S: Return zero.
+ Patch by Luca Barbieri <ldb@ldb.ods.org>.
+
+2002-10-10 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/i486/lowlevelsem.S: Use slow generic
+ dynamic lookup for errno in PIC.
+
+ * allocatestack.c (get_cached_stack): Rearrange code slightly to
+ release the stack lock as soon as possible.
+ Call _dl_allocate_tls_init for TCB from the cache to re-initialize
+ the static TLS block.
+ (allocate_stack): Call _dl_allocate_tls_init for user-provided stack.
+
+ * cancellation.c: Renamed from cancelation.c.
+ * Makefile: Adjust accordingly.
+ * pthreadP.h (CANCELLATION_P): Renamed from CANCELATION_P.
+ * cleanup_defer.c: Use CANCELLATION_P.
+ * pthread_testcancel.c: Likewise.
+ * descr.h: Fix spelling in comments.
+ * init.c: Likewise.
+ * pthread_getattr_np.c: Likewise.
+ * pthread_getschedparam.c: Likewise.
+ * pthread_setschedparam.c: Likewise.
+ * Versions: Likewise.
+
+ * pt-pselect.c: New file.
+ * Makefile (libpthread-routines): Add pt-pselect.
+ * Versions: Add pselect.
+
+ * tst-cancel4.c: New file.
+ * Makefile (tests): Add tst-cancel4.
+
+2002-10-09 Ulrich Drepper <drepper@redhat.com>
+
+ * pthread_mutex_lock.c: Always record lock ownership.
+ * pthread_mutex_timedlock.c: Likewise.
+ * pthread_mutex_trylock.c: Likewise.
+
+ * pt-readv.c: New file.
+ * pt-writev.c: New file.
+ * pt-creat.c: New file.
+ * pt-msgrcv.c: New file.
+ * pt-msgsnd.c: New file.
+ * pt-poll.c: New file.
+ * pt-select.c: New file.
+ * pt-sigpause.c: New file.
+ * pt-sigsuspend.c: New file.
+ * pt-sigwait.c: New file.
+ * pt-sigwaitinfo.c: New file.
+ * pt-waitid.c: New file.
+ * Makefile (libpthread-routines): Add pt-readv, pt-writev, pt-creat,
+ pt-msgrcv, pt-msgsnd, pt-poll, pt-select, pt-sigpause, pt-sigsuspend,
+ pt-sigwait, pt-sigwaitinfo, and pt-waitid.
+ * Versions: Add all the new functions.
+
+ * tst-exit1.c: New file.
+ * Makefile (tests): Add tst-exit1.
+
+ * sem_timedwait.c: Minor optimization for more optimal fastpath.
+
+2002-10-08 Ulrich Drepper <drepper@redhat.com>
+
+ * pt-fcntl.c: Only enable asynchronous cancellation for F_SETLKW.
+
+ * pthread_join.c: Enable asynchronous cancellation around lll_wait_tid
+ call. pthread_join is an official cancellation point.
+ * pthread_timedjoin.c: Likewise.
+
+ * pthread_cond_wait.c: Revert order in which internal lock are dropped
+ and the condvar's mutex are retrieved.
+ * pthread_cond_timedwait.c: Likewise.
+ Reported by dice@saros.East.Sun.COM.
+
+2002-10-07 Ulrich Drepper <drepper@redhat.com>
+
+ * pthreadP.h: Cut out all type definitions and move them...
+ * sysdeps/unix/sysv/linux/internaltypes.h: ...here. New file.
+ * pthreadP.h: Include <internaltypes.h>.
+
+ * sysdeps/unix/sysv/linux/i386/lowlevelsem.h (lll_sem_post): Little
+ performance tweaks.
+
+ * sem_trywait.c: Shuffle #includes around to get right order.
+ * sem_timedwait.c: Likewise.
+ * sem_post.c: Likewise.
+ * sem_wait.c: Likewise.
+
+ * nptl 0.3 released.
+
+ * Makefile (tests): Add tst-signal3.
+ * tst-signal3.c: New file.
+
+2002-10-05 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/i386/lowlevelsem.h: Tell the compiler that
+ the asms modify the sem object.
+ (__lll_sem_timedwait): Now takes struct sem* as first parameter.
+
+ * sysdeps/unix/sysv/linux/i386/bits/semaphore.h (sem_t): Don't expose
+ the actual members.
+ * pthreadP.h (struct sem): New type. Actual semaphore type.
+ * semaphoreP.h: Include pthreadP.h.
+ * sem_getvalue.c: Adjust to sem_t change.
+ * sem_init.c: Likewise.
+ * sem_open.c: Likewise.
+ * sem_post.c: Likewise.
+ * sem_timedwait.c: Likewise.
+ * sem_trywait.c: Likewise.
+ * sem_wait.c: Likewise.
+
+2002-10-04 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-basic2, tst-exec1, tst-exec3, tst-exec3.
+ * tst-basic2.c: New file.
+ * tst-exec1.c: New file.
+ * tst-exec2.c: New file.
+ * tst-exec3.c: New file.
+
+ * tst-fork1.c: Remove extra */.
+
+ * nptl 0.2 released. The API for IA-32 is complete.
diff --git a/libc/nptl/DESIGN-barrier.txt b/libc/nptl/DESIGN-barrier.txt
new file mode 100644
index 000000000..23463c6b7
--- /dev/null
+++ b/libc/nptl/DESIGN-barrier.txt
@@ -0,0 +1,44 @@
+Barriers pseudocode
+===================
+
+ int pthread_barrier_wait(barrier_t *barrier);
+
+struct barrier_t {
+
+ unsigned int lock:
+ - internal mutex
+
+ unsigned int left;
+ - current barrier count, # of threads still needed.
+
+ unsigned int init_count;
+ - number of threads needed for the barrier to continue.
+
+ unsigned int curr_event;
+ - generation count
+}
+
+pthread_barrier_wait(barrier_t *barrier)
+{
+ unsigned int event;
+ result = 0;
+
+ lll_lock(barrier->lock);
+ if (!--barrier->left) {
+ barrier->curr_event++;
+ futex_wake(&barrier->curr_event, INT_MAX)
+
+ result = BARRIER_SERIAL_THREAD;
+ } else {
+ event = barrier->curr_event;
+ lll_unlock(barrier->lock);
+ do {
+ futex_wait(&barrier->curr_event, event)
+ } while (event == barrier->curr_event);
+ }
+
+ if (atomic_increment_val (barrier->left) == barrier->init_count)
+ lll_unlock(barrier->lock);
+
+ return result;
+}
diff --git a/libc/nptl/DESIGN-condvar.txt b/libc/nptl/DESIGN-condvar.txt
new file mode 100644
index 000000000..4845251c7
--- /dev/null
+++ b/libc/nptl/DESIGN-condvar.txt
@@ -0,0 +1,134 @@
+Conditional Variable pseudocode.
+================================
+
+ int pthread_cond_timedwait (pthread_cond_t *cv, pthread_mutex_t *mutex);
+ int pthread_cond_signal (pthread_cond_t *cv);
+ int pthread_cond_broadcast (pthread_cond_t *cv);
+
+struct pthread_cond_t {
+
+ unsigned int cond_lock;
+
+ internal mutex
+
+ uint64_t total_seq;
+
+ Total number of threads using the conditional variable.
+
+ uint64_t wakeup_seq;
+
+ sequence number for next wakeup.
+
+ uint64_t woken_seq;
+
+ sequence number of last woken thread.
+
+ uint32_t broadcast_seq;
+
+}
+
+
+struct cv_data {
+
+ pthread_cond_t *cv;
+
+ uint32_t bc_seq
+
+}
+
+
+
+cleanup_handler(cv_data)
+{
+ cv = cv_data->cv;
+ lll_lock(cv->lock);
+
+ if (cv_data->bc_seq == cv->broadcast_seq) {
+ ++cv->wakeup_seq;
+ ++cv->woken_seq;
+ }
+
+ /* make sure no signal gets lost. */
+ FUTEX_WAKE(cv->wakeup_seq, ALL);
+
+ lll_unlock(cv->lock);
+}
+
+
+cond_timedwait(cv, mutex, timeout):
+{
+ lll_lock(cv->lock);
+ mutex_unlock(mutex);
+
+ cleanup_push
+
+ ++cv->total_seq;
+ val = seq = cv->wakeup_seq;
+ cv_data.bc = cv->broadcast_seq;
+ cv_data.cv = cv;
+
+ while (1) {
+
+ lll_unlock(cv->lock);
+
+ enable_async(&cv_data);
+
+ ret = FUTEX_WAIT(cv->wakeup_seq, val, timeout);
+
+ restore_async
+
+ lll_lock(cv->lock);
+
+ if (bc != cv->broadcast_seq)
+ goto bc_out;
+
+ val = cv->wakeup_seq;
+
+ if (val != seq && cv->woken_seq != val) {
+ ret = 0;
+ break;
+ }
+
+ if (ret == TIMEDOUT) {
+ ++cv->wakeup_seq;
+ break;
+ }
+ }
+
+ ++cv->woken_seq;
+
+ bc_out:
+ lll_unlock(cv->lock);
+
+ cleanup_pop
+
+ mutex_lock(mutex);
+
+ return ret;
+}
+
+cond_signal(cv)
+{
+ lll_lock(cv->lock);
+
+ if (cv->total_seq > cv->wakeup_seq) {
+ ++cv->wakeup_seq;
+ FUTEX_WAKE(cv->wakeup_seq, 1);
+ }
+
+ lll_unlock(cv->lock);
+}
+
+cond_broadcast(cv)
+{
+ lll_lock(cv->lock);
+
+ if (cv->total_seq > cv->wakeup_seq) {
+ cv->wakeup_seq = cv->total_seq;
+ cv->woken_seq = cv->total_seq;
+ ++cv->broadcast_seq;
+ FUTEX_WAKE(cv->wakeup_seq, ALL);
+ }
+
+ lll_unlock(cv->lock);
+}
diff --git a/libc/nptl/DESIGN-rwlock.txt b/libc/nptl/DESIGN-rwlock.txt
new file mode 100644
index 000000000..810d1b8f3
--- /dev/null
+++ b/libc/nptl/DESIGN-rwlock.txt
@@ -0,0 +1,113 @@
+Reader Writer Locks pseudocode
+==============================
+
+ pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
+ pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
+ pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
+
+struct pthread_rwlock_t {
+
+ unsigned int lock:
+ - internal mutex
+
+ unsigned int writers_preferred;
+ - locking mode: 0 recursive, readers preferred
+ 1 nonrecursive, writers preferred
+
+ unsigned int readers;
+ - number of read-only references various threads have
+
+ pthread_t writer;
+ - descriptor of the writer or 0
+
+ unsigned int readers_wakeup;
+ - 'all readers should wake up' futex.
+
+ unsigned int writer_wakeup;
+ - 'one writer should wake up' futex.
+
+ unsigned int nr_readers_queued;
+ - number of readers queued up.
+
+ unsigned int nr_writers_queued;
+ - number of writers queued up.
+}
+
+pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
+{
+ lll_lock(rwlock->lock);
+ for (;;) {
+ if (!rwlock->writer && (!rwlock->nr_writers_queued ||
+ !rwlock->writers_preferred))
+ break;
+
+ rwlock->nr_readers_queued++;
+ val = rwlock->readers_wakeup;
+ lll_unlock(rwlock->lock);
+
+ futex_wait(&rwlock->readers_wakeup, val)
+
+ lll_lock(rwlock->lock);
+ rwlock->nr_readers_queued--;
+ }
+ rwlock->readers++;
+ lll_unlock(rwlock->lock);
+}
+
+pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock)
+{
+ int result = EBUSY;
+ lll_lock(rwlock->lock);
+ if (!rwlock->writer && (!rwlock->nr_writers_queued ||
+ !rwlock->writers_preferred))
+ rwlock->readers++;
+ lll_unlock(rwlock->lock);
+ return result;
+}
+
+pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
+{
+ lll_lock(rwlock->lock);
+ for (;;) {
+ if (!rwlock->writer && !rwlock->readers)
+ break;
+
+ rwlock->nr_writers_queued++;
+ val = rwlock->writer_wakeup;
+ lll_unlock(rwlock->lock);
+
+ futex_wait(&rwlock->writer_wakeup, val);
+
+ lll_lock(rwlock->lock);
+ rwlock->nr_writers_queued--;
+ }
+ rwlock->writer = pthread_self();
+ lll_unlock(rwlock->lock);
+}
+
+pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
+{
+ lll_lock(rwlock->lock);
+
+ if (rwlock->writer)
+ rwlock->writer = 0;
+ else
+ rwlock->readers--;
+
+ if (!rwlock->readers) {
+ if (rwlock->nr_writers_queued) {
+ ++rwlock->writer_wakeup;
+ lll_unlock(rwlock->lock);
+ futex_wake(&rwlock->writer_wakeup, 1);
+ return;
+ } else
+ if (rwlock->nr_readers_queued) {
+ ++rwlock->readers_wakeup;
+ lll_unlock(rwlock->lock);
+ futex_wake(&rwlock->readers_wakeup, MAX_INT);
+ return;
+ }
+ }
+
+ lll_unlock(rwlock->lock);
+}
diff --git a/libc/nptl/DESIGN-sem.txt b/libc/nptl/DESIGN-sem.txt
new file mode 100644
index 000000000..17eb0c11c
--- /dev/null
+++ b/libc/nptl/DESIGN-sem.txt
@@ -0,0 +1,46 @@
+Semaphores pseudocode
+==============================
+
+ int sem_wait(sem_t * sem);
+ int sem_trywait(sem_t * sem);
+ int sem_post(sem_t * sem);
+ int sem_getvalue(sem_t * sem, int * sval);
+
+struct sem_t {
+
+ unsigned int count;
+ - current semaphore count, also used as a futex
+}
+
+sem_wait(sem_t *sem)
+{
+ for (;;) {
+
+ if (atomic_decrement_if_positive(sem->count))
+ break;
+
+ futex_wait(&sem->count, 0)
+ }
+}
+
+sem_post(sem_t *sem)
+{
+ n = atomic_increment(sem->count);
+ // Pass the new value of sem->count
+ futex_wake(&sem->count, n + 1);
+}
+
+sem_trywait(sem_t *sem)
+{
+ if (atomic_decrement_if_positive(sem->count)) {
+ return 0;
+ } else {
+ return EAGAIN;
+ }
+}
+
+sem_getvalue(sem_t *sem, int *sval)
+{
+ *sval = sem->count;
+ read_barrier();
+}
diff --git a/libc/nptl/Makeconfig b/libc/nptl/Makeconfig
new file mode 100644
index 000000000..54e2f65b0
--- /dev/null
+++ b/libc/nptl/Makeconfig
@@ -0,0 +1,30 @@
+# Copyright (C) 2002,2003,2005,2006 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+# Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+# 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.
+
+# Makeconfig fragment for NPTL add-on.
+# This gets included at the end of the main glibc Makeconfig.
+
+have-thread-library = yes
+
+shared-thread-library = $(common-objpfx)nptl/libpthread_nonshared.a \
+ $(common-objpfx)nptl/libpthread.so
+static-thread-library = $(common-objpfx)nptl/libpthread.a
+bounded-thread-library = $(common-objpfx)nptl/libpthread_b.a
+
+rpath-dirs += nptl
diff --git a/libc/nptl/Makefile b/libc/nptl/Makefile
new file mode 100644
index 000000000..3ba647ab7
--- /dev/null
+++ b/libc/nptl/Makefile
@@ -0,0 +1,620 @@
+# Copyright (C) 2002,2003,2004,2005,2006 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# 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.
+
+#
+# Sub-makefile for NPTL portion of the library.
+#
+subdir := nptl
+
+headers := pthread.h semaphore.h bits/semaphore.h
+
+extra-libs := libpthread
+extra-libs-others := $(extra-libs)
+install-lib-ldscripts := libpthread.so
+
+routines = alloca_cutoff forward libc-lowlevellock libc-cancellation
+shared-only-routines = forward
+
+libpthread-routines = init vars events version \
+ pthread_create pthread_exit pthread_detach \
+ pthread_join pthread_tryjoin pthread_timedjoin \
+ pthread_self pthread_equal pthread_yield \
+ pthread_getconcurrency pthread_setconcurrency \
+ pthread_getschedparam pthread_setschedparam \
+ pthread_setschedprio \
+ pthread_attr_init pthread_attr_destroy \
+ pthread_attr_getdetachstate pthread_attr_setdetachstate \
+ pthread_attr_getguardsize pthread_attr_setguardsize \
+ pthread_attr_getschedparam pthread_attr_setschedparam \
+ pthread_attr_getschedpolicy pthread_attr_setschedpolicy \
+ pthread_attr_getinheritsched \
+ pthread_attr_setinheritsched \
+ pthread_attr_getscope pthread_attr_setscope \
+ pthread_attr_getstackaddr pthread_attr_setstackaddr \
+ pthread_attr_getstacksize pthread_attr_setstacksize \
+ pthread_attr_getstack pthread_attr_setstack \
+ pthread_getattr_np \
+ pthread_mutex_init pthread_mutex_destroy \
+ pthread_mutex_lock pthread_mutex_trylock \
+ pthread_mutex_timedlock pthread_mutex_unlock \
+ pthread_mutexattr_init pthread_mutexattr_destroy \
+ pthread_mutexattr_getpshared \
+ pthread_mutexattr_setpshared \
+ pthread_mutexattr_gettype pthread_mutexattr_settype \
+ pthread_rwlock_init pthread_rwlock_destroy \
+ pthread_rwlock_rdlock pthread_rwlock_timedrdlock \
+ pthread_rwlock_wrlock pthread_rwlock_timedwrlock \
+ pthread_rwlock_tryrdlock pthread_rwlock_trywrlock \
+ pthread_rwlock_unlock \
+ pthread_rwlockattr_init pthread_rwlockattr_destroy \
+ pthread_rwlockattr_getpshared \
+ pthread_rwlockattr_setpshared \
+ pthread_rwlockattr_getkind_np \
+ pthread_rwlockattr_setkind_np \
+ pthread_cond_init pthread_cond_destroy \
+ pthread_cond_wait pthread_cond_timedwait \
+ pthread_cond_signal pthread_cond_broadcast \
+ old_pthread_cond_init old_pthread_cond_destroy \
+ old_pthread_cond_wait old_pthread_cond_timedwait \
+ old_pthread_cond_signal old_pthread_cond_broadcast \
+ pthread_condattr_init pthread_condattr_destroy \
+ pthread_condattr_getpshared pthread_condattr_setpshared \
+ pthread_condattr_getclock pthread_condattr_setclock \
+ pthread_spin_init pthread_spin_destroy \
+ pthread_spin_lock pthread_spin_trylock \
+ pthread_spin_unlock \
+ pthread_barrier_init pthread_barrier_destroy \
+ pthread_barrier_wait \
+ pthread_barrierattr_init pthread_barrierattr_destroy \
+ pthread_barrierattr_getpshared \
+ pthread_barrierattr_setpshared \
+ pthread_key_create pthread_key_delete \
+ pthread_getspecific pthread_setspecific \
+ pthread_sigmask pthread_kill \
+ pthread_cancel pthread_testcancel \
+ pthread_setcancelstate pthread_setcanceltype \
+ pthread_once \
+ old_pthread_atfork pthread_atfork \
+ pthread_getcpuclockid \
+ pthread_clock_gettime pthread_clock_settime \
+ sem_init sem_destroy \
+ sem_open sem_close sem_unlink \
+ sem_getvalue \
+ sem_wait sem_trywait sem_timedwait sem_post \
+ cleanup cleanup_defer cleanup_compat \
+ cleanup_defer_compat unwind \
+ pt-longjmp pt-cleanup\
+ cancellation \
+ lowlevellock lowlevelrobustlock \
+ pt-vfork \
+ ptw-write ptw-read ptw-close ptw-fcntl ptw-accept \
+ ptw-connect ptw-recv ptw-recvfrom ptw-recvmsg ptw-send \
+ ptw-sendmsg ptw-sendto ptw-fsync ptw-lseek ptw-llseek \
+ ptw-msync ptw-nanosleep ptw-open ptw-open64 ptw-pause \
+ ptw-pread ptw-pread64 ptw-pwrite ptw-pwrite64 \
+ ptw-tcdrain ptw-wait ptw-waitpid ptw-msgrcv ptw-msgsnd \
+ ptw-sigwait ptw-sigsuspend \
+ pt-raise pt-system \
+ flockfile ftrylockfile funlockfile \
+ sigaction \
+ herrno res pt-allocrtsig \
+ pthread_kill_other_threads \
+ pthread_getaffinity pthread_setaffinity \
+ pthread_attr_getaffinity pthread_attr_setaffinity \
+ pthread_mutexattr_getrobust pthread_mutexattr_setrobust \
+ pthread_mutex_consistent \
+ cleanup_routine unwind-forcedunwind \
+ pthread_mutexattr_getprotocol \
+ pthread_mutexattr_setprotocol \
+ pthread_mutexattr_getprioceiling \
+ pthread_mutexattr_setprioceiling tpp \
+ pthread_mutex_getprioceiling pthread_mutex_setprioceiling
+# pthread_setuid pthread_seteuid pthread_setreuid \
+# pthread_setresuid \
+# pthread_setgid pthread_setegid pthread_setregid \
+# pthread_setresgid
+
+libpthread-shared-only-routines = version pt-allocrtsig unwind-forcedunwind
+libpthread-static-only-routines = 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
+CFLAGS-unwind-forcedunwind.c = -fexceptions -fasynchronous-unwind-tables
+
+# 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
+
+# Among others, __pthread_unwind is forwarded. This function must handle
+# exceptions.
+CFLAGS-forward.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_once.c = $(uses-callbacks) -fexceptions \
+ -fasynchronous-unwind-tables
+CFLAGS-pthread_cond_wait.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-pthread_cond_timedwait.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-sem_wait.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-sem_timedwait.c = -fexceptions -fasynchronous-unwind-tables
+
+# These are the function wrappers we have to duplicate here.
+CFLAGS-fcntl.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-lockf.c = -fexceptions
+CFLAGS-pread.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-pread64.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-pwrite.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-pwrite64.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-wait.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-waitpid.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-sigwait.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-msgrcv.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-msgsnd.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-tcdrain.c = -fexceptions -fasynchronous-unwind-tables
+
+CFLAGS-pt-system.c = -fexceptions
+
+# Don't generate deps for calls with no sources. See sysdeps/unix/Makefile.
+omit-deps = $(unix-syscalls:%=ptw-%)
+
+
+tests = tst-typesizes \
+ tst-attr1 tst-attr2 tst-attr3 \
+ tst-mutex1 tst-mutex2 tst-mutex3 tst-mutex4 tst-mutex5 tst-mutex6 \
+ tst-mutex7 tst-mutex8 tst-mutex9 tst-mutex5a tst-mutex7a \
+ tst-mutexpi1 tst-mutexpi2 tst-mutexpi3 tst-mutexpi4 tst-mutexpi5 \
+ tst-mutexpi5a tst-mutexpi6 tst-mutexpi7 tst-mutexpi7a tst-mutexpi8 \
+ tst-mutexpi9 \
+ tst-spin1 tst-spin2 tst-spin3 \
+ tst-cond1 tst-cond2 tst-cond3 tst-cond4 tst-cond5 tst-cond6 tst-cond7 \
+ tst-cond8 tst-cond9 tst-cond10 tst-cond11 tst-cond12 tst-cond13 \
+ tst-cond14 tst-cond15 tst-cond16 tst-cond17 tst-cond18 tst-cond19 \
+ tst-cond20 tst-cond21 \
+ tst-robust1 tst-robust2 tst-robust3 tst-robust4 tst-robust5 \
+ tst-robust6 tst-robust7 tst-robust8 \
+ tst-robustpi1 tst-robustpi2 tst-robustpi3 tst-robustpi4 \
+ tst-robustpi5 tst-robustpi6 tst-robustpi7 tst-robustpi8 \
+ tst-rwlock1 tst-rwlock2 tst-rwlock3 tst-rwlock4 tst-rwlock5 \
+ tst-rwlock6 tst-rwlock7 tst-rwlock8 tst-rwlock9 tst-rwlock10 \
+ tst-rwlock11 tst-rwlock12 tst-rwlock13 tst-rwlock14 \
+ tst-once1 tst-once2 tst-once3 tst-once4 \
+ tst-key1 tst-key2 tst-key3 tst-key4 \
+ tst-sem1 tst-sem2 tst-sem3 tst-sem4 tst-sem5 tst-sem6 tst-sem7 \
+ tst-sem8 tst-sem9 \
+ tst-barrier1 tst-barrier2 tst-barrier3 tst-barrier4 \
+ tst-align tst-align2 tst-align3 \
+ tst-basic1 tst-basic2 tst-basic3 tst-basic4 tst-basic5 tst-basic6 \
+ tst-kill1 tst-kill2 tst-kill3 tst-kill4 tst-kill5 tst-kill6 \
+ tst-raise1 \
+ tst-join1 tst-join2 tst-join3 tst-join4 tst-join5 tst-join6 \
+ tst-detach1 \
+ tst-eintr1 tst-eintr2 tst-eintr3 tst-eintr4 tst-eintr5 \
+ tst-tsd1 tst-tsd2 tst-tsd3 tst-tsd4 tst-tsd5 \
+ tst-tls1 tst-tls2 \
+ tst-fork1 tst-fork2 tst-fork3 tst-fork4 \
+ 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-cancel12 tst-cancel13 tst-cancel14 tst-cancel15 \
+ tst-cancel16 tst-cancel17 tst-cancel18 tst-cancel19 tst-cancel20 \
+ tst-cancel21 tst-cancel22 tst-cancel23 tst-cancel24 \
+ tst-cleanup0 tst-cleanup1 tst-cleanup2 tst-cleanup3 tst-cleanup4 \
+ tst-flock1 tst-flock2 \
+ tst-signal1 tst-signal2 tst-signal3 tst-signal4 tst-signal5 \
+ tst-signal6 tst-signal7 \
+ tst-exec1 tst-exec2 tst-exec3 tst-exec4 \
+ tst-exit1 tst-exit2 tst-exit3 \
+ tst-stdio1 tst-stdio2 \
+ tst-stack1 tst-stack2 tst-stack3 \
+ tst-unload \
+ tst-dlsym1 \
+ tst-sysconf \
+ tst-locale1 tst-locale2 \
+ tst-umask1 \
+ tst-popen1 \
+ tst-clock1 \
+ tst-context1 \
+ tst-sched1 \
+ tst-backtrace1 \
+ tst-oddstacklimit \
+ tst-vfork1 tst-vfork2 tst-vfork1x tst-vfork2x \
+ tst-getpid1 tst-getpid2 tst-getpid3 \
+ tst-initializers1 $(patsubst %,tst-initializers1-%,c89 gnu89 c99 gnu99)
+xtests = tst-setuid1 tst-setuid1-static tst-mutexpp1 tst-mutexpp6 tst-mutexpp10
+
+# Files which must not be linked with libpthread.
+tests-nolibpthread = tst-unload
+
+# This sets the stack resource limit to 1023kb, which is not a multiple
+# of the page size since every architecture's page size is > 1k.
+tst-oddstacklimit-ENV = ; ulimit -s 1023;
+
+distribute = eintr.c tst-cleanup4aux.c
+
+gen-as-const-headers = pthread-errnos.sym
+
+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-cancelx16 tst-cancelx17 tst-cancelx18 tst-cancelx20 tst-cancelx21 \
+ tst-cleanupx0 tst-cleanupx1 tst-cleanupx2 tst-cleanupx3 tst-cleanupx4 \
+ tst-oncex3 tst-oncex4
+endif
+ifeq ($(build-shared),yes)
+tests += tst-atfork2 tst-tls3 tst-tls4 tst-tls5 tst-_res1 tst-fini1 \
+ tst-stackguard1
+tests-nolibpthread += tst-fini1
+ifeq ($(have-z-execstack),yes)
+tests += tst-execstack
+endif
+endif
+
+modules-names = tst-atfork2mod tst-tls3mod tst-tls4moda tst-tls4modb \
+ tst-tls5mod tst-tls5moda tst-tls5modb tst-tls5modc \
+ tst-tls5modd tst-tls5mode tst-tls5modf \
+ tst-_res1mod1 tst-_res1mod2 tst-execstack-mod tst-fini1mod
+extra-objs += $(addsuffix .os,$(strip $(modules-names))) tst-cleanup4aux.o
+test-extras += $(modules-names)
+test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(modules-names)))
+
+tst-atfork2mod.so-no-z-defs = yes
+tst-tls3mod.so-no-z-defs = yes
+tst-tls5mod.so-no-z-defs = yes
+tst-tls5moda.so-no-z-defs = yes
+tst-tls5modb.so-no-z-defs = yes
+tst-tls5modc.so-no-z-defs = yes
+tst-tls5modd.so-no-z-defs = yes
+tst-tls5mode.so-no-z-defs = yes
+tst-tls5modf.so-no-z-defs = yes
+
+ifeq ($(build-shared),yes)
+# Build all the modules even when not actually running test programs.
+tests: $(test-modules)
+endif
+
+ifeq ($(build-shared),yes)
+
+# Set the `multidir' variable by grabbing the variable from the compiler.
+# We do it once and save the result in a generated makefile.
+-include $(objpfx)multidir.mk
+$(objpfx)multidir.mk: $(common-objpfx)config.make
+ $(make-target-directory)
+ dir=`$(CC) $(CFLAGS) $(CPPFLAGS) -print-multi-directory`; \
+ echo "multidir := $$dir" > $@T
+ mv -f $@T $@
+
+crti-objs := crti.o
+crtn-objs := crtn.o
+ifneq (,$(patsubst .,,$(multidir)))
+generated-dirs := $(firstword $(subst /, , $(multidir)))
+crti-objs += $(multidir)/crti.o
+crtn-objs += $(multidir)/crtn.o
+omit-deps += $(multidir)/crti $(multidir)/crtn
+$(objpfx)$(multidir):
+ mkdir -p $@
+endif
+extra-objs += $(crti-objs) $(crtn-objs)
+omit-deps += crti crtn
+
+CFLAGS-pt-initfini.s = -g0 -fPIC -fno-inline-functions $(fno-unit-at-a-time)
+endif
+
+CFLAGS-flockfile.c = -D_IO_MTSAFE_IO
+CFLAGS-ftrylockfile.c = -D_IO_MTSAFE_IO
+CFLAGS-funlockfile.c = -D_IO_MTSAFE_IO
+
+link-libc-static := $(common-objpfx)libc.a $(static-gnulib) \
+ $(common-objpfx)libc.a
+
+ifeq ($(build-static),yes)
+tests-static += tst-locale1 tst-locale2 tst-stackguard1-static
+tests += tst-stackguard1-static
+xtests-static += tst-setuid1-static
+endif
+# These tests are linked with libc before libpthread
+tests-reverse += tst-cancel5 tst-cancel23 tst-vfork1x tst-vfork2x
+
+include ../Rules
+
+ifeq (yes,$(build-shared))
+# Make sure these things are built in the `make lib' pass so they can be used
+# to run programs during the `make others' pass.
+lib-noranlib: $(addprefix $(objpfx),$(extra-objs))
+
+# What we install as libpthread.so for programs to link against is in fact a
+# link script. It contains references for the various libraries we need.
+# The libpthread.so object is not complete since some functions are only
+# defined in libpthread_nonshared.a.
+# We need to use absolute paths since otherwise local copies (if they exist)
+# of the files are taken by the linker.
+install: $(inst_libdir)/libpthread.so
+
+$(inst_libdir)/libpthread.so: $(common-objpfx)format.lds \
+ $(objpfx)libpthread.so$(libpthread.so-version) \
+ $(inst_libdir)/$(patsubst %,$(libtype.oS),\
+ $(libprefix)pthread) \
+ $(+force)
+ (echo '/* GNU ld script';\
+ echo ' Use the shared library, but some functions are only in';\
+ echo ' the static library, so try that secondarily. */';\
+ cat $<; \
+ echo 'GROUP ( $(slibdir)/libpthread.so$(libpthread.so-version)' \
+ '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)pthread)'\
+ ')' \
+ ) > $@.new
+ mv -f $@.new $@
+endif
+
+
+# 'pthread_self' is a simple memory or register load. Setting up the
+# stack frame is more work than the actual operation. Disable the
+# frame creation entirely. This will help applications which call the
+# function frequently to get a thread-specific handle.
+CFLAGS-pthread_self.os += -fomit-frame-pointer
+
+# 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-cancelx12.c += -fexceptions
+CFLAGS-tst-cancelx13.c += -fexceptions
+CFLAGS-tst-cancelx14.c += -fexceptions
+CFLAGS-tst-cancelx15.c += -fexceptions
+CFLAGS-tst-cancelx16.c += -fexceptions
+CFLAGS-tst-cancelx17.c += -fexceptions
+CFLAGS-tst-cancelx18.c += -fexceptions
+CFLAGS-tst-cancelx20.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-tst-cancelx21.c += -fexceptions -fasynchronous-unwind-tables
+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
+CFLAGS-tst-cleanupx4.c += -fexceptions
+CFLAGS-tst-oncex3.c += -fexceptions
+CFLAGS-tst-oncex4.c += -fexceptions
+CFLAGS-tst-align.c += $(stack-align-test-flags)
+CFLAGS-tst-align3.c += $(stack-align-test-flags)
+CFLAGS-tst-initializers1.c = -W -Wall -Werror
+CFLAGS-tst-initializers1-< = $(CFLAGS-tst-initializers1.c) \
+ $(patsubst tst-initializers1-%.c,-std=%,$<)
+CFLAGS-tst-initializers1-c89.c = $(CFLAGS-tst-initializers1-<)
+CFLAGS-tst-initializers1-c99.c = $(CFLAGS-tst-initializers1-<)
+CFLAGS-tst-initializers1-gnu89.c = $(CFLAGS-tst-initializers1-<)
+CFLAGS-tst-initializers1-gnu99.c = $(CFLAGS-tst-initializers1-<)
+
+tst-cancel7-ARGS = --command "$(built-program-cmd)"
+tst-cancelx7-ARGS = $(tst-cancel7-ARGS)
+tst-umask1-ARGS = $(objpfx)tst-umask1.temp
+
+$(objpfx)tst-atfork2: $(libdl) $(shared-thread-library)
+LDFLAGS-tst-atfork2 = -rdynamic
+tst-atfork2-ENV = MALLOC_TRACE=$(objpfx)tst-atfork2.mtrace
+$(objpfx)tst-atfork2mod.so: $(shared-thread-library)
+
+tests: $(objpfx)tst-stack3-mem
+tst-stack3-ENV = MALLOC_TRACE=$(objpfx)tst-stack3.mtrace
+$(objpfx)tst-stack3-mem: $(objpfx)tst-stack3.out
+ $(common-objpfx)malloc/mtrace $(objpfx)tst-stack3.mtrace > $@
+generated += tst-stack3-mem tst-stack3.mtrace
+
+$(objpfx)tst-cleanup4: $(objpfx)tst-cleanup4aux.o $(shared-thread-library)
+$(objpfx)tst-cleanupx4: $(objpfx)tst-cleanup4aux.o $(shared-thread-library)
+
+$(objpfx)tst-tls3: $(libdl) $(shared-thread-library)
+LDFLAGS-tst-tls3 = -rdynamic
+$(objpfx)tst-tls3.out: $(objpfx)tst-tls3mod.so
+$(objpfx)tst-tls3mod.so: $(shared-thread-library)
+
+$(objpfx)tst-tls4: $(libdl) $(shared-thread-library)
+$(objpfx)tst-tls4.out: $(objpfx)tst-tls4moda.so $(objpfx)tst-tls4modb.so
+
+$(objpfx)tst-tls5: $(objpfx)tst-tls5mod.so $(shared-thread-library)
+LDFLAGS-tst-tls5mod.so = -Wl,-soname,tst-tls5mod.so
+
+ifeq ($(build-shared),yes)
+tests: $(objpfx)tst-tls6.out
+$(objpfx)tst-tls6.out: tst-tls6.sh $(objpfx)tst-tls5 \
+ $(objpfx)tst-tls5moda.so $(objpfx)tst-tls5modb.so \
+ $(objpfx)tst-tls5modc.so $(objpfx)tst-tls5modd.so \
+ $(objpfx)tst-tls5mode.so $(objpfx)tst-tls5modf.so
+ $(SHELL) -e tst-tls6.sh $(common-objpfx) $(elf-objpfx) \
+ $(rtld-installed-name)
+endif
+
+$(objpfx)tst-dlsym1: $(libdl) $(shared-thread-library)
+
+$(objpfx)tst-fini1: $(shared-thread-library) $(objpfx)tst-fini1mod.so
+
+ifeq (yes,$(build-shared))
+$(objpfx)tst-cond11: $(common-objpfx)rt/librt.so
+$(objpfx)tst-cond19: $(common-objpfx)rt/librt.so
+$(objpfx)tst-cancel17: $(common-objpfx)rt/librt.so
+$(objpfx)tst-cancelx17: $(common-objpfx)rt/librt.so
+$(objpfx)tst-cancel18: $(common-objpfx)rt/librt.so
+$(objpfx)tst-cancelx18: $(common-objpfx)rt/librt.so
+$(objpfx)tst-clock2: $(common-objpfx)rt/librt.so
+$(objpfx)tst-rwlock14: $(common-objpfx)rt/librt.so
+$(objpfx)tst-_res1mod2.so: $(objpfx)tst-_res1mod1.so
+LDFLAGS-tst-_res1mod1.so = -Wl,-soname,tst-_res1mod1.so
+LDFLAGS-tst-_res1mod2.so = -Wl,-soname,tst-_res1mod2.so
+$(objpfx)tst-_res1: $(objpfx)tst-_res1mod2.so $(shared-thread-library)
+else
+$(objpfx)tst-cond11: $(common-objpfx)rt/librt.a
+$(objpfx)tst-cond19: $(common-objpfx)rt/librt.a
+$(objpfx)tst-cancel17: $(common-objpfx)rt/librt.a
+$(objpfx)tst-cancelx17: $(common-objpfx)rt/librt.a
+$(objpfx)tst-cancel18: $(common-objpfx)rt/librt.a
+$(objpfx)tst-cancelx18: $(common-objpfx)rt/librt.a
+$(objpfx)tst-clock2: $(common-objpfx)rt/librt.a
+$(objpfx)tst-rwlock14: $(common-objpfx)rt/librt.a
+endif
+
+LDFLAGS-tst-cancel24 = -lstdc++
+
+extra-B-pthread.so = -B$(common-objpfx)nptl/
+$(objpfx)libpthread.so: $(addprefix $(objpfx),$(crti-objs) $(crtn-objs))
+$(objpfx)libpthread.so: +preinit += $(addprefix $(objpfx),$(crti-objs))
+$(objpfx)libpthread.so: +postinit += $(addprefix $(objpfx),$(crtn-objs))
+
+# Depend on libc.so so a DT_NEEDED is generated in the shared objects.
+# This ensures they will load libc.so for needed symbols if loaded by
+# a statically-linked program that hasn't already loaded it.
+# Depend on ld.so too to get proper versions of ld.so symbols.
+$(objpfx)libpthread.so: $(common-objpfx)libc.so \
+ $(common-objpfx)libc_nonshared.a \
+ $(if $(filter yes,$(elf)), $(elfobjdir)/ld.so)
+
+# Make sure we link with the thread library.
+ifeq ($(build-shared),yes)
+$(addprefix $(objpfx), \
+ $(filter-out $(tests-static) $(xtests-static) $(tests-reverse) \
+ $(tests-nolibpthread), \
+ $(tests) $(xtests) $(test-srcs))): $(objpfx)libpthread.so \
+ $(objpfx)libpthread_nonshared.a
+$(objpfx)tst-unload: $(common-objpfx)dlfcn/libdl.so
+# $(objpfx)../libc.so is used instead of $(common-objpfx)libc.so,
+# since otherwise libpthread.so comes before libc.so when linking.
+$(addprefix $(objpfx), $(tests-reverse)): \
+ $(objpfx)../libc.so $(objpfx)libpthread.so \
+ $(objpfx)libpthread_nonshared.a
+$(objpfx)../libc.so: $(common-objpfx)libc.so ;
+$(addprefix $(objpfx),$(tests-static) $(xtests-static)): $(objpfx)libpthread.a
+
+$(objpfx)tst-atfork2.out: $(objpfx)tst-atfork2mod.so
+else
+$(addprefix $(objpfx),$(tests) $(test-srcs)): $(objpfx)libpthread.a
+endif
+
+ifeq ($(build-shared),yes)
+vpath pt-initfini.c $(sysdirs)
+
+$(objpfx)pt-initfini.s: pt-initfini.c
+ $(compile.c) -S $(CFLAGS-pt-initfini.s) -finhibit-size-directive \
+ $(patsubst -f%,-fno-%,$(exceptions)) -o $@
+
+$(objpfx)tst-cleanup0.out: /dev/null $(objpfx)tst-cleanup0
+ $(make-test-out) 2>&1 | cmp - tst-cleanup0.expect >& $@
+
+# We only have one kind of startup code files. Static binaries and
+# shared libraries are build using the PIC version.
+$(objpfx)crti.S: $(objpfx)pt-initfini.s
+ sed -n -e '1,/@HEADER_ENDS/p' \
+ -e '/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \
+ -e '/@TRAILER_BEGINS/,$$p' $< > $@
+$(objpfx)crtn.S: $(objpfx)pt-initfini.s
+ sed -n -e '1,/@HEADER_ENDS/p' \
+ -e '/@_.*_EPILOG_BEGINS/,/@_.*_EPILOG_ENDS/p' \
+ -e '/@TRAILER_BEGINS/,$$p' $< > $@
+
+$(objpfx)defs.h: $(objpfx)pt-initfini.s
+ sed -n -e '/@TESTS_BEGIN/,/@TESTS_END/p' $< | \
+ $(AWK) -f ../csu/defs.awk > $@
+
+$(objpfx)crti.o: $(objpfx)crti.S $(objpfx)defs.h
+ $(compile.S) -g0 $(ASFLAGS-.os) -o $@
+
+$(objpfx)crtn.o: $(objpfx)crtn.S $(objpfx)defs.h
+ $(compile.S) -g0 $(ASFLAGS-.os) -o $@
+
+ifneq ($(multidir),.)
+$(objpfx)$(multidir)/crti.o: $(objpfx)crti.o $(objpfx)$(multidir)/
+ ln -f $< $@
+
+$(objpfx)$(multidir)/crtn.o: $(objpfx)crtn.o $(objpfx)$(multidir)/
+ ln -f $< $@
+endif
+
+generated += crti.S crtn.S defs.h pt-initfini.s libpthread_nonshared.a \
+ multidir.mk tst-atfork2.mtrace tst-cancel-wrappers.out \
+ tst-tls6.out
+
+generated += $(objpfx)tst-atfork2.mtrace \
+ $(addsuffix .so,$(strip $(modules-names)))
+
+$(objpfx)version.d: $(objpfx)banner.h
+$(objpfx)version.os: $(objpfx)banner.h
+$(objpfx)banner.h: Banner
+ sed 's/\(.*\)/"\1\\n"/' $< > $@
+generated += banner.h
+# Give libpthread.so an entry point and make it directly runnable itself.
+LDFLAGS-pthread.so += -e __nptl_main
+endif
+
+ifeq (no,$(cross-compiling))
+ifeq (yes,$(build-shared))
+tests: $(objpfx)tst-cancel-wrappers.out
+$(objpfx)tst-cancel-wrappers.out: tst-cancel-wrappers.sh
+ $(SHELL) $< $(common-objpfx)libc_pic.a \
+ $(common-objpfx)libc.a \
+ $(objpfx)libpthread_pic.a \
+ $(objpfx)libpthread.a > $@
+endif
+endif
+
+tst-exec4-ARGS = $(built-program-cmd)
+
+$(objpfx)tst-execstack: $(libdl)
+$(objpfx)tst-execstack.out: $(objpfx)tst-execstack-mod.so
+LDFLAGS-tst-execstack = -Wl,-z,noexecstack
+
+$(objpfx)tst-fini1mod.so: $(shared-thread-library)
+
+tst-stackguard1-ARGS = --command "$(built-program-cmd) --child"
+tst-stackguard1-static-ARGS = --command "$(objpfx)tst-stackguard1-static --child"
+
+# The tests here better do not run in parallel
+ifneq ($(filter %tests,$(MAKECMDGOALS)),)
+.NOTPARALLEL:
+endif
diff --git a/libc/nptl/TODO b/libc/nptl/TODO
new file mode 100644
index 000000000..d59717651
--- /dev/null
+++ b/libc/nptl/TODO
@@ -0,0 +1,16 @@
+- we should probably extend pthread_mutexattr_t with a field to create a
+ single linked list of all instances. This requires changing the
+ pthread_mutexattr_* functions.
+
+
+- a new attribute for mutexes: number of times we spin before calling
+sys_futex
+
+- for adaptive mutexes: when releasing, determine whether somebody spins.
+If yes, for a short time release lock. If someone else locks no wakeup
+syscall needed.
+
+
+
+- test with threaded process terminating and semadj (?) being applied
+ only after all threads are gone
diff --git a/libc/nptl/TODO-kernel b/libc/nptl/TODO-kernel
new file mode 100644
index 000000000..ad6d2a4b5
--- /dev/null
+++ b/libc/nptl/TODO-kernel
@@ -0,0 +1,20 @@
+- setuid/setgid must effect process
+ + test syscalls (getuid) afterwards
+ + test core file content
+
+ + use UID/GID in access(2), chmod(2), chown(2), link(2)
+
+- nice level is process property
+
+- rlimit should be process-wide and SIGXCPU should be sent if all threads
+ together exceed the limit
+
+- getrusage() must return resource utilization for the process
+
+
+
+The following are possible optimizations and in no way required:
+
+
+- the scheduler should be thread group-aware, i.e., it has to give time to
+ the thread group not proportional to the number of threads.
diff --git a/libc/nptl/TODO-testing b/libc/nptl/TODO-testing
new file mode 100644
index 000000000..e076e5624
--- /dev/null
+++ b/libc/nptl/TODO-testing
@@ -0,0 +1,20 @@
+pthread_attr_setguardsize
+
+ test effectiveness
+
+pthread_attr_[sg]etschedparam
+
+ what to test?
+
+pthread_attr_[sg]etstack
+
+ some more tests needed
+
+pthread_getcpuclockid
+
+ check that value is reset -> rt subdir
+
+pthread_getschedparam
+pthread_setschedparam
+
+ what to test?
diff --git a/libc/nptl/Versions b/libc/nptl/Versions
new file mode 100644
index 000000000..54b9b9c6a
--- /dev/null
+++ b/libc/nptl/Versions
@@ -0,0 +1,248 @@
+libc {
+ GLIBC_2.0 {
+ pthread_attr_destroy; pthread_attr_init;
+ pthread_attr_getdetachstate; pthread_attr_setdetachstate;
+ pthread_attr_getinheritsched; pthread_attr_setinheritsched;
+ pthread_attr_getschedparam; pthread_attr_setschedparam;
+ pthread_attr_getschedpolicy; pthread_attr_setschedpolicy;
+ pthread_attr_getscope; pthread_attr_setscope;
+ pthread_condattr_destroy; pthread_condattr_init;
+ pthread_cond_broadcast; pthread_cond_destroy;
+ pthread_cond_init; pthread_cond_signal; pthread_cond_wait;
+ pthread_cond_timedwait;
+ pthread_equal; pthread_exit;
+ pthread_getschedparam; pthread_setschedparam;
+ pthread_mutex_destroy; pthread_mutex_init;
+ pthread_mutex_lock; pthread_mutex_unlock;
+ pthread_self;
+ pthread_setcancelstate; pthread_setcanceltype;
+ }
+ GLIBC_2.1 {
+ pthread_attr_init;
+ }
+ GLIBC_2.3.2 {
+ # Changed pthread_cond_t.
+ pthread_cond_init; pthread_cond_destroy;
+ pthread_cond_wait; pthread_cond_signal;
+ pthread_cond_broadcast; pthread_cond_timedwait;
+ }
+ GLIBC_PRIVATE {
+ # Internal libc interface to libpthread
+ __libc_dl_error_tsd;
+ }
+}
+
+libpthread {
+ GLIBC_2.0 {
+ pthread_create; pthread_join; pthread_self; pthread_equal;
+ pthread_exit; pthread_detach;
+
+ pthread_getschedparam; pthread_setschedparam;
+
+ pthread_attr_init; pthread_attr_destroy;
+ pthread_attr_getdetachstate; pthread_attr_setdetachstate;
+ pthread_attr_getschedparam; pthread_attr_setschedparam;
+ pthread_attr_getschedpolicy; pthread_attr_setschedpolicy;
+ pthread_attr_getinheritsched; pthread_attr_setinheritsched;
+ pthread_attr_getscope; pthread_attr_setscope;
+
+ pthread_mutex_init; pthread_mutex_destroy;
+ pthread_mutex_lock; pthread_mutex_trylock; pthread_mutex_unlock;
+
+ pthread_mutexattr_init; pthread_mutexattr_destroy;
+
+ pthread_cond_init; pthread_cond_destroy;
+ pthread_cond_wait; pthread_cond_timedwait;
+ pthread_cond_signal; pthread_cond_broadcast;
+
+ pthread_condattr_destroy; pthread_condattr_init;
+
+ pthread_cancel; pthread_testcancel;
+ pthread_setcancelstate; pthread_setcanceltype;
+
+ pthread_sigmask; pthread_kill;
+
+ pthread_key_create; pthread_key_delete;
+ pthread_getspecific; pthread_setspecific;
+
+ pthread_once;
+
+ pthread_atfork;
+
+ flockfile; funlockfile; ftrylockfile;
+
+ # Non-standard POSIX1.x functions.
+ pthread_mutexattr_getkind_np; pthread_mutexattr_setkind_np;
+
+ # Protected names for functions used in other shared objects.
+ __pthread_mutex_init; __pthread_mutex_destroy;
+ __pthread_mutex_lock; __pthread_mutex_trylock; __pthread_mutex_unlock;
+ __pthread_mutexattr_init; __pthread_mutexattr_destroy;
+ __pthread_mutexattr_settype;
+ __pthread_key_create; __pthread_getspecific; __pthread_setspecific;
+ __pthread_once; __pthread_atfork;
+ _IO_flockfile; _IO_ftrylockfile; _IO_funlockfile;
+
+ # Hidden entry point (through macros).
+ #_pthread_cleanup_pop; _pthread_cleanup_pop_restore; _pthread_cleanup_push;
+ #_pthread_cleanup_push_defer;
+
+ # Semaphores.
+ sem_destroy; sem_getvalue; sem_init; sem_post; sem_trywait; sem_wait;
+
+ # Special fork handling.
+ fork; __fork; vfork;
+
+ # Cancellation points.
+ close; __close; fcntl; __fcntl; read; __read; write; __write; accept;
+ connect; __connect; recv; recvfrom; recvmsg; send; __send; sendmsg; sendto;
+ fsync; lseek; __lseek; msync; nanosleep; open; __open; pause; tcdrain;
+ system; wait; __wait; waitpid;
+
+ # Hidden entry point (through macros).
+ _pthread_cleanup_push; _pthread_cleanup_pop;
+ _pthread_cleanup_push_defer; _pthread_cleanup_pop_restore;
+
+ pthread_kill_other_threads_np;
+
+ # The error functions.
+ __errno_location; __h_errno_location;
+
+ # Functions which previously have been overwritten.
+ sigwait; sigaction; __sigaction; _exit; _Exit; longjmp; siglongjmp;
+ raise;
+ }
+
+ GLIBC_2.1 {
+ pthread_create;
+ pthread_attr_init;
+
+ pthread_attr_getguardsize; pthread_attr_setguardsize;
+ pthread_attr_getstackaddr; pthread_attr_setstackaddr;
+ pthread_attr_getstacksize; pthread_attr_setstacksize;
+
+ pthread_mutexattr_gettype; pthread_mutexattr_settype;
+
+ pthread_rwlock_init; pthread_rwlock_destroy;
+ pthread_rwlock_rdlock; pthread_rwlock_wrlock; pthread_rwlock_unlock;
+ pthread_rwlock_tryrdlock; pthread_rwlock_trywrlock;
+
+ pthread_rwlockattr_init; pthread_rwlockattr_destroy;
+ pthread_rwlockattr_getpshared; pthread_rwlockattr_setpshared;
+ pthread_rwlockattr_getkind_np; pthread_rwlockattr_setkind_np;
+
+ pthread_getconcurrency; pthread_setconcurrency;
+
+ # Semaphores.
+ sem_destroy; sem_getvalue; sem_init; sem_post; sem_trywait; sem_wait;
+
+ __libc_current_sigrtmin; __libc_current_sigrtmax;
+ __libc_allocate_rtsig;
+ }
+
+ GLIBC_2.1.1 {
+ sem_close; sem_open; sem_unlink;
+ }
+
+ GLIBC_2.1.2 {
+ __vfork;
+ }
+
+ GLIBC_2.2 {
+ pthread_mutexattr_getpshared; pthread_mutexattr_setpshared;
+
+ pthread_condattr_getpshared; pthread_condattr_setpshared;
+
+ # New functions from IEEE Std. 1003.1-2001.
+ pthread_mutex_timedlock;
+
+ pthread_rwlock_timedrdlock; pthread_rwlock_timedwrlock;
+
+ pthread_attr_getstack; pthread_attr_setstack;
+
+ pthread_spin_destroy; pthread_spin_init; pthread_spin_lock;
+ pthread_spin_trylock; pthread_spin_unlock;
+
+ pthread_barrier_init; pthread_barrier_destroy; pthread_barrier_wait;
+ pthread_barrierattr_destroy; pthread_barrierattr_init;
+ pthread_barrierattr_setpshared;
+
+ sem_timedwait;
+
+ pthread_yield;
+
+ pthread_getcpuclockid;
+
+ # Cancellation points.
+ lseek64; open64; __open64; pread; pread64; __pread64; pwrite; pwrite64;
+ __pwrite64;
+
+ # Names used internally.
+ __pthread_rwlock_init; __pthread_rwlock_destroy;
+ __pthread_rwlock_rdlock; __pthread_rwlock_tryrdlock;
+ __pthread_rwlock_wrlock; __pthread_rwlock_trywrlock;
+ __pthread_rwlock_unlock;
+
+ __res_state;
+ }
+
+ GLIBC_2.2.3 {
+ # Extensions.
+ pthread_getattr_np;
+ }
+
+ GLIBC_2.2.6 {
+ # Cancellation wrapper
+ __nanosleep;
+ }
+
+ GLIBC_2.3.2 {
+ # Changed pthread_cond_t.
+ pthread_cond_init; pthread_cond_destroy;
+ pthread_cond_wait; pthread_cond_timedwait;
+ pthread_cond_signal; pthread_cond_broadcast;
+ }
+
+ GLIBC_2.3.3 {
+ # 1003.1-2001 function accidentally left out in 2.2.
+ pthread_barrierattr_getpshared;
+
+ # Unix CS option.
+ pthread_condattr_getclock; pthread_condattr_setclock;
+
+ # Proposed API extensions.
+ pthread_tryjoin_np; pthread_timedjoin_np;
+
+ # New cancellation cleanup handling.
+ __pthread_register_cancel; __pthread_unregister_cancel;
+ __pthread_register_cancel_defer; __pthread_unregister_cancel_restore;
+ __pthread_unwind_next;
+ __pthread_cleanup_routine;
+
+ # affinity interfaces without size parameter
+ pthread_getaffinity_np; pthread_setaffinity_np;
+ pthread_attr_getaffinity_np; pthread_attr_setaffinity_np;
+ }
+
+ GLIBC_2.3.4 {
+ # New affinity interfaces.
+ pthread_getaffinity_np; pthread_setaffinity_np;
+ pthread_attr_getaffinity_np; pthread_attr_setaffinity_np;
+
+ pthread_setschedprio;
+ }
+
+ GLIBC_2.4 {
+ pthread_mutexattr_getrobust_np; pthread_mutexattr_setrobust_np;
+ pthread_mutex_consistent_np;
+ pthread_mutexattr_getprotocol; pthread_mutexattr_setprotocol;
+ pthread_mutexattr_getprioceiling; pthread_mutexattr_setprioceiling;
+ pthread_mutex_getprioceiling; pthread_mutex_setprioceiling;
+ };
+
+ GLIBC_PRIVATE {
+ __pthread_initialize_minimal;
+ __pthread_clock_gettime; __pthread_clock_settime;
+ __pthread_unwind;
+ }
+}
diff --git a/libc/nptl/alloca_cutoff.c b/libc/nptl/alloca_cutoff.c
new file mode 100644
index 000000000..ba26ceba3
--- /dev/null
+++ b/libc/nptl/alloca_cutoff.c
@@ -0,0 +1,36 @@
+/* Determine whether block of given size can be allocated on the stack or not.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <alloca.h>
+#include <stdlib.h>
+#include <sys/param.h>
+#include <pthreadP.h>
+
+
+int
+__libc_alloca_cutoff (size_t size)
+{
+ return size <= (MIN (__MAX_ALLOCA_CUTOFF,
+ THREAD_GETMEM (THREAD_SELF, stackblock_size) / 4
+ /* The main thread, before the thread library is
+ initialized, has zero in the stackblock_size
+ element. Since it is the main thread we can
+ assume the maximum available stack space. */
+ ?: __MAX_ALLOCA_CUTOFF * 4));
+}
diff --git a/libc/nptl/allocatestack.c b/libc/nptl/allocatestack.c
new file mode 100644
index 000000000..4a1cd1848
--- /dev/null
+++ b/libc/nptl/allocatestack.c
@@ -0,0 +1,970 @@
+/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include <errno.h>
+#include <signal.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/param.h>
+#include <dl-sysdep.h>
+#include <tls.h>
+#include <lowlevellock.h>
+
+
+#ifndef NEED_SEPARATE_REGISTER_STACK
+
+/* Most architectures have exactly one stack pointer. Some have more. */
+# define STACK_VARIABLES void *stackaddr = NULL
+
+/* How to pass the values to the 'create_thread' function. */
+# define STACK_VARIABLES_ARGS stackaddr
+
+/* How to declare function which gets there parameters. */
+# define STACK_VARIABLES_PARMS void *stackaddr
+
+/* How to declare allocate_stack. */
+# define ALLOCATE_STACK_PARMS void **stack
+
+/* This is how the function is called. We do it this way to allow
+ other variants of the function to have more parameters. */
+# define ALLOCATE_STACK(attr, pd) allocate_stack (attr, pd, &stackaddr)
+
+#else
+
+/* We need two stacks. The kernel will place them but we have to tell
+ the kernel about the size of the reserved address space. */
+# define STACK_VARIABLES void *stackaddr = NULL; size_t stacksize = 0
+
+/* How to pass the values to the 'create_thread' function. */
+# define STACK_VARIABLES_ARGS stackaddr, stacksize
+
+/* How to declare function which gets there parameters. */
+# define STACK_VARIABLES_PARMS void *stackaddr, size_t stacksize
+
+/* How to declare allocate_stack. */
+# define ALLOCATE_STACK_PARMS void **stack, size_t *stacksize
+
+/* This is how the function is called. We do it this way to allow
+ other variants of the function to have more parameters. */
+# define ALLOCATE_STACK(attr, pd) \
+ allocate_stack (attr, pd, &stackaddr, &stacksize)
+
+#endif
+
+
+/* Default alignment of stack. */
+#ifndef STACK_ALIGN
+# define STACK_ALIGN __alignof__ (long double)
+#endif
+
+/* Default value for minimal stack size after allocating thread
+ descriptor and guard. */
+#ifndef MINIMAL_REST_STACK
+# define MINIMAL_REST_STACK 4096
+#endif
+
+
+/* Let the architecture add some flags to the mmap() call used to
+ allocate stacks. */
+#ifndef ARCH_MAP_FLAGS
+# define ARCH_MAP_FLAGS 0
+#endif
+
+/* This yields the pointer that TLS support code calls the thread pointer. */
+#if TLS_TCB_AT_TP
+# define TLS_TPADJ(pd) (pd)
+#elif TLS_DTV_AT_TP
+# define TLS_TPADJ(pd) ((struct pthread *)((char *) (pd) + TLS_PRE_TCB_SIZE))
+#endif
+
+/* Cache handling for not-yet free stacks. */
+
+/* Maximum size in kB of cache. */
+static size_t stack_cache_maxsize = 40 * 1024 * 1024; /* 40MiBi by default. */
+static size_t stack_cache_actsize;
+
+/* Mutex protecting this variable. */
+static lll_lock_t stack_cache_lock = LLL_LOCK_INITIALIZER;
+
+/* List of queued stack frames. */
+static LIST_HEAD (stack_cache);
+
+/* List of the stacks in use. */
+static LIST_HEAD (stack_used);
+
+/* List of the threads with user provided stacks in use. No need to
+ initialize this, since it's done in __pthread_initialize_minimal. */
+list_t __stack_user __attribute__ ((nocommon));
+hidden_data_def (__stack_user)
+
+#if COLORING_INCREMENT != 0
+/* Number of threads created. */
+static unsigned int nptl_ncreated;
+#endif
+
+
+/* Check whether the stack is still used or not. */
+#define FREE_P(descr) ((descr)->tid <= 0)
+
+
+/* We create a double linked list of all cache entries. Double linked
+ because this allows removing entries from the end. */
+
+
+/* Get a stack frame from the cache. We have to match by size since
+ some blocks might be too small or far too large. */
+static struct pthread *
+get_cached_stack (size_t *sizep, void **memp)
+{
+ size_t size = *sizep;
+ struct pthread *result = NULL;
+ list_t *entry;
+
+ lll_lock (stack_cache_lock);
+
+ /* Search the cache for a matching entry. We search for the
+ smallest stack which has at least the required size. Note that
+ in normal situations the size of all allocated stacks is the
+ same. As the very least there are only a few different sizes.
+ Therefore this loop will exit early most of the time with an
+ exact match. */
+ list_for_each (entry, &stack_cache)
+ {
+ struct pthread *curr;
+
+ curr = list_entry (entry, struct pthread, list);
+ if (FREE_P (curr) && curr->stackblock_size >= size)
+ {
+ if (curr->stackblock_size == size)
+ {
+ result = curr;
+ break;
+ }
+
+ if (result == NULL
+ || result->stackblock_size > curr->stackblock_size)
+ result = curr;
+ }
+ }
+
+ if (__builtin_expect (result == NULL, 0)
+ /* Make sure the size difference is not too excessive. In that
+ case we do not use the block. */
+ || __builtin_expect (result->stackblock_size > 4 * size, 0))
+ {
+ /* Release the lock. */
+ lll_unlock (stack_cache_lock);
+
+ return NULL;
+ }
+
+ /* Dequeue the entry. */
+ list_del (&result->list);
+
+ /* And add to the list of stacks in use. */
+ list_add (&result->list, &stack_used);
+
+ /* And decrease the cache size. */
+ stack_cache_actsize -= result->stackblock_size;
+
+ /* Release the lock early. */
+ lll_unlock (stack_cache_lock);
+
+ /* Report size and location of the stack to the caller. */
+ *sizep = result->stackblock_size;
+ *memp = result->stackblock;
+
+ /* Cancellation handling is back to the default. */
+ result->cancelhandling = 0;
+ result->cleanup = NULL;
+
+ /* No pending event. */
+ result->nextevent = NULL;
+
+ /* Clear the DTV. */
+ dtv_t *dtv = GET_DTV (TLS_TPADJ (result));
+ memset (dtv, '\0', (dtv[-1].counter + 1) * sizeof (dtv_t));
+
+ /* Re-initialize the TLS. */
+ _dl_allocate_tls_init (TLS_TPADJ (result));
+
+ return result;
+}
+
+
+/* Add a stack frame which is not used anymore to the stack. Must be
+ called with the cache lock held. */
+static inline void
+__attribute ((always_inline))
+queue_stack (struct pthread *stack)
+{
+ /* We unconditionally add the stack to the list. The memory may
+ still be in use but it will not be reused until the kernel marks
+ the stack as not used anymore. */
+ list_add (&stack->list, &stack_cache);
+
+ stack_cache_actsize += stack->stackblock_size;
+ if (__builtin_expect (stack_cache_actsize > stack_cache_maxsize, 0))
+ {
+ /* We reduce the size of the cache. Remove the last entries
+ until the size is below the limit. */
+ list_t *entry;
+ list_t *prev;
+
+ /* Search from the end of the list. */
+ list_for_each_prev_safe (entry, prev, &stack_cache)
+ {
+ struct pthread *curr;
+
+ curr = list_entry (entry, struct pthread, list);
+ if (FREE_P (curr))
+ {
+ /* Unlink the block. */
+ list_del (entry);
+
+ /* Account for the freed memory. */
+ stack_cache_actsize -= curr->stackblock_size;
+
+ /* Free the memory associated with the ELF TLS. */
+ _dl_deallocate_tls (TLS_TPADJ (curr), false);
+
+ /* Remove this block. This should never fail. If it
+ does something is really wrong. */
+ if (munmap (curr->stackblock, curr->stackblock_size) != 0)
+ abort ();
+
+ /* Maybe we have freed enough. */
+ if (stack_cache_actsize <= stack_cache_maxsize)
+ break;
+ }
+ }
+ }
+}
+
+
+static int
+internal_function
+change_stack_perm (struct pthread *pd
+#ifdef NEED_SEPARATE_REGISTER_STACK
+ , size_t pagemask
+#endif
+ )
+{
+#ifdef NEED_SEPARATE_REGISTER_STACK
+ void *stack = (pd->stackblock
+ + (((((pd->stackblock_size - pd->guardsize) / 2)
+ & pagemask) + pd->guardsize) & pagemask));
+ size_t len = pd->stackblock + pd->stackblock_size - stack;
+#else
+ void *stack = pd->stackblock + pd->guardsize;
+ size_t len = pd->stackblock_size - pd->guardsize;
+#endif
+ if (mprotect (stack, len, PROT_READ | PROT_WRITE | PROT_EXEC) != 0)
+ return errno;
+
+ return 0;
+}
+
+
+static int
+allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
+ ALLOCATE_STACK_PARMS)
+{
+ struct pthread *pd;
+ size_t size;
+ size_t pagesize_m1 = __getpagesize () - 1;
+ void *stacktop;
+
+ assert (attr != NULL);
+ assert (powerof2 (pagesize_m1 + 1));
+ assert (TCB_ALIGNMENT >= STACK_ALIGN);
+
+ /* Get the stack size from the attribute if it is set. Otherwise we
+ use the default we determined at start time. */
+ size = attr->stacksize ?: __default_stacksize;
+
+ /* Get memory for the stack. */
+ if (__builtin_expect (attr->flags & ATTR_FLAG_STACKADDR, 0))
+ {
+ uintptr_t adj;
+
+ /* If the user also specified the size of the stack make sure it
+ is large enough. */
+ if (attr->stacksize != 0
+ && attr->stacksize < (__static_tls_size + MINIMAL_REST_STACK))
+ return EINVAL;
+
+ /* Adjust stack size for alignment of the TLS block. */
+#if TLS_TCB_AT_TP
+ adj = ((uintptr_t) attr->stackaddr - TLS_TCB_SIZE)
+ & __static_tls_align_m1;
+ assert (size > adj + TLS_TCB_SIZE);
+#elif TLS_DTV_AT_TP
+ adj = ((uintptr_t) attr->stackaddr - __static_tls_size)
+ & __static_tls_align_m1;
+ assert (size > adj);
+#endif
+
+ /* The user provided some memory. Let's hope it matches the
+ size... We do not allocate guard pages if the user provided
+ the stack. It is the user's responsibility to do this if it
+ is wanted. */
+#if TLS_TCB_AT_TP
+ pd = (struct pthread *) ((uintptr_t) attr->stackaddr
+ - TLS_TCB_SIZE - adj);
+#elif TLS_DTV_AT_TP
+ pd = (struct pthread *) (((uintptr_t) attr->stackaddr
+ - __static_tls_size - adj)
+ - TLS_PRE_TCB_SIZE);
+#endif
+
+ /* The user provided stack memory needs to be cleared. */
+ memset (pd, '\0', sizeof (struct pthread));
+
+ /* The first TSD block is included in the TCB. */
+ pd->specific[0] = pd->specific_1stblock;
+
+ /* Remember the stack-related values. */
+ pd->stackblock = (char *) attr->stackaddr - size;
+ pd->stackblock_size = size;
+
+ /* This is a user-provided stack. It will not be queued in the
+ stack cache nor will the memory (except the TLS memory) be freed. */
+ pd->user_stack = true;
+
+ /* This is at least the second thread. */
+ pd->header.multiple_threads = 1;
+#ifndef TLS_MULTIPLE_THREADS_IN_TCB
+ __pthread_multiple_threads = *__libc_multiple_threads_ptr = 1;
+#endif
+
+#ifdef NEED_DL_SYSINFO
+ /* Copy the sysinfo value from the parent. */
+ THREAD_SYSINFO(pd) = THREAD_SELF_SYSINFO;
+#endif
+
+ /* The process ID is also the same as that of the caller. */
+ pd->pid = THREAD_GETMEM (THREAD_SELF, pid);
+
+ /* Allocate the DTV for this thread. */
+ if (_dl_allocate_tls (TLS_TPADJ (pd)) == NULL)
+ {
+ /* Something went wrong. */
+ assert (errno == ENOMEM);
+ return EAGAIN;
+ }
+
+
+ /* Prepare to modify global data. */
+ lll_lock (stack_cache_lock);
+
+ /* And add to the list of stacks in use. */
+ list_add (&pd->list, &__stack_user);
+
+ lll_unlock (stack_cache_lock);
+ }
+ else
+ {
+ /* Allocate some anonymous memory. If possible use the cache. */
+ size_t guardsize;
+ size_t reqsize;
+ void *mem;
+ const int prot = (PROT_READ | PROT_WRITE
+ | ((GL(dl_stack_flags) & PF_X) ? PROT_EXEC : 0));
+
+#if COLORING_INCREMENT != 0
+ /* Add one more page for stack coloring. Don't do it for stacks
+ with 16 times pagesize or larger. This might just cause
+ unnecessary misalignment. */
+ if (size <= 16 * pagesize_m1)
+ size += pagesize_m1 + 1;
+#endif
+
+ /* Adjust the stack size for alignment. */
+ size &= ~__static_tls_align_m1;
+ assert (size != 0);
+
+ /* Make sure the size of the stack is enough for the guard and
+ eventually the thread descriptor. */
+ guardsize = (attr->guardsize + pagesize_m1) & ~pagesize_m1;
+ if (__builtin_expect (size < ((guardsize + __static_tls_size
+ + MINIMAL_REST_STACK + pagesize_m1)
+ & ~pagesize_m1),
+ 0))
+ /* The stack is too small (or the guard too large). */
+ return EINVAL;
+
+ /* Try to get a stack from the cache. */
+ reqsize = size;
+ pd = get_cached_stack (&size, &mem);
+ if (pd == NULL)
+ {
+ /* To avoid aliasing effects on a larger scale than pages we
+ adjust the allocated stack size if necessary. This way
+ allocations directly following each other will not have
+ aliasing problems. */
+#if MULTI_PAGE_ALIASING != 0
+ if ((size % MULTI_PAGE_ALIASING) == 0)
+ size += pagesize_m1 + 1;
+#endif
+
+ mem = mmap (NULL, size, prot,
+ MAP_PRIVATE | MAP_ANONYMOUS | ARCH_MAP_FLAGS, -1, 0);
+
+ if (__builtin_expect (mem == MAP_FAILED, 0))
+ {
+#ifdef ARCH_RETRY_MMAP
+ mem = ARCH_RETRY_MMAP (size);
+ if (__builtin_expect (mem == MAP_FAILED, 0))
+#endif
+ return errno;
+ }
+
+ /* SIZE is guaranteed to be greater than zero.
+ So we can never get a null pointer back from mmap. */
+ assert (mem != NULL);
+
+#if COLORING_INCREMENT != 0
+ /* Atomically increment NCREATED. */
+ unsigned int ncreated = atomic_increment_val (&nptl_ncreated);
+
+ /* We chose the offset for coloring by incrementing it for
+ every new thread by a fixed amount. The offset used
+ module the page size. Even if coloring would be better
+ relative to higher alignment values it makes no sense to
+ do it since the mmap() interface does not allow us to
+ specify any alignment for the returned memory block. */
+ size_t coloring = (ncreated * COLORING_INCREMENT) & pagesize_m1;
+
+ /* Make sure the coloring offsets does not disturb the alignment
+ of the TCB and static TLS block. */
+ if (__builtin_expect ((coloring & __static_tls_align_m1) != 0, 0))
+ coloring = (((coloring + __static_tls_align_m1)
+ & ~(__static_tls_align_m1))
+ & ~pagesize_m1);
+#else
+ /* Unless specified we do not make any adjustments. */
+# define coloring 0
+#endif
+
+ /* Place the thread descriptor at the end of the stack. */
+#if TLS_TCB_AT_TP
+ pd = (struct pthread *) ((char *) mem + size - coloring) - 1;
+#elif TLS_DTV_AT_TP
+ pd = (struct pthread *) ((((uintptr_t) mem + size - coloring
+ - __static_tls_size)
+ & ~__static_tls_align_m1)
+ - TLS_PRE_TCB_SIZE);
+#endif
+
+ /* Remember the stack-related values. */
+ pd->stackblock = mem;
+ pd->stackblock_size = size;
+
+ /* We allocated the first block thread-specific data array.
+ This address will not change for the lifetime of this
+ descriptor. */
+ pd->specific[0] = pd->specific_1stblock;
+
+ /* This is at least the second thread. */
+ pd->header.multiple_threads = 1;
+#ifndef TLS_MULTIPLE_THREADS_IN_TCB
+ __pthread_multiple_threads = *__libc_multiple_threads_ptr = 1;
+#endif
+
+#ifdef NEED_DL_SYSINFO
+ /* Copy the sysinfo value from the parent. */
+ THREAD_SYSINFO(pd) = THREAD_SELF_SYSINFO;
+#endif
+
+ /* The process ID is also the same as that of the caller. */
+ pd->pid = THREAD_GETMEM (THREAD_SELF, pid);
+
+ /* Allocate the DTV for this thread. */
+ if (_dl_allocate_tls (TLS_TPADJ (pd)) == NULL)
+ {
+ /* Something went wrong. */
+ assert (errno == ENOMEM);
+
+ /* Free the stack memory we just allocated. */
+ (void) munmap (mem, size);
+
+ return EAGAIN;
+ }
+
+
+ /* Prepare to modify global data. */
+ lll_lock (stack_cache_lock);
+
+ /* And add to the list of stacks in use. */
+ list_add (&pd->list, &stack_used);
+
+ lll_unlock (stack_cache_lock);
+
+
+ /* There might have been a race. Another thread might have
+ caused the stacks to get exec permission while this new
+ stack was prepared. Detect if this was possible and
+ change the permission if necessary. */
+ if (__builtin_expect ((GL(dl_stack_flags) & PF_X) != 0
+ && (prot & PROT_EXEC) == 0, 0))
+ {
+ int err = change_stack_perm (pd
+#ifdef NEED_SEPARATE_REGISTER_STACK
+ , ~pagesize_m1
+#endif
+ );
+ if (err != 0)
+ {
+ /* Free the stack memory we just allocated. */
+ (void) munmap (mem, size);
+
+ return err;
+ }
+ }
+
+
+ /* Note that all of the stack and the thread descriptor is
+ zeroed. This means we do not have to initialize fields
+ with initial value zero. This is specifically true for
+ the 'tid' field which is always set back to zero once the
+ stack is not used anymore and for the 'guardsize' field
+ which will be read next. */
+ }
+
+ /* Create or resize the guard area if necessary. */
+ if (__builtin_expect (guardsize > pd->guardsize, 0))
+ {
+#ifdef NEED_SEPARATE_REGISTER_STACK
+ char *guard = mem + (((size - guardsize) / 2) & ~pagesize_m1);
+#else
+ char *guard = mem;
+#endif
+ if (mprotect (guard, guardsize, PROT_NONE) != 0)
+ {
+ int err;
+ mprot_error:
+ err = errno;
+
+ lll_lock (stack_cache_lock);
+
+ /* Remove the thread from the list. */
+ list_del (&pd->list);
+
+ lll_unlock (stack_cache_lock);
+
+ /* Get rid of the TLS block we allocated. */
+ _dl_deallocate_tls (TLS_TPADJ (pd), false);
+
+ /* Free the stack memory regardless of whether the size
+ of the cache is over the limit or not. If this piece
+ of memory caused problems we better do not use it
+ anymore. Uh, and we ignore possible errors. There
+ is nothing we could do. */
+ (void) munmap (mem, size);
+
+ return err;
+ }
+
+ pd->guardsize = guardsize;
+ }
+ else if (__builtin_expect (pd->guardsize - guardsize > size - reqsize,
+ 0))
+ {
+ /* The old guard area is too large. */
+
+#ifdef NEED_SEPARATE_REGISTER_STACK
+ char *guard = mem + (((size - guardsize) / 2) & ~pagesize_m1);
+ char *oldguard = mem + (((size - pd->guardsize) / 2) & ~pagesize_m1);
+
+ if (oldguard < guard
+ && mprotect (oldguard, guard - oldguard, prot) != 0)
+ goto mprot_error;
+
+ if (mprotect (guard + guardsize,
+ oldguard + pd->guardsize - guard - guardsize,
+ prot) != 0)
+ goto mprot_error;
+#else
+ if (mprotect ((char *) mem + guardsize, pd->guardsize - guardsize,
+ prot) != 0)
+ goto mprot_error;
+#endif
+
+ pd->guardsize = guardsize;
+ }
+ /* The pthread_getattr_np() calls need to get passed the size
+ requested in the attribute, regardless of how large the
+ actually used guardsize is. */
+ pd->reported_guardsize = guardsize;
+ }
+
+ /* Initialize the lock. We have to do this unconditionally since the
+ stillborn thread could be canceled while the lock is taken. */
+ pd->lock = LLL_LOCK_INITIALIZER;
+
+ /* The robust mutex lists also need to be initialized
+ unconditionally because the cleanup for the previous stack owner
+ might have happened in the kernel. */
+ pd->robust_head.futex_offset = (offsetof (pthread_mutex_t, __data.__lock)
+ - offsetof (pthread_mutex_t,
+ __data.__list.__next));
+ pd->robust_head.list_op_pending = NULL;
+#ifdef __PTHREAD_MUTEX_HAVE_PREV
+ pd->robust_prev = &pd->robust_head;
+#endif
+ pd->robust_head.list = &pd->robust_head;
+
+ /* We place the thread descriptor at the end of the stack. */
+ *pdp = pd;
+
+#if TLS_TCB_AT_TP
+ /* The stack begins before the TCB and the static TLS block. */
+ stacktop = ((char *) (pd + 1) - __static_tls_size);
+#elif TLS_DTV_AT_TP
+ stacktop = (char *) (pd - 1);
+#endif
+
+#ifdef NEED_SEPARATE_REGISTER_STACK
+ *stack = pd->stackblock;
+ *stacksize = stacktop - *stack;
+#else
+ *stack = stacktop;
+#endif
+
+ return 0;
+}
+
+
+void
+internal_function
+__deallocate_stack (struct pthread *pd)
+{
+ lll_lock (stack_cache_lock);
+
+ /* Remove the thread from the list of threads with user defined
+ stacks. */
+ list_del (&pd->list);
+
+ /* Not much to do. Just free the mmap()ed memory. Note that we do
+ not reset the 'used' flag in the 'tid' field. This is done by
+ the kernel. If no thread has been created yet this field is
+ still zero. */
+ if (__builtin_expect (! pd->user_stack, 1))
+ (void) queue_stack (pd);
+ else
+ /* Free the memory associated with the ELF TLS. */
+ _dl_deallocate_tls (TLS_TPADJ (pd), false);
+
+ lll_unlock (stack_cache_lock);
+}
+
+
+int
+internal_function
+__make_stacks_executable (void **stack_endp)
+{
+ /* First the main thread's stack. */
+ int err = _dl_make_stack_executable (stack_endp);
+ if (err != 0)
+ return err;
+
+#ifdef NEED_SEPARATE_REGISTER_STACK
+ const size_t pagemask = ~(__getpagesize () - 1);
+#endif
+
+ lll_lock (stack_cache_lock);
+
+ list_t *runp;
+ list_for_each (runp, &stack_used)
+ {
+ err = change_stack_perm (list_entry (runp, struct pthread, list)
+#ifdef NEED_SEPARATE_REGISTER_STACK
+ , pagemask
+#endif
+ );
+ if (err != 0)
+ break;
+ }
+
+ /* Also change the permission for the currently unused stacks. This
+ might be wasted time but better spend it here than adding a check
+ in the fast path. */
+ if (err == 0)
+ list_for_each (runp, &stack_cache)
+ {
+ err = change_stack_perm (list_entry (runp, struct pthread, list)
+#ifdef NEED_SEPARATE_REGISTER_STACK
+ , pagemask
+#endif
+ );
+ if (err != 0)
+ break;
+ }
+
+ lll_unlock (stack_cache_lock);
+
+ return err;
+}
+
+
+/* In case of a fork() call the memory allocation in the child will be
+ the same but only one thread is running. All stacks except that of
+ the one running thread are not used anymore. We have to recycle
+ them. */
+void
+__reclaim_stacks (void)
+{
+ struct pthread *self = (struct pthread *) THREAD_SELF;
+
+ /* No locking necessary. The caller is the only stack in use. */
+
+ /* Mark all stacks except the still running one as free. */
+ list_t *runp;
+ list_for_each (runp, &stack_used)
+ {
+ struct pthread *curp = list_entry (runp, struct pthread, list);
+ if (curp != self)
+ {
+ /* This marks the stack as free. */
+ curp->tid = 0;
+
+ /* The PID field must be initialized for the new process. */
+ curp->pid = self->pid;
+
+ /* Account for the size of the stack. */
+ stack_cache_actsize += curp->stackblock_size;
+ }
+ }
+
+ /* Reset the PIDs in any cached stacks. */
+ list_for_each (runp, &stack_cache)
+ {
+ struct pthread *curp = list_entry (runp, struct pthread, list);
+ curp->pid = self->pid;
+ }
+
+ /* Add the stack of all running threads to the cache. */
+ list_splice (&stack_used, &stack_cache);
+
+ /* Remove the entry for the current thread to from the cache list
+ and add it to the list of running threads. Which of the two
+ lists is decided by the user_stack flag. */
+ list_del (&self->list);
+
+ /* Re-initialize the lists for all the threads. */
+ INIT_LIST_HEAD (&stack_used);
+ INIT_LIST_HEAD (&__stack_user);
+
+ if (__builtin_expect (THREAD_GETMEM (self, user_stack), 0))
+ list_add (&self->list, &__stack_user);
+ else
+ list_add (&self->list, &stack_used);
+
+ /* There is one thread running. */
+ __nptl_nthreads = 1;
+
+ /* Initialize the lock. */
+ stack_cache_lock = LLL_LOCK_INITIALIZER;
+}
+
+
+#if HP_TIMING_AVAIL
+# undef __find_thread_by_id
+/* Find a thread given the thread ID. */
+attribute_hidden
+struct pthread *
+__find_thread_by_id (pid_t tid)
+{
+ struct pthread *result = NULL;
+
+ lll_lock (stack_cache_lock);
+
+ /* Iterate over the list with system-allocated threads first. */
+ list_t *runp;
+ list_for_each (runp, &stack_used)
+ {
+ struct pthread *curp;
+
+ curp = list_entry (runp, struct pthread, list);
+
+ if (curp->tid == tid)
+ {
+ result = curp;
+ goto out;
+ }
+ }
+
+ /* Now the list with threads using user-allocated stacks. */
+ list_for_each (runp, &__stack_user)
+ {
+ struct pthread *curp;
+
+ curp = list_entry (runp, struct pthread, list);
+
+ if (curp->tid == tid)
+ {
+ result = curp;
+ goto out;
+ }
+ }
+
+ out:
+ lll_unlock (stack_cache_lock);
+
+ return result;
+}
+#endif
+
+
+static void
+internal_function
+setxid_signal_thread (struct xid_command *cmdp, struct pthread *t)
+{
+ if (! IS_DETACHED (t))
+ {
+ int ch;
+ do
+ {
+ ch = t->cancelhandling;
+
+ /* If the thread is exiting right now, ignore it. */
+ if ((ch & EXITING_BITMASK) != 0)
+ return;
+ }
+ while (atomic_compare_and_exchange_bool_acq (&t->cancelhandling,
+ ch | SETXID_BITMASK, ch));
+ }
+
+ int val;
+ INTERNAL_SYSCALL_DECL (err);
+#if __ASSUME_TGKILL
+ val = INTERNAL_SYSCALL (tgkill, err, 3, THREAD_GETMEM (THREAD_SELF, pid),
+ t->tid, SIGSETXID);
+#else
+# ifdef __NR_tgkill
+ val = INTERNAL_SYSCALL (tgkill, err, 3, THREAD_GETMEM (THREAD_SELF, pid),
+ t->tid, SIGSETXID);
+ if (INTERNAL_SYSCALL_ERROR_P (val, err)
+ && INTERNAL_SYSCALL_ERRNO (val, err) == ENOSYS)
+# endif
+ val = INTERNAL_SYSCALL (tkill, err, 2, t->tid, SIGSETXID);
+#endif
+
+ if (!INTERNAL_SYSCALL_ERROR_P (val, err))
+ atomic_increment (&cmdp->cntr);
+}
+
+
+int
+attribute_hidden
+__nptl_setxid (struct xid_command *cmdp)
+{
+ int result;
+ lll_lock (stack_cache_lock);
+
+ __xidcmd = cmdp;
+ cmdp->cntr = 0;
+
+ struct pthread *self = THREAD_SELF;
+
+ /* Iterate over the list with system-allocated threads first. */
+ list_t *runp;
+ list_for_each (runp, &stack_used)
+ {
+ struct pthread *t = list_entry (runp, struct pthread, list);
+ if (t == self)
+ continue;
+
+ setxid_signal_thread (cmdp, t);
+ }
+
+ /* Now the list with threads using user-allocated stacks. */
+ list_for_each (runp, &__stack_user)
+ {
+ struct pthread *t = list_entry (runp, struct pthread, list);
+ if (t == self)
+ continue;
+
+ setxid_signal_thread (cmdp, t);
+ }
+
+ int cur = cmdp->cntr;
+ while (cur != 0)
+ {
+ lll_futex_wait (&cmdp->cntr, cur);
+ cur = cmdp->cntr;
+ }
+
+ /* This must be last, otherwise the current thread might not have
+ permissions to send SIGSETXID syscall to the other threads. */
+ INTERNAL_SYSCALL_DECL (err);
+ result = INTERNAL_SYSCALL_NCS (cmdp->syscall_no, err, 3,
+ cmdp->id[0], cmdp->id[1], cmdp->id[2]);
+ if (INTERNAL_SYSCALL_ERROR_P (result, err))
+ {
+ __set_errno (INTERNAL_SYSCALL_ERRNO (result, err));
+ result = -1;
+ }
+
+ lll_unlock (stack_cache_lock);
+ return result;
+}
+
+static inline void __attribute__((always_inline))
+init_one_static_tls (struct pthread *curp, struct link_map *map)
+{
+ dtv_t *dtv = GET_DTV (TLS_TPADJ (curp));
+# if TLS_TCB_AT_TP
+ void *dest = (char *) curp - map->l_tls_offset;
+# elif TLS_DTV_AT_TP
+ void *dest = (char *) curp + map->l_tls_offset + TLS_PRE_TCB_SIZE;
+# else
+# error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
+# endif
+
+ /* Fill in the DTV slot so that a later LD/GD access will find it. */
+ dtv[map->l_tls_modid].pointer.val = dest;
+ dtv[map->l_tls_modid].pointer.is_static = true;
+
+ /* Initialize the memory. */
+ memset (__mempcpy (dest, map->l_tls_initimage, map->l_tls_initimage_size),
+ '\0', map->l_tls_blocksize - map->l_tls_initimage_size);
+}
+
+void
+attribute_hidden
+__pthread_init_static_tls (struct link_map *map)
+{
+ lll_lock (stack_cache_lock);
+
+ /* Iterate over the list with system-allocated threads first. */
+ list_t *runp;
+ list_for_each (runp, &stack_used)
+ init_one_static_tls (list_entry (runp, struct pthread, list), map);
+
+ /* Now the list with threads using user-allocated stacks. */
+ list_for_each (runp, &__stack_user)
+ init_one_static_tls (list_entry (runp, struct pthread, list), map);
+
+ lll_unlock (stack_cache_lock);
+}
diff --git a/libc/nptl/cancellation.c b/libc/nptl/cancellation.c
new file mode 100644
index 000000000..1d28d383f
--- /dev/null
+++ b/libc/nptl/cancellation.c
@@ -0,0 +1,90 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <setjmp.h>
+#include <stdlib.h>
+#include "pthreadP.h"
+
+
+/* The next two functions are similar to pthread_setcanceltype() but
+ more specialized for the use in the cancelable functions like write().
+ They do not need to check parameters etc. */
+int
+attribute_hidden
+__pthread_enable_asynccancel (void)
+{
+ struct pthread *self = THREAD_SELF;
+ int oldval = THREAD_GETMEM (self, cancelhandling);
+
+ while (1)
+ {
+ int newval = oldval | CANCELTYPE_BITMASK;
+
+ if (newval == oldval)
+ break;
+
+ int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
+ oldval);
+ if (__builtin_expect (curval == oldval, 1))
+ {
+ if (CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS (newval))
+ {
+ THREAD_SETMEM (self, result, PTHREAD_CANCELED);
+ __do_cancel ();
+ }
+
+ break;
+ }
+
+ /* Prepare the next round. */
+ oldval = curval;
+ }
+
+ return oldval;
+}
+
+
+void
+internal_function attribute_hidden
+__pthread_disable_asynccancel (int oldtype)
+{
+ /* If asynchronous cancellation was enabled before we do not have
+ anything to do. */
+ if (oldtype & CANCELTYPE_BITMASK)
+ return;
+
+ struct pthread *self = THREAD_SELF;
+ int oldval = THREAD_GETMEM (self, cancelhandling);
+
+ while (1)
+ {
+ int newval = oldval & ~CANCELTYPE_BITMASK;
+
+ if (newval == oldval)
+ break;
+
+ int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
+ oldval);
+ if (__builtin_expect (curval == oldval, 1))
+ break;
+
+ /* Prepare the next round. */
+ oldval = curval;
+ }
+}
diff --git a/libc/nptl/cleanup.c b/libc/nptl/cleanup.c
new file mode 100644
index 000000000..af828c49f
--- /dev/null
+++ b/libc/nptl/cleanup.c
@@ -0,0 +1,49 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <stdlib.h>
+#include "pthreadP.h"
+
+
+void
+__cleanup_fct_attribute
+__pthread_register_cancel (__pthread_unwind_buf_t *buf)
+{
+ struct pthread_unwind_buf *ibuf = (struct pthread_unwind_buf *) buf;
+ struct pthread *self = THREAD_SELF;
+
+ /* Store old info. */
+ ibuf->priv.data.prev = THREAD_GETMEM (self, cleanup_jmp_buf);
+ ibuf->priv.data.cleanup = THREAD_GETMEM (self, cleanup);
+
+ /* Store the new cleanup handler info. */
+ THREAD_SETMEM (self, cleanup_jmp_buf, (struct pthread_unwind_buf *) buf);
+}
+hidden_def (__pthread_register_cancel)
+
+
+void
+__cleanup_fct_attribute
+__pthread_unregister_cancel (__pthread_unwind_buf_t *buf)
+{
+ struct pthread_unwind_buf *ibuf = (struct pthread_unwind_buf *) buf;
+
+ THREAD_SETMEM (THREAD_SELF, cleanup_jmp_buf, ibuf->priv.data.prev);
+}
+hidden_def (__pthread_unregister_cancel)
diff --git a/libc/nptl/cleanup_compat.c b/libc/nptl/cleanup_compat.c
new file mode 100644
index 000000000..a25b397f9
--- /dev/null
+++ b/libc/nptl/cleanup_compat.c
@@ -0,0 +1,55 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <stdlib.h>
+#include "pthreadP.h"
+
+
+void
+_pthread_cleanup_push (buffer, routine, arg)
+ struct _pthread_cleanup_buffer *buffer;
+ void (*routine) (void *);
+ void *arg;
+{
+ struct pthread *self = THREAD_SELF;
+
+ buffer->__routine = routine;
+ buffer->__arg = arg;
+ buffer->__prev = THREAD_GETMEM (self, cleanup);
+
+ THREAD_SETMEM (self, cleanup, buffer);
+}
+strong_alias (_pthread_cleanup_push, __pthread_cleanup_push)
+
+
+void
+_pthread_cleanup_pop (buffer, execute)
+ struct _pthread_cleanup_buffer *buffer;
+ int execute;
+{
+ struct pthread *self __attribute ((unused)) = THREAD_SELF;
+
+ THREAD_SETMEM (self, cleanup, buffer->__prev);
+
+ /* If necessary call the cleanup routine after we removed the
+ current cleanup block from the list. */
+ if (execute)
+ buffer->__routine (buffer->__arg);
+}
+strong_alias (_pthread_cleanup_pop, __pthread_cleanup_pop)
diff --git a/libc/nptl/cleanup_defer.c b/libc/nptl/cleanup_defer.c
new file mode 100644
index 000000000..498d9557d
--- /dev/null
+++ b/libc/nptl/cleanup_defer.c
@@ -0,0 +1,92 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <stdlib.h>
+#include "pthreadP.h"
+
+
+void
+__cleanup_fct_attribute
+__pthread_register_cancel_defer (__pthread_unwind_buf_t *buf)
+{
+ struct pthread_unwind_buf *ibuf = (struct pthread_unwind_buf *) buf;
+ struct pthread *self = THREAD_SELF;
+
+ /* Store old info. */
+ ibuf->priv.data.prev = THREAD_GETMEM (self, cleanup_jmp_buf);
+ ibuf->priv.data.cleanup = THREAD_GETMEM (self, cleanup);
+
+ int cancelhandling = THREAD_GETMEM (self, cancelhandling);
+
+ /* Disable asynchronous cancellation for now. */
+ if (__builtin_expect (cancelhandling & CANCELTYPE_BITMASK, 0))
+ while (1)
+ {
+ int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling,
+ cancelhandling
+ & ~CANCELTYPE_BITMASK,
+ cancelhandling);
+ if (__builtin_expect (curval == cancelhandling, 1))
+ /* Successfully replaced the value. */
+ break;
+
+ /* Prepare for the next round. */
+ cancelhandling = curval;
+ }
+
+ ibuf->priv.data.canceltype = (cancelhandling & CANCELTYPE_BITMASK
+ ? PTHREAD_CANCEL_ASYNCHRONOUS
+ : PTHREAD_CANCEL_DEFERRED);
+
+ /* Store the new cleanup handler info. */
+ THREAD_SETMEM (self, cleanup_jmp_buf, (struct pthread_unwind_buf *) buf);
+}
+
+
+void
+__cleanup_fct_attribute
+__pthread_unregister_cancel_restore (__pthread_unwind_buf_t *buf)
+{
+ struct pthread *self = THREAD_SELF;
+ struct pthread_unwind_buf *ibuf = (struct pthread_unwind_buf *) buf;
+
+ THREAD_SETMEM (self, cleanup_jmp_buf, ibuf->priv.data.prev);
+
+ int cancelhandling;
+ if (ibuf->priv.data.canceltype != PTHREAD_CANCEL_DEFERRED
+ && ((cancelhandling = THREAD_GETMEM (self, cancelhandling))
+ & CANCELTYPE_BITMASK) == 0)
+ {
+ while (1)
+ {
+ int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling,
+ cancelhandling
+ | CANCELTYPE_BITMASK,
+ cancelhandling);
+ if (__builtin_expect (curval == cancelhandling, 1))
+ /* Successfully replaced the value. */
+ break;
+
+ /* Prepare for the next round. */
+ cancelhandling = curval;
+ }
+
+ CANCELLATION_P (self);
+ }
+}
diff --git a/libc/nptl/cleanup_defer_compat.c b/libc/nptl/cleanup_defer_compat.c
new file mode 100644
index 000000000..a0ed6da88
--- /dev/null
+++ b/libc/nptl/cleanup_defer_compat.c
@@ -0,0 +1,98 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "pthreadP.h"
+
+
+void
+_pthread_cleanup_push_defer (buffer, routine, arg)
+ struct _pthread_cleanup_buffer *buffer;
+ void (*routine) (void *);
+ void *arg;
+{
+ struct pthread *self = THREAD_SELF;
+
+ buffer->__routine = routine;
+ buffer->__arg = arg;
+ buffer->__prev = THREAD_GETMEM (self, cleanup);
+
+ int cancelhandling = THREAD_GETMEM (self, cancelhandling);
+
+ /* Disable asynchronous cancellation for now. */
+ if (__builtin_expect (cancelhandling & CANCELTYPE_BITMASK, 0))
+ while (1)
+ {
+ int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling,
+ cancelhandling
+ & ~CANCELTYPE_BITMASK,
+ cancelhandling);
+ if (__builtin_expect (curval == cancelhandling, 1))
+ /* Successfully replaced the value. */
+ break;
+
+ /* Prepare for the next round. */
+ cancelhandling = curval;
+ }
+
+ buffer->__canceltype = (cancelhandling & CANCELTYPE_BITMASK
+ ? PTHREAD_CANCEL_ASYNCHRONOUS
+ : PTHREAD_CANCEL_DEFERRED);
+
+ THREAD_SETMEM (self, cleanup, buffer);
+}
+strong_alias (_pthread_cleanup_push_defer, __pthread_cleanup_push_defer)
+
+
+void
+_pthread_cleanup_pop_restore (buffer, execute)
+ struct _pthread_cleanup_buffer *buffer;
+ int execute;
+{
+ struct pthread *self = THREAD_SELF;
+
+ THREAD_SETMEM (self, cleanup, buffer->__prev);
+
+ int cancelhandling;
+ if (__builtin_expect (buffer->__canceltype != PTHREAD_CANCEL_DEFERRED, 0)
+ && ((cancelhandling = THREAD_GETMEM (self, cancelhandling))
+ & CANCELTYPE_BITMASK) == 0)
+ {
+ while (1)
+ {
+ int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling,
+ cancelhandling
+ | CANCELTYPE_BITMASK,
+ cancelhandling);
+ if (__builtin_expect (curval == cancelhandling, 1))
+ /* Successfully replaced the value. */
+ break;
+
+ /* Prepare for the next round. */
+ cancelhandling = curval;
+ }
+
+ CANCELLATION_P (self);
+ }
+
+ /* If necessary call the cleanup routine after we removed the
+ current cleanup block from the list. */
+ if (execute)
+ buffer->__routine (buffer->__arg);
+}
+strong_alias (_pthread_cleanup_pop_restore, __pthread_cleanup_pop_restore)
diff --git a/libc/nptl/cleanup_routine.c b/libc/nptl/cleanup_routine.c
new file mode 100644
index 000000000..cbf231834
--- /dev/null
+++ b/libc/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/libc/nptl/cond-perf.c b/libc/nptl/cond-perf.c
new file mode 100644
index 000000000..e37914e6b
--- /dev/null
+++ b/libc/nptl/cond-perf.c
@@ -0,0 +1,103 @@
+#include <pthread.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <atomic.h>
+
+static pthread_cond_t cond1 = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t mut1 = PTHREAD_MUTEX_INITIALIZER;
+
+static pthread_cond_t cond2 = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t mut2 = PTHREAD_MUTEX_INITIALIZER;
+
+static bool last_round;
+static int ntogo;
+static bool alldone;
+
+
+static void *
+cons (void *arg)
+{
+ pthread_mutex_lock (&mut1);
+
+ do
+ {
+ if (atomic_decrement_and_test (&ntogo))
+ {
+ pthread_mutex_lock (&mut2);
+ alldone = true;
+ pthread_cond_signal (&cond2);
+ pthread_mutex_unlock (&mut2);
+ }
+
+ pthread_cond_wait (&cond1, &mut1);
+ }
+ while (! last_round);
+
+ pthread_mutex_unlock (&mut1);
+
+ return NULL;
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ int opt;
+ int err;
+ int nthreads = 10;
+ int nrounds = 100;
+ bool keeplock = false;
+
+ while ((opt = getopt (argc, argv, "n:r:k")) != -1)
+ switch (opt)
+ {
+ case 'n':
+ nthreads = atol (optarg);
+ break;
+ case 'r':
+ nrounds = atol (optarg);
+ break;
+ case 'k':
+ keeplock = true;
+ break;
+ }
+
+ ntogo = nthreads;
+
+ pthread_t th[nthreads];
+ int i;
+ for (i = 0; __builtin_expect (i < nthreads, 1); ++i)
+ if (__builtin_expect ((err = pthread_create (&th[i], NULL, cons, (void *) (long) i)) != 0, 0))
+ printf ("pthread_create: %s\n", strerror (err));
+
+ for (i = 0; __builtin_expect (i < nrounds, 1); ++i)
+ {
+ pthread_mutex_lock (&mut2);
+ while (! alldone)
+ pthread_cond_wait (&cond2, &mut2);
+ pthread_mutex_unlock (&mut2);
+
+ pthread_mutex_lock (&mut1);
+ if (! keeplock)
+ pthread_mutex_unlock (&mut1);
+
+ ntogo = nthreads;
+ alldone = false;
+ if (i + 1 >= nrounds)
+ last_round = true;
+
+ pthread_cond_broadcast (&cond1);
+
+ if (keeplock)
+ pthread_mutex_unlock (&mut1);
+ }
+
+ for (i = 0; i < nthreads; ++i)
+ if ((err = pthread_join (th[i], NULL)) != 0)
+ printf ("pthread_create: %s\n", strerror (err));
+
+ return 0;
+}
diff --git a/libc/nptl/configure b/libc/nptl/configure
new file mode 100644
index 000000000..dd246c755
--- /dev/null
+++ b/libc/nptl/configure
@@ -0,0 +1,13 @@
+# This is a shell script fragment sourced by the main configure script.
+# We're obliged to give here the canonical name that will be used to
+# as a subdirectory to search for in other add-ons' sysdeps trees.
+
+libc_add_on_canonical=nptl
+
+# Only linux configurations support NPTL.
+if test $add_ons_automatic = yes; then
+ case "$config_os" in
+ *linux*) ;;
+ *) libc_add_on= ;;
+ esac
+fi
diff --git a/libc/nptl/descr.h b/libc/nptl/descr.h
new file mode 100644
index 000000000..7acd2f4f2
--- /dev/null
+++ b/libc/nptl/descr.h
@@ -0,0 +1,368 @@
+/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+#ifndef _DESCR_H
+#define _DESCR_H 1
+
+#include <limits.h>
+#include <sched.h>
+#include <setjmp.h>
+#include <stdbool.h>
+#include <sys/types.h>
+#include <hp-timing.h>
+#include <list.h>
+#include <lowlevellock.h>
+#include <pthreaddef.h>
+#include <dl-sysdep.h>
+#include "../nptl_db/thread_db.h"
+#include <tls.h>
+#ifdef HAVE_FORCED_UNWIND
+# include <unwind.h>
+#endif
+#define __need_res_state
+#include <resolv.h>
+
+#ifndef TCB_ALIGNMENT
+# define TCB_ALIGNMENT sizeof (double)
+#endif
+
+
+/* We keep thread specific data in a special data structure, a two-level
+ array. The top-level array contains pointers to dynamically allocated
+ arrays of a certain number of data pointers. So we can implement a
+ sparse array. Each dynamic second-level array has
+ PTHREAD_KEY_2NDLEVEL_SIZE
+ entries. This value shouldn't be too large. */
+#define PTHREAD_KEY_2NDLEVEL_SIZE 32
+
+/* We need to address PTHREAD_KEYS_MAX key with PTHREAD_KEY_2NDLEVEL_SIZE
+ keys in each subarray. */
+#define PTHREAD_KEY_1STLEVEL_SIZE \
+ ((PTHREAD_KEYS_MAX + PTHREAD_KEY_2NDLEVEL_SIZE - 1) \
+ / PTHREAD_KEY_2NDLEVEL_SIZE)
+
+
+
+
+/* Internal version of the buffer to store cancellation handler
+ information. */
+struct pthread_unwind_buf
+{
+ struct
+ {
+ __jmp_buf jmp_buf;
+ int mask_was_saved;
+ } cancel_jmp_buf[1];
+
+ union
+ {
+ /* This is the placeholder of the public version. */
+ void *pad[4];
+
+ struct
+ {
+ /* Pointer to the previous cleanup buffer. */
+ struct pthread_unwind_buf *prev;
+
+ /* Backward compatibility: state of the old-style cleanup
+ handler at the time of the previous new-style cleanup handler
+ installment. */
+ struct _pthread_cleanup_buffer *cleanup;
+
+ /* Cancellation type before the push call. */
+ int canceltype;
+ } data;
+ } priv;
+};
+
+
+/* Opcodes and data types for communication with the signal handler to
+ change user/group IDs. */
+struct xid_command
+{
+ int syscall_no;
+ long int id[3];
+ volatile int cntr;
+};
+
+
+/* Data structure used by the kernel to find robust futexes. */
+struct robust_list_head
+{
+ void *list;
+ long int futex_offset;
+ void *list_op_pending;
+};
+
+
+/* Data strcture used to handle thread priority protection. */
+struct priority_protection_data
+{
+ int priomax;
+ unsigned int priomap[];
+};
+
+
+/* Thread descriptor data structure. */
+struct pthread
+{
+ union
+ {
+#if !TLS_DTV_AT_TP
+ /* This overlaps the TCB as used for TLS without threads (see tls.h). */
+ tcbhead_t header;
+#else
+ struct
+ {
+ int multiple_threads;
+ } header;
+#endif
+
+ /* This extra padding has no special purpose, and this structure layout
+ is private and subject to change without affecting the official ABI.
+ We just have it here in case it might be convenient for some
+ implementation-specific instrumentation hack or suchlike. */
+ void *__padding[16];
+ };
+
+ /* This descriptor's link on the `stack_used' or `__stack_user' list. */
+ list_t list;
+
+ /* Thread ID - which is also a 'is this thread descriptor (and
+ therefore stack) used' flag. */
+ pid_t tid;
+
+ /* Process ID - thread group ID in kernel speak. */
+ pid_t pid;
+
+ /* List of robust mutexes the thread is holding. */
+#ifdef __PTHREAD_MUTEX_HAVE_PREV
+ void *robust_prev;
+ struct robust_list_head robust_head;
+
+ /* The list above is strange. It is basically a double linked list
+ but the pointer to the next/previous element of the list points
+ in the middle of the object, the __next element. Whenever
+ casting to __pthread_list_t we need to adjust the pointer
+ first. */
+# define QUEUE_PTR_ADJUST (offsetof (__pthread_list_t, __next))
+
+# define ENQUEUE_MUTEX_BOTH(mutex, val) \
+ do { \
+ __pthread_list_t *next = (__pthread_list_t *) \
+ ((((uintptr_t) THREAD_GETMEM (THREAD_SELF, robust_head.list)) & ~1ul) \
+ - QUEUE_PTR_ADJUST); \
+ next->__prev = (void *) &mutex->__data.__list.__next; \
+ mutex->__data.__list.__next = THREAD_GETMEM (THREAD_SELF, \
+ robust_head.list); \
+ mutex->__data.__list.__prev = (void *) &THREAD_SELF->robust_head; \
+ THREAD_SETMEM (THREAD_SELF, robust_head.list, \
+ (void *) (((uintptr_t) &mutex->__data.__list.__next) \
+ | val)); \
+ } while (0)
+# define DEQUEUE_MUTEX(mutex) \
+ do { \
+ __pthread_list_t *next = (__pthread_list_t *) \
+ ((char *) (((uintptr_t) mutex->__data.__list.__next) & ~1ul) \
+ - QUEUE_PTR_ADJUST); \
+ next->__prev = mutex->__data.__list.__prev; \
+ __pthread_list_t *prev = (__pthread_list_t *) \
+ ((char *) (((uintptr_t) mutex->__data.__list.__prev) & ~1ul) \
+ - QUEUE_PTR_ADJUST); \
+ prev->__next = mutex->__data.__list.__next; \
+ mutex->__data.__list.__prev = NULL; \
+ mutex->__data.__list.__next = NULL; \
+ } while (0)
+#else
+ union
+ {
+ __pthread_slist_t robust_list;
+ struct robust_list_head robust_head;
+ };
+
+# define ENQUEUE_MUTEX_BOTH(mutex, val) \
+ do { \
+ mutex->__data.__list.__next \
+ = THREAD_GETMEM (THREAD_SELF, robust_list.__next); \
+ THREAD_SETMEM (THREAD_SELF, robust_list.__next, \
+ ((uintptr_t) &mutex->__data.__list) | val); \
+ } while (0)
+# define DEQUEUE_MUTEX(mutex) \
+ do { \
+ __pthread_slist_t *runp = (__pthread_slist_t *) \
+ (((uintptr_t) THREAD_GETMEM (THREAD_SELF, robust_list.__next)) & ~1ul); \
+ if (runp == &mutex->__data.__list) \
+ THREAD_SETMEM (THREAD_SELF, robust_list.__next, runp->__next); \
+ else \
+ { \
+ __pthread_slist_t *next = (__pthread_slist_t *) \
+ (((uintptr_t) runp->__next) & ~1ul); \
+ while (next != &mutex->__data.__list) \
+ { \
+ runp = next; \
+ next = (__pthread_slist_t *) (((uintptr_t) runp->__next) & ~1ul); \
+ } \
+ \
+ runp->__next = next->__next; \
+ mutex->__data.__list.__next = NULL; \
+ } \
+ } while (0)
+#endif
+#define ENQUEUE_MUTEX(mutex) ENQUEUE_MUTEX_BOTH (mutex, 0)
+#define ENQUEUE_MUTEX_PI(mutex) ENQUEUE_MUTEX_BOTH (mutex, 1)
+
+ /* List of cleanup buffers. */
+ struct _pthread_cleanup_buffer *cleanup;
+
+ /* Unwind information. */
+ struct pthread_unwind_buf *cleanup_jmp_buf;
+#define HAVE_CLEANUP_JMP_BUF
+
+ /* Flags determining processing of cancellation. */
+ int cancelhandling;
+ /* Bit set if cancellation is disabled. */
+#define CANCELSTATE_BIT 0
+#define CANCELSTATE_BITMASK 0x01
+ /* Bit set if asynchronous cancellation mode is selected. */
+#define CANCELTYPE_BIT 1
+#define CANCELTYPE_BITMASK 0x02
+ /* Bit set if canceling has been initiated. */
+#define CANCELING_BIT 2
+#define CANCELING_BITMASK 0x04
+ /* Bit set if canceled. */
+#define CANCELED_BIT 3
+#define CANCELED_BITMASK 0x08
+ /* Bit set if thread is exiting. */
+#define EXITING_BIT 4
+#define EXITING_BITMASK 0x10
+ /* Bit set if thread terminated and TCB is freed. */
+#define TERMINATED_BIT 5
+#define TERMINATED_BITMASK 0x20
+ /* Bit set if thread is supposed to change XID. */
+#define SETXID_BIT 6
+#define SETXID_BITMASK 0x40
+ /* Mask for the rest. Helps the compiler to optimize. */
+#define CANCEL_RESTMASK 0xffffff80
+
+#define CANCEL_ENABLED_AND_CANCELED(value) \
+ (((value) & (CANCELSTATE_BITMASK | CANCELED_BITMASK | EXITING_BITMASK \
+ | CANCEL_RESTMASK | TERMINATED_BITMASK)) == CANCELED_BITMASK)
+#define CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS(value) \
+ (((value) & (CANCELSTATE_BITMASK | CANCELTYPE_BITMASK | CANCELED_BITMASK \
+ | EXITING_BITMASK | CANCEL_RESTMASK | TERMINATED_BITMASK)) \
+ == (CANCELTYPE_BITMASK | CANCELED_BITMASK))
+
+ /* We allocate one block of references here. This should be enough
+ to avoid allocating any memory dynamically for most applications. */
+ struct pthread_key_data
+ {
+ /* Sequence number. We use uintptr_t to not require padding on
+ 32- and 64-bit machines. On 64-bit machines it helps to avoid
+ wrapping, too. */
+ uintptr_t seq;
+
+ /* Data pointer. */
+ void *data;
+ } specific_1stblock[PTHREAD_KEY_2NDLEVEL_SIZE];
+
+ /* Two-level array for the thread-specific data. */
+ struct pthread_key_data *specific[PTHREAD_KEY_1STLEVEL_SIZE];
+
+ /* Flag which is set when specific data is set. */
+ bool specific_used;
+
+ /* True if events must be reported. */
+ bool report_events;
+
+ /* True if the user provided the stack. */
+ bool user_stack;
+
+ /* True if thread must stop at startup time. */
+ bool stopped_start;
+
+ /* Lock to synchronize access to the descriptor. */
+ lll_lock_t lock;
+
+ /* Lock for synchronizing setxid calls. */
+ lll_lock_t setxid_futex;
+
+#if HP_TIMING_AVAIL
+ /* Offset of the CPU clock at start thread start time. */
+ hp_timing_t cpuclock_offset;
+#endif
+
+ /* If the thread waits to join another one the ID of the latter is
+ stored here.
+
+ In case a thread is detached this field contains a pointer of the
+ TCB if the thread itself. This is something which cannot happen
+ in normal operation. */
+ struct pthread *joinid;
+ /* Check whether a thread is detached. */
+#define IS_DETACHED(pd) ((pd)->joinid == (pd))
+
+ /* Flags. Including those copied from the thread attribute. */
+ int flags;
+
+ /* The result of the thread function. */
+ void *result;
+
+ /* Scheduling parameters for the new thread. */
+ struct sched_param schedparam;
+ int schedpolicy;
+
+ /* Start position of the code to be executed and the argument passed
+ to the function. */
+ void *(*start_routine) (void *);
+ void *arg;
+
+ /* Debug state. */
+ td_eventbuf_t eventbuf;
+ /* Next descriptor with a pending event. */
+ struct pthread *nextevent;
+
+#ifdef HAVE_FORCED_UNWIND
+ /* Machine-specific unwind info. */
+ struct _Unwind_Exception exc;
+#endif
+
+ /* If nonzero pointer to area allocated for the stack and its
+ size. */
+ void *stackblock;
+ size_t stackblock_size;
+ /* Size of the included guard area. */
+ size_t guardsize;
+ /* This is what the user specified and what we will report. */
+ size_t reported_guardsize;
+
+ /* Thread Priority Protection data. */
+ struct priority_protection_data *tpp;
+
+ /* Resolver state. */
+ struct __res_state res;
+
+ /* This member must be last. */
+ char end_padding[];
+
+#define PTHREAD_STRUCT_END_PADDING \
+ (sizeof (struct pthread) - offsetof (struct pthread, end_padding))
+} __attribute ((aligned (TCB_ALIGNMENT)));
+
+
+#endif /* descr.h */
diff --git a/libc/nptl/eintr.c b/libc/nptl/eintr.c
new file mode 100644
index 000000000..933c5d81b
--- /dev/null
+++ b/libc/nptl/eintr.c
@@ -0,0 +1,89 @@
+/* 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>
+#include <signal.h>
+#include <unistd.h>
+
+
+static int the_sig;
+
+
+static void
+eintr_handler (int sig)
+{
+ if (sig != the_sig)
+ {
+ write (STDOUT_FILENO, "eintr_handler: signal number wrong\n", 35);
+ _exit (1);
+ }
+ write (STDOUT_FILENO, ".", 1);
+}
+
+
+static void *
+eintr_source (void *arg)
+{
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 500000 };
+
+ if (arg == NULL)
+ {
+ sigset_t ss;
+ sigemptyset (&ss);
+ sigaddset (&ss, the_sig);
+ pthread_sigmask (SIG_BLOCK, &ss, NULL);
+ }
+
+ while (1)
+ {
+ if (arg != NULL)
+ pthread_kill (*(pthread_t *) arg, the_sig);
+ else
+ kill (getpid (), the_sig);
+
+ nanosleep (&ts, NULL);
+ }
+
+ /* NOTREACHED */
+ return NULL;
+}
+
+
+static void
+setup_eintr (int sig, pthread_t *thp)
+{
+ struct sigaction sa;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = eintr_handler;
+ if (sigaction (sig, &sa, NULL) != 0)
+ {
+ puts ("setup_eintr: sigaction failed");
+ exit (1);
+ }
+ the_sig = sig;
+
+ /* Create the thread which will fire off the signals. */
+ pthread_t th;
+ if (pthread_create (&th, NULL, eintr_source, thp) != 0)
+ {
+ puts ("setup_eintr: pthread_create failed");
+ exit (1);
+ }
+}
diff --git a/libc/nptl/errno-loc.c b/libc/nptl/errno-loc.c
new file mode 100644
index 000000000..712b2b119
--- /dev/null
+++ b/libc/nptl/errno-loc.c
@@ -0,0 +1 @@
+#include "../csu/errno-loc.c"
diff --git a/libc/nptl/events.c b/libc/nptl/events.c
new file mode 100644
index 000000000..df97e54f6
--- /dev/null
+++ b/libc/nptl/events.c
@@ -0,0 +1,34 @@
+/* Event functions used while debugging.
+ Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* The functions contained here do nothing, they just return. */
+
+#include "pthreadP.h"
+
+void
+__nptl_create_event (void)
+{
+}
+hidden_def (__nptl_create_event)
+
+void
+__nptl_death_event (void)
+{
+}
+hidden_def (__nptl_death_event)
diff --git a/libc/nptl/forward.c b/libc/nptl/forward.c
new file mode 100644
index 000000000..e5f93d475
--- /dev/null
+++ b/libc/nptl/forward.c
@@ -0,0 +1,203 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <dlfcn.h>
+#include <pthreadP.h>
+#include <signal.h>
+#include <stdlib.h>
+
+#include <shlib-compat.h>
+#include <atomic.h>
+#include <sysdep.h>
+
+
+/* Pointers to the libc functions. */
+struct pthread_functions __libc_pthread_functions attribute_hidden;
+
+
+#define FORWARD2(name, rettype, decl, params, defaction) \
+rettype \
+name decl \
+{ \
+ if (__libc_pthread_functions.ptr_##name == NULL) \
+ defaction; \
+ \
+ return __libc_pthread_functions.ptr_##name params; \
+}
+
+#define FORWARD(name, decl, params, defretval) \
+ FORWARD2 (name, int, decl, params, return defretval)
+
+
+FORWARD (pthread_attr_destroy, (pthread_attr_t *attr), (attr), 0)
+
+#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_1)
+FORWARD (__pthread_attr_init_2_0, (pthread_attr_t *attr), (attr), 0)
+compat_symbol (libc, __pthread_attr_init_2_0, pthread_attr_init, GLIBC_2_0);
+#endif
+
+FORWARD (__pthread_attr_init_2_1, (pthread_attr_t *attr), (attr), 0)
+versioned_symbol (libc, __pthread_attr_init_2_1, pthread_attr_init, GLIBC_2_1);
+
+FORWARD (pthread_attr_getdetachstate,
+ (const pthread_attr_t *attr, int *detachstate), (attr, detachstate),
+ 0)
+FORWARD (pthread_attr_setdetachstate, (pthread_attr_t *attr, int detachstate),
+ (attr, detachstate), 0)
+
+FORWARD (pthread_attr_getinheritsched,
+ (const pthread_attr_t *attr, int *inherit), (attr, inherit), 0)
+FORWARD (pthread_attr_setinheritsched, (pthread_attr_t *attr, int inherit),
+ (attr, inherit), 0)
+
+FORWARD (pthread_attr_getschedparam,
+ (const pthread_attr_t *attr, struct sched_param *param),
+ (attr, param), 0)
+FORWARD (pthread_attr_setschedparam,
+ (pthread_attr_t *attr, const struct sched_param *param),
+ (attr, param), 0)
+
+FORWARD (pthread_attr_getschedpolicy,
+ (const pthread_attr_t *attr, int *policy), (attr, policy), 0)
+FORWARD (pthread_attr_setschedpolicy, (pthread_attr_t *attr, int policy),
+ (attr, policy), 0)
+
+FORWARD (pthread_attr_getscope,
+ (const pthread_attr_t *attr, int *scope), (attr, scope), 0)
+FORWARD (pthread_attr_setscope, (pthread_attr_t *attr, int scope),
+ (attr, scope), 0)
+
+
+FORWARD (pthread_condattr_destroy, (pthread_condattr_t *attr), (attr), 0)
+FORWARD (pthread_condattr_init, (pthread_condattr_t *attr), (attr), 0)
+
+#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
+FORWARD2 (__pthread_cond_broadcast_2_0, int attribute_compat_text_section,
+ (pthread_cond_2_0_t *cond), (cond), return 0)
+compat_symbol (libc, __pthread_cond_broadcast_2_0, pthread_cond_broadcast,
+ GLIBC_2_0);
+#endif
+FORWARD (__pthread_cond_broadcast, (pthread_cond_t *cond), (cond), 0)
+versioned_symbol (libc, __pthread_cond_broadcast, pthread_cond_broadcast,
+ GLIBC_2_3_2);
+
+#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
+FORWARD2 (__pthread_cond_destroy_2_0, int attribute_compat_text_section,
+ (pthread_cond_2_0_t *cond), (cond), return 0)
+compat_symbol (libc, __pthread_cond_destroy_2_0, pthread_cond_destroy,
+ GLIBC_2_0);
+#endif
+FORWARD (__pthread_cond_destroy, (pthread_cond_t *cond), (cond), 0)
+versioned_symbol (libc, __pthread_cond_destroy, pthread_cond_destroy,
+ GLIBC_2_3_2);
+
+#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
+FORWARD2 (__pthread_cond_init_2_0, int attribute_compat_text_section,
+ (pthread_cond_2_0_t *cond, const pthread_condattr_t *cond_attr),
+ (cond, cond_attr), return 0)
+compat_symbol (libc, __pthread_cond_init_2_0, pthread_cond_init, GLIBC_2_0);
+#endif
+FORWARD (__pthread_cond_init,
+ (pthread_cond_t *cond, const pthread_condattr_t *cond_attr),
+ (cond, cond_attr), 0)
+versioned_symbol (libc, __pthread_cond_init, pthread_cond_init, GLIBC_2_3_2);
+
+#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
+FORWARD2 (__pthread_cond_signal_2_0, int attribute_compat_text_section,
+ (pthread_cond_2_0_t *cond), (cond), return 0)
+compat_symbol (libc, __pthread_cond_signal_2_0, pthread_cond_signal,
+ GLIBC_2_0);
+#endif
+FORWARD (__pthread_cond_signal, (pthread_cond_t *cond), (cond), 0)
+versioned_symbol (libc, __pthread_cond_signal, pthread_cond_signal,
+ GLIBC_2_3_2);
+
+#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
+FORWARD2 (__pthread_cond_wait_2_0, int attribute_compat_text_section,
+ (pthread_cond_2_0_t *cond, pthread_mutex_t *mutex), (cond, mutex),
+ return 0)
+compat_symbol (libc, __pthread_cond_wait_2_0, pthread_cond_wait,
+ GLIBC_2_0);
+#endif
+FORWARD (__pthread_cond_wait, (pthread_cond_t *cond, pthread_mutex_t *mutex),
+ (cond, mutex), 0)
+versioned_symbol (libc, __pthread_cond_wait, pthread_cond_wait,
+ GLIBC_2_3_2);
+
+#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
+FORWARD2 (__pthread_cond_timedwait_2_0, int attribute_compat_text_section,
+ (pthread_cond_2_0_t *cond, pthread_mutex_t *mutex,
+ const struct timespec *abstime), (cond, mutex, abstime),
+ return 0)
+compat_symbol (libc, __pthread_cond_timedwait_2_0, pthread_cond_timedwait,
+ GLIBC_2_0);
+#endif
+FORWARD (__pthread_cond_timedwait,
+ (pthread_cond_t *cond, pthread_mutex_t *mutex,
+ const struct timespec *abstime), (cond, mutex, abstime), 0)
+versioned_symbol (libc, __pthread_cond_timedwait, pthread_cond_timedwait,
+ GLIBC_2_3_2);
+
+
+FORWARD (pthread_equal, (pthread_t thread1, pthread_t thread2),
+ (thread1, thread2), 1)
+
+
+/* Use an alias to avoid warning, as pthread_exit is declared noreturn. */
+FORWARD2 (__pthread_exit, void, (void *retval), (retval), exit (EXIT_SUCCESS))
+strong_alias (__pthread_exit, pthread_exit);
+
+
+FORWARD (pthread_getschedparam,
+ (pthread_t target_thread, int *policy, struct sched_param *param),
+ (target_thread, policy, param), 0)
+FORWARD (pthread_setschedparam,
+ (pthread_t target_thread, int policy,
+ const struct sched_param *param), (target_thread, policy, param), 0)
+
+
+FORWARD (pthread_mutex_destroy, (pthread_mutex_t *mutex), (mutex), 0)
+
+FORWARD (pthread_mutex_init,
+ (pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr),
+ (mutex, mutexattr), 0)
+
+FORWARD (pthread_mutex_lock, (pthread_mutex_t *mutex), (mutex), 0)
+
+FORWARD (pthread_mutex_unlock, (pthread_mutex_t *mutex), (mutex), 0)
+
+
+FORWARD2 (pthread_self, pthread_t, (void), (), return 0)
+
+
+FORWARD (pthread_setcancelstate, (int state, int *oldstate), (state, oldstate),
+ 0)
+
+FORWARD (pthread_setcanceltype, (int type, int *oldtype), (type, oldtype), 0)
+
+#define return /* value is void */
+FORWARD2(__pthread_unwind,
+ void attribute_hidden __attribute ((noreturn)) __cleanup_fct_attribute
+ attribute_compat_text_section,
+ (__pthread_unwind_buf_t *buf), (buf), {
+ /* We cannot call abort() here. */
+ INTERNAL_SYSCALL_DECL (err);
+ INTERNAL_SYSCALL (kill, err, 1, SIGKILL);
+ })
+#undef return
diff --git a/libc/nptl/herrno.c b/libc/nptl/herrno.c
new file mode 100644
index 000000000..6e8339d43
--- /dev/null
+++ b/libc/nptl/herrno.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 1996,97,98,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <features.h>
+#include <netdb.h>
+#undef h_errno
+
+#include <tls.h>
+
+/* We need to have the error status variable of the resolver
+ accessible in the libc. */
+extern __thread int h_errno;
+
+
+/* When threaded, h_errno may be a per-thread variable. */
+int *
+__h_errno_location (void)
+{
+ return &h_errno;
+}
diff --git a/libc/nptl/init.c b/libc/nptl/init.c
new file mode 100644
index 000000000..7cfe803c4
--- /dev/null
+++ b/libc/nptl/init.c
@@ -0,0 +1,398 @@
+/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include <limits.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/param.h>
+#include <sys/resource.h>
+#include <pthreadP.h>
+#include <atomic.h>
+#include <ldsodefs.h>
+#include <tls.h>
+#include <fork.h>
+#include <version.h>
+#include <shlib-compat.h>
+#include <smp.h>
+#include <lowlevellock.h>
+
+
+#ifndef __NR_set_tid_address
+/* XXX For the time being... Once we can rely on the kernel headers
+ having the definition remove these lines. */
+#if defined __s390__
+# define __NR_set_tid_address 252
+#elif defined __ia64__
+# define __NR_set_tid_address 1233
+#elif defined __i386__
+# define __NR_set_tid_address 258
+#elif defined __x86_64__
+# define __NR_set_tid_address 218
+#elif defined __powerpc__
+# define __NR_set_tid_address 232
+#elif defined __sparc__
+# define __NR_set_tid_address 166
+#else
+# error "define __NR_set_tid_address"
+#endif
+#endif
+
+
+/* Size and alignment of static TLS block. */
+size_t __static_tls_size;
+size_t __static_tls_align_m1;
+
+#ifndef __ASSUME_SET_ROBUST_LIST
+/* Negative if we do not have the system call and we can use it. */
+int __set_robust_list_avail;
+# define set_robust_list_not_avail() \
+ __set_robust_list_avail = -1
+#else
+# define set_robust_list_not_avail() do { } while (0)
+#endif
+
+/* Version of the library, used in libthread_db to detect mismatches. */
+static const char nptl_version[] __attribute_used__ = VERSION;
+
+
+#if defined USE_TLS && !defined SHARED
+extern void __libc_setup_tls (size_t tcbsize, size_t tcbalign);
+#endif
+
+
+#ifdef SHARED
+static const struct pthread_functions pthread_functions =
+ {
+ .ptr_pthread_attr_destroy = __pthread_attr_destroy,
+# if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1)
+ .ptr___pthread_attr_init_2_0 = __pthread_attr_init_2_0,
+# endif
+ .ptr___pthread_attr_init_2_1 = __pthread_attr_init_2_1,
+ .ptr_pthread_attr_getdetachstate = __pthread_attr_getdetachstate,
+ .ptr_pthread_attr_setdetachstate = __pthread_attr_setdetachstate,
+ .ptr_pthread_attr_getinheritsched = __pthread_attr_getinheritsched,
+ .ptr_pthread_attr_setinheritsched = __pthread_attr_setinheritsched,
+ .ptr_pthread_attr_getschedparam = __pthread_attr_getschedparam,
+ .ptr_pthread_attr_setschedparam = __pthread_attr_setschedparam,
+ .ptr_pthread_attr_getschedpolicy = __pthread_attr_getschedpolicy,
+ .ptr_pthread_attr_setschedpolicy = __pthread_attr_setschedpolicy,
+ .ptr_pthread_attr_getscope = __pthread_attr_getscope,
+ .ptr_pthread_attr_setscope = __pthread_attr_setscope,
+ .ptr_pthread_condattr_destroy = __pthread_condattr_destroy,
+ .ptr_pthread_condattr_init = __pthread_condattr_init,
+ .ptr___pthread_cond_broadcast = __pthread_cond_broadcast,
+ .ptr___pthread_cond_destroy = __pthread_cond_destroy,
+ .ptr___pthread_cond_init = __pthread_cond_init,
+ .ptr___pthread_cond_signal = __pthread_cond_signal,
+ .ptr___pthread_cond_wait = __pthread_cond_wait,
+ .ptr___pthread_cond_timedwait = __pthread_cond_timedwait,
+# if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_3_2)
+ .ptr___pthread_cond_broadcast_2_0 = __pthread_cond_broadcast_2_0,
+ .ptr___pthread_cond_destroy_2_0 = __pthread_cond_destroy_2_0,
+ .ptr___pthread_cond_init_2_0 = __pthread_cond_init_2_0,
+ .ptr___pthread_cond_signal_2_0 = __pthread_cond_signal_2_0,
+ .ptr___pthread_cond_wait_2_0 = __pthread_cond_wait_2_0,
+ .ptr___pthread_cond_timedwait_2_0 = __pthread_cond_timedwait_2_0,
+# endif
+ .ptr_pthread_equal = __pthread_equal,
+ .ptr___pthread_exit = __pthread_exit,
+ .ptr_pthread_getschedparam = __pthread_getschedparam,
+ .ptr_pthread_setschedparam = __pthread_setschedparam,
+ .ptr_pthread_mutex_destroy = INTUSE(__pthread_mutex_destroy),
+ .ptr_pthread_mutex_init = INTUSE(__pthread_mutex_init),
+ .ptr_pthread_mutex_lock = INTUSE(__pthread_mutex_lock),
+ .ptr_pthread_mutex_unlock = INTUSE(__pthread_mutex_unlock),
+ .ptr_pthread_self = __pthread_self,
+ .ptr_pthread_setcancelstate = __pthread_setcancelstate,
+ .ptr_pthread_setcanceltype = __pthread_setcanceltype,
+ .ptr___pthread_cleanup_upto = __pthread_cleanup_upto,
+ .ptr___pthread_once = __pthread_once_internal,
+ .ptr___pthread_rwlock_rdlock = __pthread_rwlock_rdlock_internal,
+ .ptr___pthread_rwlock_wrlock = __pthread_rwlock_wrlock_internal,
+ .ptr___pthread_rwlock_unlock = __pthread_rwlock_unlock_internal,
+ .ptr___pthread_key_create = __pthread_key_create_internal,
+ .ptr___pthread_getspecific = __pthread_getspecific_internal,
+ .ptr___pthread_setspecific = __pthread_setspecific_internal,
+ .ptr__pthread_cleanup_push_defer = __pthread_cleanup_push_defer,
+ .ptr__pthread_cleanup_pop_restore = __pthread_cleanup_pop_restore,
+ .ptr_nthreads = &__nptl_nthreads,
+ .ptr___pthread_unwind = &__pthread_unwind,
+ .ptr__nptl_deallocate_tsd = __nptl_deallocate_tsd,
+ .ptr__nptl_setxid = __nptl_setxid
+ };
+# define ptr_pthread_functions &pthread_functions
+#else
+# define ptr_pthread_functions NULL
+#endif
+
+
+/* For asynchronous cancellation we use a signal. This is the handler. */
+static void
+sigcancel_handler (int sig, siginfo_t *si, void *ctx)
+{
+#ifdef __ASSUME_CORRECT_SI_PID
+ /* Determine the process ID. It might be negative if the thread is
+ in the middle of a fork() call. */
+ pid_t pid = THREAD_GETMEM (THREAD_SELF, pid);
+ if (__builtin_expect (pid < 0, 0))
+ pid = -pid;
+#endif
+
+ /* Safety check. It would be possible to call this function for
+ other signals and send a signal from another process. This is not
+ correct and might even be a security problem. Try to catch as
+ many incorrect invocations as possible. */
+ if (sig != SIGCANCEL
+#ifdef __ASSUME_CORRECT_SI_PID
+ /* Kernels before 2.5.75 stored the thread ID and not the process
+ ID in si_pid so we skip this test. */
+ || si->si_pid != pid
+#endif
+ || si->si_code != SI_TKILL)
+ return;
+
+ struct pthread *self = THREAD_SELF;
+
+ int oldval = THREAD_GETMEM (self, cancelhandling);
+ while (1)
+ {
+ /* We are canceled now. When canceled by another thread this flag
+ is already set but if the signal is directly send (internally or
+ from another process) is has to be done here. */
+ int newval = oldval | CANCELING_BITMASK | CANCELED_BITMASK;
+
+ if (oldval == newval || (oldval & EXITING_BITMASK) != 0)
+ /* Already canceled or exiting. */
+ break;
+
+ int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
+ oldval);
+ if (curval == oldval)
+ {
+ /* Set the return value. */
+ THREAD_SETMEM (self, result, PTHREAD_CANCELED);
+
+ /* Make sure asynchronous cancellation is still enabled. */
+ if ((newval & CANCELTYPE_BITMASK) != 0)
+ /* Run the registered destructors and terminate the thread. */
+ __do_cancel ();
+
+ break;
+ }
+
+ oldval = curval;
+ }
+}
+
+
+struct xid_command *__xidcmd attribute_hidden;
+
+/* For asynchronous cancellation we use a signal. This is the handler. */
+static void
+sighandler_setxid (int sig, siginfo_t *si, void *ctx)
+{
+#ifdef __ASSUME_CORRECT_SI_PID
+ /* Determine the process ID. It might be negative if the thread is
+ in the middle of a fork() call. */
+ pid_t pid = THREAD_GETMEM (THREAD_SELF, pid);
+ if (__builtin_expect (pid < 0, 0))
+ pid = -pid;
+#endif
+
+ /* Safety check. It would be possible to call this function for
+ other signals and send a signal from another process. This is not
+ correct and might even be a security problem. Try to catch as
+ many incorrect invocations as possible. */
+ if (sig != SIGSETXID
+#ifdef __ASSUME_CORRECT_SI_PID
+ /* Kernels before 2.5.75 stored the thread ID and not the process
+ ID in si_pid so we skip this test. */
+ || si->si_pid != pid
+#endif
+ || si->si_code != SI_TKILL)
+ return;
+
+ INTERNAL_SYSCALL_DECL (err);
+ INTERNAL_SYSCALL_NCS (__xidcmd->syscall_no, err, 3, __xidcmd->id[0],
+ __xidcmd->id[1], __xidcmd->id[2]);
+
+ if (atomic_decrement_val (&__xidcmd->cntr) == 0)
+ lll_futex_wake (&__xidcmd->cntr, 1);
+
+ /* Reset the SETXID flag. */
+ struct pthread *self = THREAD_SELF;
+ int flags = THREAD_GETMEM (self, cancelhandling);
+ THREAD_SETMEM (self, cancelhandling, flags & ~SETXID_BITMASK);
+
+ /* And release the futex. */
+ self->setxid_futex = 1;
+ lll_futex_wake (&self->setxid_futex, 1);
+}
+
+
+/* When using __thread for this, we do it in libc so as not
+ to give libpthread its own TLS segment just for this. */
+extern void **__libc_dl_error_tsd (void) __attribute__ ((const));
+
+
+void
+__pthread_initialize_minimal_internal (void)
+{
+#ifndef SHARED
+ /* Unlike in the dynamically linked case the dynamic linker has not
+ taken care of initializing the TLS data structures. */
+ __libc_setup_tls (TLS_TCB_SIZE, TLS_TCB_ALIGN);
+
+ /* We must prevent gcc from being clever and move any of the
+ following code ahead of the __libc_setup_tls call. This function
+ will initialize the thread register which is subsequently
+ used. */
+ __asm __volatile ("");
+#endif
+
+ /* Minimal initialization of the thread descriptor. */
+ struct pthread *pd = THREAD_SELF;
+ INTERNAL_SYSCALL_DECL (err);
+ pd->pid = pd->tid = INTERNAL_SYSCALL (set_tid_address, err, 1, &pd->tid);
+ THREAD_SETMEM (pd, specific[0], &pd->specific_1stblock[0]);
+ THREAD_SETMEM (pd, user_stack, true);
+ if (LLL_LOCK_INITIALIZER != 0)
+ THREAD_SETMEM (pd, lock, LLL_LOCK_INITIALIZER);
+#if HP_TIMING_AVAIL
+ THREAD_SETMEM (pd, cpuclock_offset, GL(dl_cpuclock_offset));
+#endif
+
+ /* Initialize the robust mutex data. */
+#ifdef __PTHREAD_MUTEX_HAVE_PREV
+ pd->robust_prev = &pd->robust_head;
+#endif
+ pd->robust_head.list = &pd->robust_head;
+#ifdef __NR_set_robust_list
+ pd->robust_head.futex_offset = (offsetof (pthread_mutex_t, __data.__lock)
+ - offsetof (pthread_mutex_t,
+ __data.__list.__next));
+ int res = INTERNAL_SYSCALL (set_robust_list, err, 2, &pd->robust_head,
+ sizeof (struct robust_list_head));
+ if (INTERNAL_SYSCALL_ERROR_P (res, err))
+#endif
+ set_robust_list_not_avail ();
+
+ /* Set initial thread's stack block from 0 up to __libc_stack_end.
+ It will be bigger than it actually is, but for unwind.c/pt-longjmp.c
+ purposes this is good enough. */
+ THREAD_SETMEM (pd, stackblock_size, (size_t) __libc_stack_end);
+
+ /* Initialize the list of all running threads with the main thread. */
+ INIT_LIST_HEAD (&__stack_user);
+ list_add (&pd->list, &__stack_user);
+
+
+ /* Install the cancellation signal handler. If for some reason we
+ cannot install the handler we do not abort. Maybe we should, but
+ it is only asynchronous cancellation which is affected. */
+ struct sigaction sa;
+ sa.sa_sigaction = sigcancel_handler;
+ sa.sa_flags = SA_SIGINFO;
+ __sigemptyset (&sa.sa_mask);
+
+ (void) __libc_sigaction (SIGCANCEL, &sa, NULL);
+
+ /* Install the handle to change the threads' uid/gid. */
+ sa.sa_sigaction = sighandler_setxid;
+ sa.sa_flags = SA_SIGINFO | SA_RESTART;
+
+ (void) __libc_sigaction (SIGSETXID, &sa, NULL);
+
+ /* The parent process might have left the signals blocked. Just in
+ case, unblock it. We reuse the signal mask in the sigaction
+ structure. It is already cleared. */
+ __sigaddset (&sa.sa_mask, SIGCANCEL);
+ __sigaddset (&sa.sa_mask, SIGSETXID);
+ (void) INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_UNBLOCK, &sa.sa_mask,
+ NULL, _NSIG / 8);
+
+ /* Get the size of the static and alignment requirements for the TLS
+ block. */
+ size_t static_tls_align;
+ _dl_get_tls_static_info (&__static_tls_size, &static_tls_align);
+
+ /* Make sure the size takes all the alignments into account. */
+ if (STACK_ALIGN > static_tls_align)
+ static_tls_align = STACK_ALIGN;
+ __static_tls_align_m1 = static_tls_align - 1;
+
+ __static_tls_size = roundup (__static_tls_size, static_tls_align);
+
+ /* Determine the default allowed stack size. This is the size used
+ in case the user does not specify one. */
+ struct rlimit limit;
+ if (getrlimit (RLIMIT_STACK, &limit) != 0
+ || limit.rlim_cur == RLIM_INFINITY)
+ /* The system limit is not usable. Use an architecture-specific
+ default. */
+ limit.rlim_cur = ARCH_STACK_DEFAULT_SIZE;
+ else if (limit.rlim_cur < PTHREAD_STACK_MIN)
+ /* The system limit is unusably small.
+ Use the minimal size acceptable. */
+ limit.rlim_cur = PTHREAD_STACK_MIN;
+
+ /* Make sure it meets the minimum size that allocate_stack
+ (allocatestack.c) will demand, which depends on the page size. */
+ const uintptr_t pagesz = __sysconf (_SC_PAGESIZE);
+ const size_t minstack = pagesz + __static_tls_size + MINIMAL_REST_STACK;
+ if (limit.rlim_cur < minstack)
+ limit.rlim_cur = minstack;
+
+ /* Round the resource limit up to page size. */
+ limit.rlim_cur = (limit.rlim_cur + pagesz - 1) & -pagesz;
+ __default_stacksize = limit.rlim_cur;
+
+#ifdef SHARED
+ /* Transfer the old value from the dynamic linker's internal location. */
+ *__libc_dl_error_tsd () = *(*GL(dl_error_catch_tsd)) ();
+ GL(dl_error_catch_tsd) = &__libc_dl_error_tsd;
+
+ /* Make __rtld_lock_{,un}lock_recursive use pthread_mutex_{,un}lock,
+ keep the lock count from the ld.so implementation. */
+ GL(dl_rtld_lock_recursive) = (void *) INTUSE (__pthread_mutex_lock);
+ GL(dl_rtld_unlock_recursive) = (void *) INTUSE (__pthread_mutex_unlock);
+ unsigned int rtld_lock_count = GL(dl_load_lock).mutex.__data.__count;
+ GL(dl_load_lock).mutex.__data.__count = 0;
+ while (rtld_lock_count-- > 0)
+ INTUSE (__pthread_mutex_lock) (&GL(dl_load_lock).mutex);
+
+ GL(dl_make_stack_executable_hook) = &__make_stacks_executable;
+#endif
+
+ GL(dl_init_static_tls) = &__pthread_init_static_tls;
+
+ /* Register the fork generation counter with the libc. */
+#ifndef TLS_MULTIPLE_THREADS_IN_TCB
+ __libc_multiple_threads_ptr =
+#endif
+ __libc_pthread_init (&__fork_generation, __reclaim_stacks,
+ ptr_pthread_functions);
+
+ /* Determine whether the machine is SMP or not. */
+ __is_smp = is_smp_system ();
+}
+strong_alias (__pthread_initialize_minimal_internal,
+ __pthread_initialize_minimal)
diff --git a/libc/nptl/libc-cancellation.c b/libc/nptl/libc-cancellation.c
new file mode 100644
index 000000000..b88a32fef
--- /dev/null
+++ b/libc/nptl/libc-cancellation.c
@@ -0,0 +1,116 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <setjmp.h>
+#include <stdlib.h>
+#include "pthreadP.h"
+#include <atomic.h>
+#include <bits/libc-lock.h>
+
+
+#ifndef NOT_IN_libc
+
+/* The next two functions are similar to pthread_setcanceltype() but
+ more specialized for the use in the cancelable functions like write().
+ They do not need to check parameters etc. */
+int
+attribute_hidden
+__libc_enable_asynccancel (void)
+{
+ struct pthread *self = THREAD_SELF;
+ int oldval = THREAD_GETMEM (self, cancelhandling);
+
+ while (1)
+ {
+ int newval = oldval | CANCELTYPE_BITMASK;
+
+ if (__builtin_expect ((oldval & CANCELED_BITMASK) != 0, 0))
+ {
+ /* If we are already exiting or if PTHREAD_CANCEL_DISABLED,
+ stop right here. */
+ if ((oldval & (EXITING_BITMASK | CANCELSTATE_BITMASK)) != 0)
+ break;
+
+ int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling,
+ newval, oldval);
+ if (__builtin_expect (curval != oldval, 0))
+ {
+ /* Somebody else modified the word, try again. */
+ oldval = curval;
+ continue;
+ }
+
+ THREAD_SETMEM (self, result, PTHREAD_CANCELED);
+
+ __do_cancel ();
+
+ /* NOTREACHED */
+ }
+
+ int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
+ oldval);
+ if (__builtin_expect (curval == oldval, 1))
+ break;
+
+ /* Prepare the next round. */
+ oldval = curval;
+ }
+
+ return oldval;
+}
+
+
+void
+internal_function attribute_hidden
+__libc_disable_asynccancel (int oldtype)
+{
+ /* If asynchronous cancellation was enabled before we do not have
+ anything to do. */
+ if (oldtype & CANCELTYPE_BITMASK)
+ return;
+
+ struct pthread *self = THREAD_SELF;
+ int oldval = THREAD_GETMEM (self, cancelhandling);
+
+ while (1)
+ {
+ int newval = oldval & ~CANCELTYPE_BITMASK;
+
+ if (newval == oldval)
+ break;
+
+ int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
+ oldval);
+ if (__builtin_expect (curval == oldval, 1))
+ break;
+
+ /* Prepare the next round. */
+ oldval = curval;
+ }
+}
+
+
+void
+__libc_cleanup_routine (struct __pthread_cleanup_frame *f)
+{
+ if (f->__do_it)
+ f->__cancel_routine (f->__cancel_arg);
+}
+
+#endif
diff --git a/libc/nptl/lowlevellock.h b/libc/nptl/lowlevellock.h
new file mode 100644
index 000000000..338da3999
--- /dev/null
+++ b/libc/nptl/lowlevellock.h
@@ -0,0 +1,90 @@
+/* Low level locking macros used in NPTL implementation. Stub version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <atomic.h>
+
+
+/* Implement generic mutex. Basic futex syscall support is required:
+
+ lll_futex_wait(futex, value) - call sys_futex with FUTEX_WAIT
+ and third parameter VALUE
+
+ lll_futex_wake(futex, value) - call sys_futex with FUTEX_WAKE
+ and third parameter VALUE
+*/
+
+
+/* Mutex lock counter:
+ bit 31 clear means unlocked;
+ bit 31 set means locked.
+
+ All code that looks at bit 31 first increases the 'number of
+ interested threads' usage counter, which is in bits 0-30.
+
+ All negative mutex values indicate that the mutex is still locked. */
+
+
+static inline void
+__generic_mutex_lock (int *mutex)
+{
+ unsigned int v;
+
+ /* Bit 31 was clear, we got the mutex. (this is the fastpath). */
+ if (atomic_bit_test_set (mutex, 31) == 0)
+ return;
+
+ atomic_increment (mutex);
+
+ while (1)
+ {
+ if (atomic_bit_test_set (mutex, 31) == 0)
+ {
+ atomic_decrement (mutex);
+ return;
+ }
+
+ /* We have to wait now. First make sure the futex value we are
+ monitoring is truly negative (i.e. locked). */
+ v = *mutex;
+ if (v >= 0)
+ continue;
+
+ lll_futex_wait (mutex, v);
+ }
+}
+
+
+static inline void
+__generic_mutex_unlock (int *mutex)
+{
+ /* Adding 0x80000000 to the counter results in 0 if and only if
+ there are not other interested threads - we can return (this is
+ the fastpath). */
+ if (atomic_add_zero (mutex, 0x80000000))
+ return;
+
+ /* There are other threads waiting for this mutex, wake one of them
+ up. */
+ lll_futex_wake (mutex, 1);
+}
+
+
+#define lll_mutex_lock(futex) __generic_mutex_lock (&(futex))
+#define lll_mutex_unlock(futex) __generic_mutex_unlock (&(futex))
diff --git a/libc/nptl/old_pthread_atfork.c b/libc/nptl/old_pthread_atfork.c
new file mode 100644
index 000000000..768e6876c
--- /dev/null
+++ b/libc/nptl/old_pthread_atfork.c
@@ -0,0 +1,27 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <shlib-compat.h>
+
+#if SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_3)
+# define __pthread_atfork __dyn_pthread_atfork
+# include "pthread_atfork.c"
+# undef __pthread_atfork
+compat_symbol (libpthread, __dyn_pthread_atfork, pthread_atfork, GLIBC_2_0);
+#endif
diff --git a/libc/nptl/old_pthread_cond_broadcast.c b/libc/nptl/old_pthread_cond_broadcast.c
new file mode 100644
index 000000000..3852943fa
--- /dev/null
+++ b/libc/nptl/old_pthread_cond_broadcast.c
@@ -0,0 +1,58 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <stdlib.h>
+#include "pthreadP.h"
+#include <atomic.h>
+#include <shlib-compat.h>
+
+
+#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_3_2)
+int
+__pthread_cond_broadcast_2_0 (cond)
+ pthread_cond_2_0_t *cond;
+{
+ if (cond->cond == NULL)
+ {
+ pthread_cond_t *newcond;
+
+#if LLL_MUTEX_LOCK_INITIALIZER == 0
+ newcond = (pthread_cond_t *) calloc (sizeof (pthread_cond_t), 1);
+ if (newcond == NULL)
+ return ENOMEM;
+#else
+ newcond = (pthread_cond_t *) malloc (sizeof (pthread_cond_t));
+ if (newcond == NULL)
+ return ENOMEM;
+
+ /* Initialize the condvar. */
+ (void) pthread_cond_init (newcond, NULL);
+#endif
+
+ if (atomic_compare_and_exchange_bool_acq (&cond->cond, newcond, NULL))
+ /* Somebody else just initialized the condvar. */
+ free (newcond);
+ }
+
+ return __pthread_cond_broadcast (cond->cond);
+}
+compat_symbol (libpthread, __pthread_cond_broadcast_2_0,
+ pthread_cond_broadcast, GLIBC_2_0);
+#endif
diff --git a/libc/nptl/old_pthread_cond_destroy.c b/libc/nptl/old_pthread_cond_destroy.c
new file mode 100644
index 000000000..f6dba1188
--- /dev/null
+++ b/libc/nptl/old_pthread_cond_destroy.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <stdlib.h>
+#include "pthreadP.h"
+#include <shlib-compat.h>
+
+
+#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_3_2)
+int
+__pthread_cond_destroy_2_0 (cond)
+ pthread_cond_2_0_t *cond;
+{
+ /* Free the memory which was eventually allocated. */
+ free (cond->cond);
+
+ return 0;
+}
+compat_symbol (libpthread, __pthread_cond_destroy_2_0, pthread_cond_destroy,
+ GLIBC_2_0);
+#endif
diff --git a/libc/nptl/old_pthread_cond_init.c b/libc/nptl/old_pthread_cond_init.c
new file mode 100644
index 000000000..47e68b000
--- /dev/null
+++ b/libc/nptl/old_pthread_cond_init.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include "pthreadP.h"
+#include <shlib-compat.h>
+
+
+#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_3_2)
+int
+__pthread_cond_init_2_0 (cond, cond_attr)
+ pthread_cond_2_0_t *cond;
+ const pthread_condattr_t *cond_attr;
+{
+ struct pthread_condattr *icond_attr = (struct pthread_condattr *) cond_attr;
+
+ /* The type of the first argument is actually that of the old, too
+ small pthread_cond_t. We use only the first word of it, as a
+ pointer. */
+ cond->cond = NULL;
+
+ /* We can't support PSHARED condvars in the old pthread_cond_*
+ functions and neither clocks other than CLOCK_REALTIME. */
+ if (icond_attr != NULL && icond_attr->value)
+ return EINVAL;
+
+ return 0;
+}
+compat_symbol (libpthread, __pthread_cond_init_2_0, pthread_cond_init,
+ GLIBC_2_0);
+#endif
diff --git a/libc/nptl/old_pthread_cond_signal.c b/libc/nptl/old_pthread_cond_signal.c
new file mode 100644
index 000000000..65beb0b9d
--- /dev/null
+++ b/libc/nptl/old_pthread_cond_signal.c
@@ -0,0 +1,58 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <stdlib.h>
+#include "pthreadP.h"
+#include <atomic.h>
+#include <shlib-compat.h>
+
+
+#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_3_2)
+int
+__pthread_cond_signal_2_0 (cond)
+ pthread_cond_2_0_t *cond;
+{
+ if (cond->cond == NULL)
+ {
+ pthread_cond_t *newcond;
+
+#if LLL_MUTEX_LOCK_INITIALIZER == 0
+ newcond = (pthread_cond_t *) calloc (sizeof (pthread_cond_t), 1);
+ if (newcond == NULL)
+ return ENOMEM;
+#else
+ newcond = (pthread_cond_t *) malloc (sizeof (pthread_cond_t));
+ if (newcond == NULL)
+ return ENOMEM;
+
+ /* Initialize the condvar. */
+ (void) pthread_cond_init (newcond, NULL);
+#endif
+
+ if (atomic_compare_and_exchange_bool_acq (&cond->cond, newcond, NULL))
+ /* Somebody else just initialized the condvar. */
+ free (newcond);
+ }
+
+ return __pthread_cond_signal (cond->cond);
+}
+compat_symbol (libpthread, __pthread_cond_signal_2_0, pthread_cond_signal,
+ GLIBC_2_0);
+#endif
diff --git a/libc/nptl/old_pthread_cond_timedwait.c b/libc/nptl/old_pthread_cond_timedwait.c
new file mode 100644
index 000000000..27c10938d
--- /dev/null
+++ b/libc/nptl/old_pthread_cond_timedwait.c
@@ -0,0 +1,60 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <stdlib.h>
+#include "pthreadP.h"
+#include <atomic.h>
+#include <shlib-compat.h>
+
+
+#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_3_2)
+int
+__pthread_cond_timedwait_2_0 (cond, mutex, abstime)
+ pthread_cond_2_0_t *cond;
+ pthread_mutex_t *mutex;
+ const struct timespec *abstime;
+{
+ if (cond->cond == NULL)
+ {
+ pthread_cond_t *newcond;
+
+#if LLL_MUTEX_LOCK_INITIALIZER == 0
+ newcond = (pthread_cond_t *) calloc (sizeof (pthread_cond_t), 1);
+ if (newcond == NULL)
+ return ENOMEM;
+#else
+ newcond = (pthread_cond_t *) malloc (sizeof (pthread_cond_t));
+ if (newcond == NULL)
+ return ENOMEM;
+
+ /* Initialize the condvar. */
+ (void) pthread_cond_init (newcond, NULL);
+#endif
+
+ if (atomic_compare_and_exchange_bool_acq (&cond->cond, newcond, NULL))
+ /* Somebody else just initialized the condvar. */
+ free (newcond);
+ }
+
+ return __pthread_cond_timedwait (cond->cond, mutex, abstime);
+}
+compat_symbol (libpthread, __pthread_cond_timedwait_2_0,
+ pthread_cond_timedwait, GLIBC_2_0);
+#endif
diff --git a/libc/nptl/old_pthread_cond_wait.c b/libc/nptl/old_pthread_cond_wait.c
new file mode 100644
index 000000000..0a503a1cd
--- /dev/null
+++ b/libc/nptl/old_pthread_cond_wait.c
@@ -0,0 +1,59 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <stdlib.h>
+#include "pthreadP.h"
+#include <atomic.h>
+#include <shlib-compat.h>
+
+
+#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_3_2)
+int
+__pthread_cond_wait_2_0 (cond, mutex)
+ pthread_cond_2_0_t *cond;
+ pthread_mutex_t *mutex;
+{
+ if (cond->cond == NULL)
+ {
+ pthread_cond_t *newcond;
+
+#if LLL_MUTEX_LOCK_INITIALIZER == 0
+ newcond = (pthread_cond_t *) calloc (sizeof (pthread_cond_t), 1);
+ if (newcond == NULL)
+ return ENOMEM;
+#else
+ newcond = (pthread_cond_t *) malloc (sizeof (pthread_cond_t));
+ if (newcond == NULL)
+ return ENOMEM;
+
+ /* Initialize the condvar. */
+ (void) pthread_cond_init (newcond, NULL);
+#endif
+
+ if (atomic_compare_and_exchange_bool_acq (&cond->cond, newcond, NULL))
+ /* Somebody else just initialized the condvar. */
+ free (newcond);
+ }
+
+ return __pthread_cond_wait (cond->cond, mutex);
+}
+compat_symbol (libpthread, __pthread_cond_wait_2_0, pthread_cond_wait,
+ GLIBC_2_0);
+#endif
diff --git a/libc/nptl/perf.c b/libc/nptl/perf.c
new file mode 100644
index 000000000..f0dbc29ca
--- /dev/null
+++ b/libc/nptl/perf.c
@@ -0,0 +1,760 @@
+/* Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+#define _GNU_SOURCE 1
+#include <argp.h>
+#include <error.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/param.h>
+#include <sys/types.h>
+
+#ifndef MAX_THREADS
+# define MAX_THREADS 100000
+#endif
+#ifndef DEFAULT_THREADS
+# define DEFAULT_THREADS 50
+#endif
+
+
+#define OPT_TO_THREAD 300
+#define OPT_TO_PROCESS 301
+#define OPT_SYNC_SIGNAL 302
+#define OPT_SYNC_JOIN 303
+#define OPT_TOPLEVEL 304
+
+
+static const struct argp_option options[] =
+ {
+ { NULL, 0, NULL, 0, "\
+This is a test for threads so we allow ther user to selection the number of \
+threads which are used at any one time. Independently the total number of \
+rounds can be selected. This is the total number of threads which will have \
+run when the process terminates:" },
+ { "threads", 't', "NUMBER", 0, "Number of threads used at once" },
+ { "starts", 's', "NUMBER", 0, "Total number of working threads" },
+ { "toplevel", OPT_TOPLEVEL, "NUMBER", 0,
+ "Number of toplevel threads which start the other threads; this \
+implies --sync-join" },
+
+ { NULL, 0, NULL, 0, "\
+Each thread can do one of two things: sleep or do work. The latter is 100% \
+CPU bound. The work load is the probability a thread does work. All values \
+from zero to 100 (inclusive) are valid. How often each thread repeats this \
+can be determined by the number of rounds. The work cost determines how long \
+each work session (not sleeping) takes. If it is zero a thread would \
+effectively nothing. By setting the number of rounds to zero the thread \
+does no work at all and pure thread creation times can be measured." },
+ { "workload", 'w', "PERCENT", 0, "Percentage of time spent working" },
+ { "workcost", 'c', "NUMBER", 0,
+ "Factor in the cost of each round of working" },
+ { "rounds", 'r', "NUMBER", 0, "Number of rounds each thread runs" },
+
+ { NULL, 0, NULL, 0, "\
+There are a number of different methods how thread creation can be \
+synchronized. Synchronization is necessary since the number of concurrently \
+running threads is limited." },
+ { "sync-signal", OPT_SYNC_SIGNAL, NULL, 0,
+ "Synchronize using a signal (default)" },
+ { "sync-join", OPT_SYNC_JOIN, NULL, 0, "Synchronize using pthread_join" },
+
+ { NULL, 0, NULL, 0, "\
+One parameter for each threads execution is the size of the stack. If this \
+parameter is not used the system's default stack size is used. If many \
+threads are used the stack size should be chosen quite small." },
+ { "stacksize", 'S', "BYTES", 0, "Size of threads stack" },
+ { "guardsize", 'g', "BYTES", 0,
+ "Size of stack guard area; must fit into the stack" },
+
+ { NULL, 0, NULL, 0, "Signal options:" },
+ { "to-thread", OPT_TO_THREAD, NULL, 0, "Send signal to main thread" },
+ { "to-process", OPT_TO_PROCESS, NULL, 0,
+ "Send signal to process (default)" },
+
+ { NULL, 0, NULL, 0, "Administrative options:" },
+ { "progress", 'p', NULL, 0, "Show signs of progress" },
+ { "timing", 'T', NULL, 0,
+ "Measure time from startup to the last thread finishing" },
+ { NULL, 0, NULL, 0, NULL }
+ };
+
+/* Prototype for option handler. */
+static error_t parse_opt (int key, char *arg, struct argp_state *state);
+
+/* Data structure to communicate with argp functions. */
+static struct argp argp =
+{
+ options, parse_opt
+};
+
+
+static unsigned long int threads = DEFAULT_THREADS;
+static unsigned long int workload = 75;
+static unsigned long int workcost = 20;
+static unsigned long int rounds = 10;
+static long int starts = 5000;
+static unsigned long int stacksize;
+static long int guardsize = -1;
+static bool progress;
+static bool timing;
+static bool to_thread;
+static unsigned long int toplevel = 1;
+
+
+static long int running;
+static pthread_mutex_t running_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+static pid_t pid;
+static pthread_t tmain;
+
+static clockid_t cl;
+static struct timespec start_time;
+
+
+static pthread_mutex_t sum_mutex = PTHREAD_MUTEX_INITIALIZER;
+unsigned int sum;
+
+static enum
+ {
+ sync_signal,
+ sync_join
+ }
+sync_method;
+
+
+/* We use 64bit values for the times. */
+typedef unsigned long long int hp_timing_t;
+
+
+/* Attributes for all created threads. */
+static pthread_attr_t attr;
+
+
+static void *
+work (void *arg)
+{
+ unsigned long int i;
+ unsigned int state = (unsigned long int) arg;
+
+ for (i = 0; i < rounds; ++i)
+ {
+ /* Determine what to do. */
+ unsigned int rnum;
+
+ /* Uniform distribution. */
+ do
+ rnum = rand_r (&state);
+ while (rnum >= UINT_MAX - (UINT_MAX % 100));
+
+ rnum %= 100;
+
+ if (rnum < workload)
+ {
+ int j;
+ int a[4] = { i, rnum, i + rnum, rnum - i };
+
+ if (progress)
+ write (STDERR_FILENO, "c", 1);
+
+ for (j = 0; j < workcost; ++j)
+ {
+ a[0] += a[3] >> 12;
+ a[1] += a[2] >> 20;
+ a[2] += a[1] ^ 0x3423423;
+ a[3] += a[0] - a[1];
+ }
+
+ pthread_mutex_lock (&sum_mutex);
+ sum += a[0] + a[1] + a[2] + a[3];
+ pthread_mutex_unlock (&sum_mutex);
+ }
+ else
+ {
+ /* Just sleep. */
+ struct timespec tv;
+
+ tv.tv_sec = 0;
+ tv.tv_nsec = 10000000;
+
+ if (progress)
+ write (STDERR_FILENO, "w", 1);
+
+ nanosleep (&tv, NULL);
+ }
+ }
+
+ return NULL;
+}
+
+
+static void *
+thread_function (void *arg)
+{
+ work (arg);
+
+ pthread_mutex_lock (&running_mutex);
+ if (--running <= 0 && starts <= 0)
+ {
+ /* We are done. */
+ if (progress)
+ write (STDERR_FILENO, "\n", 1);
+
+ if (timing)
+ {
+ struct timespec end_time;
+
+ if (clock_gettime (cl, &end_time) == 0)
+ {
+ end_time.tv_sec -= start_time.tv_sec;
+ end_time.tv_nsec -= start_time.tv_nsec;
+ if (end_time.tv_nsec < 0)
+ {
+ end_time.tv_nsec += 1000000000;
+ --end_time.tv_sec;
+ }
+
+ printf ("\nRuntime: %lu.%09lu seconds\n",
+ (unsigned long int) end_time.tv_sec,
+ (unsigned long int) end_time.tv_nsec);
+ }
+ }
+
+ printf ("Result: %08x\n", sum);
+
+ exit (0);
+ }
+ pthread_mutex_unlock (&running_mutex);
+
+ if (sync_method == sync_signal)
+ {
+ if (to_thread)
+ /* This code sends a signal to the main thread. */
+ pthread_kill (tmain, SIGUSR1);
+ else
+ /* Use this code to test sending a signal to the process. */
+ kill (pid, SIGUSR1);
+ }
+
+ if (progress)
+ write (STDERR_FILENO, "f", 1);
+
+ return NULL;
+}
+
+
+struct start_info
+{
+ unsigned int starts;
+ unsigned int threads;
+};
+
+
+static void *
+start_threads (void *arg)
+{
+ struct start_info *si = arg;
+ unsigned int starts = si->starts;
+ pthread_t ths[si->threads];
+ unsigned int state = starts;
+ unsigned int n;
+ unsigned int i = 0;
+ int err;
+
+ if (progress)
+ write (STDERR_FILENO, "T", 1);
+
+ memset (ths, '\0', sizeof (pthread_t) * si->threads);
+
+ while (starts-- > 0)
+ {
+ if (ths[i] != 0)
+ {
+ /* Wait for the threads in the order they were created. */
+ err = pthread_join (ths[i], NULL);
+ if (err != 0)
+ error (EXIT_FAILURE, err, "cannot join thread");
+
+ if (progress)
+ write (STDERR_FILENO, "f", 1);
+ }
+
+ err = pthread_create (&ths[i], &attr, work,
+ (void *) (long) (rand_r (&state) + starts + i));
+
+ if (err != 0)
+ error (EXIT_FAILURE, err, "cannot start thread");
+
+ if (progress)
+ write (STDERR_FILENO, "t", 1);
+
+ if (++i == si->threads)
+ i = 0;
+ }
+
+ n = i;
+ do
+ {
+ if (ths[i] != 0)
+ {
+ err = pthread_join (ths[i], NULL);
+ if (err != 0)
+ error (EXIT_FAILURE, err, "cannot join thread");
+
+ if (progress)
+ write (STDERR_FILENO, "f", 1);
+ }
+
+ if (++i == si->threads)
+ i = 0;
+ }
+ while (i != n);
+
+ if (progress)
+ write (STDERR_FILENO, "F", 1);
+
+ return NULL;
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ int remaining;
+ sigset_t ss;
+ pthread_t th;
+ pthread_t *ths = NULL;
+ int empty = 0;
+ int last;
+ bool cont = true;
+
+ /* Parse and process arguments. */
+ argp_parse (&argp, argc, argv, 0, &remaining, NULL);
+
+ if (sync_method == sync_join)
+ {
+ ths = (pthread_t *) calloc (threads, sizeof (pthread_t));
+ if (ths == NULL)
+ error (EXIT_FAILURE, errno,
+ "cannot allocate memory for thread descriptor array");
+
+ last = threads;
+ }
+ else
+ {
+ ths = &th;
+ last = 1;
+ }
+
+ if (toplevel > threads)
+ {
+ printf ("resetting number of toplevel threads to %lu to not surpass number to concurrent threads\n",
+ threads);
+ toplevel = threads;
+ }
+
+ if (timing)
+ {
+ if (clock_getcpuclockid (0, &cl) != 0
+ || clock_gettime (cl, &start_time) != 0)
+ timing = false;
+ }
+
+ /* We need this later. */
+ pid = getpid ();
+ tmain = pthread_self ();
+
+ /* We use signal SIGUSR1 for communication between the threads and
+ the main thread. We only want sychronous notification. */
+ if (sync_method == sync_signal)
+ {
+ sigemptyset (&ss);
+ sigaddset (&ss, SIGUSR1);
+ if (sigprocmask (SIG_BLOCK, &ss, NULL) != 0)
+ error (EXIT_FAILURE, errno, "cannot set signal mask");
+ }
+
+ /* Create the thread attributes. */
+ pthread_attr_init (&attr);
+
+ /* If the user provided a stack size use it. */
+ if (stacksize != 0
+ && pthread_attr_setstacksize (&attr, stacksize) != 0)
+ puts ("could not set stack size; will use default");
+ /* And stack guard size. */
+ if (guardsize != -1
+ && pthread_attr_setguardsize (&attr, guardsize) != 0)
+ puts ("invalid stack guard size; will use default");
+
+ /* All threads are created detached if we are not using pthread_join
+ to synchronize. */
+ if (sync_method != sync_join)
+ pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
+
+ if (sync_method == sync_signal)
+ {
+ while (1)
+ {
+ int err;
+ bool do_wait = false;
+
+ pthread_mutex_lock (&running_mutex);
+ if (starts-- < 0)
+ cont = false;
+ else
+ do_wait = ++running >= threads && starts > 0;
+
+ pthread_mutex_unlock (&running_mutex);
+
+ if (! cont)
+ break;
+
+ if (progress)
+ write (STDERR_FILENO, "t", 1);
+
+ err = pthread_create (&ths[empty], &attr, thread_function,
+ (void *) starts);
+ if (err != 0)
+ error (EXIT_FAILURE, err, "cannot start thread %lu", starts);
+
+ if (++empty == last)
+ empty = 0;
+
+ if (do_wait)
+ sigwaitinfo (&ss, NULL);
+ }
+
+ /* Do nothing anymore. On of the threads will terminate the program. */
+ sigfillset (&ss);
+ sigdelset (&ss, SIGINT);
+ while (1)
+ sigsuspend (&ss);
+ }
+ else
+ {
+ pthread_t ths[toplevel];
+ struct start_info si[toplevel];
+ unsigned int i;
+
+ for (i = 0; i < toplevel; ++i)
+ {
+ unsigned int child_starts = starts / (toplevel - i);
+ unsigned int child_threads = threads / (toplevel - i);
+ int err;
+
+ si[i].starts = child_starts;
+ si[i].threads = child_threads;
+
+ err = pthread_create (&ths[i], &attr, start_threads, &si[i]);
+ if (err != 0)
+ error (EXIT_FAILURE, err, "cannot start thread");
+
+ starts -= child_starts;
+ threads -= child_threads;
+ }
+
+ for (i = 0; i < toplevel; ++i)
+ {
+ int err = pthread_join (ths[i], NULL);
+
+ if (err != 0)
+ error (EXIT_FAILURE, err, "cannot join thread");
+ }
+
+ /* We are done. */
+ if (progress)
+ write (STDERR_FILENO, "\n", 1);
+
+ if (timing)
+ {
+ struct timespec end_time;
+
+ if (clock_gettime (cl, &end_time) == 0)
+ {
+ end_time.tv_sec -= start_time.tv_sec;
+ end_time.tv_nsec -= start_time.tv_nsec;
+ if (end_time.tv_nsec < 0)
+ {
+ end_time.tv_nsec += 1000000000;
+ --end_time.tv_sec;
+ }
+
+ printf ("\nRuntime: %lu.%09lu seconds\n",
+ (unsigned long int) end_time.tv_sec,
+ (unsigned long int) end_time.tv_nsec);
+ }
+ }
+
+ printf ("Result: %08x\n", sum);
+
+ exit (0);
+ }
+
+ /* NOTREACHED */
+ return 0;
+}
+
+
+/* Handle program arguments. */
+static error_t
+parse_opt (int key, char *arg, struct argp_state *state)
+{
+ unsigned long int num;
+ long int snum;
+
+ switch (key)
+ {
+ case 't':
+ num = strtoul (arg, NULL, 0);
+ if (num <= MAX_THREADS)
+ threads = num;
+ else
+ printf ("\
+number of threads limited to %u; recompile with a higher limit if necessary",
+ MAX_THREADS);
+ break;
+
+ case 'w':
+ num = strtoul (arg, NULL, 0);
+ if (num <= 100)
+ workload = num;
+ else
+ puts ("workload must be between 0 and 100 percent");
+ break;
+
+ case 'c':
+ workcost = strtoul (arg, NULL, 0);
+ break;
+
+ case 'r':
+ rounds = strtoul (arg, NULL, 0);
+ break;
+
+ case 's':
+ starts = strtoul (arg, NULL, 0);
+ break;
+
+ case 'S':
+ num = strtoul (arg, NULL, 0);
+ if (num >= PTHREAD_STACK_MIN)
+ stacksize = num;
+ else
+ printf ("minimum stack size is %d\n", PTHREAD_STACK_MIN);
+ break;
+
+ case 'g':
+ snum = strtol (arg, NULL, 0);
+ if (snum < 0)
+ printf ("invalid guard size %s\n", arg);
+ else
+ guardsize = snum;
+ break;
+
+ case 'p':
+ progress = true;
+ break;
+
+ case 'T':
+ timing = true;
+ break;
+
+ case OPT_TO_THREAD:
+ to_thread = true;
+ break;
+
+ case OPT_TO_PROCESS:
+ to_thread = false;
+ break;
+
+ case OPT_SYNC_SIGNAL:
+ sync_method = sync_signal;
+ break;
+
+ case OPT_SYNC_JOIN:
+ sync_method = sync_join;
+ break;
+
+ case OPT_TOPLEVEL:
+ num = strtoul (arg, NULL, 0);
+ if (num < MAX_THREADS)
+ toplevel = num;
+ else
+ printf ("\
+number of threads limited to %u; recompile with a higher limit if necessary",
+ MAX_THREADS);
+ sync_method = sync_join;
+ break;
+
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+
+ return 0;
+}
+
+
+static hp_timing_t
+get_clockfreq (void)
+{
+ /* We read the information from the /proc filesystem. It contains at
+ least one line like
+ cpu MHz : 497.840237
+ or also
+ cpu MHz : 497.841
+ We search for this line and convert the number in an integer. */
+ static hp_timing_t result;
+ int fd;
+
+ /* If this function was called before, we know the result. */
+ if (result != 0)
+ return result;
+
+ fd = open ("/proc/cpuinfo", O_RDONLY);
+ if (__builtin_expect (fd != -1, 1))
+ {
+ /* XXX AFAIK the /proc filesystem can generate "files" only up
+ to a size of 4096 bytes. */
+ char buf[4096];
+ ssize_t n;
+
+ n = read (fd, buf, sizeof buf);
+ if (__builtin_expect (n, 1) > 0)
+ {
+ char *mhz = memmem (buf, n, "cpu MHz", 7);
+
+ if (__builtin_expect (mhz != NULL, 1))
+ {
+ char *endp = buf + n;
+ int seen_decpoint = 0;
+ int ndigits = 0;
+
+ /* Search for the beginning of the string. */
+ while (mhz < endp && (*mhz < '0' || *mhz > '9') && *mhz != '\n')
+ ++mhz;
+
+ while (mhz < endp && *mhz != '\n')
+ {
+ if (*mhz >= '0' && *mhz <= '9')
+ {
+ result *= 10;
+ result += *mhz - '0';
+ if (seen_decpoint)
+ ++ndigits;
+ }
+ else if (*mhz == '.')
+ seen_decpoint = 1;
+
+ ++mhz;
+ }
+
+ /* Compensate for missing digits at the end. */
+ while (ndigits++ < 6)
+ result *= 10;
+ }
+ }
+
+ close (fd);
+ }
+
+ return result;
+}
+
+
+int
+clock_getcpuclockid (pid_t pid, clockid_t *clock_id)
+{
+ /* We don't allow any process ID but our own. */
+ if (pid != 0 && pid != getpid ())
+ return EPERM;
+
+#ifdef CLOCK_PROCESS_CPUTIME_ID
+ /* Store the number. */
+ *clock_id = CLOCK_PROCESS_CPUTIME_ID;
+
+ return 0;
+#else
+ /* We don't have a timer for that. */
+ return ENOENT;
+#endif
+}
+
+
+#ifdef i386
+#define HP_TIMING_NOW(Var) __asm__ __volatile__ ("rdtsc" : "=A" (Var))
+#elif defined __x86_64__
+# define HP_TIMING_NOW(Var) \
+ ({ unsigned int _hi, _lo; \
+ asm volatile ("rdtsc" : "=a" (_lo), "=d" (_hi)); \
+ (Var) = ((unsigned long long int) _hi << 32) | _lo; })
+#elif defined __ia64__
+#define HP_TIMING_NOW(Var) __asm__ __volatile__ ("mov %0=ar.itc" : "=r" (Var) : : "memory")
+#else
+#error "HP_TIMING_NOW missing"
+#endif
+
+/* Get current value of CLOCK and store it in TP. */
+int
+clock_gettime (clockid_t clock_id, struct timespec *tp)
+{
+ int retval = -1;
+
+ switch (clock_id)
+ {
+ case CLOCK_PROCESS_CPUTIME_ID:
+ {
+
+ static hp_timing_t freq;
+ hp_timing_t tsc;
+
+ /* Get the current counter. */
+ HP_TIMING_NOW (tsc);
+
+ if (freq == 0)
+ {
+ freq = get_clockfreq ();
+ if (freq == 0)
+ return EINVAL;
+ }
+
+ /* Compute the seconds. */
+ tp->tv_sec = tsc / freq;
+
+ /* And the nanoseconds. This computation should be stable until
+ we get machines with about 16GHz frequency. */
+ tp->tv_nsec = ((tsc % freq) * UINT64_C (1000000000)) / freq;
+
+ retval = 0;
+ }
+ break;
+
+ default:
+ errno = EINVAL;
+ break;
+ }
+
+ return retval;
+}
diff --git a/libc/nptl/pt-allocrtsig.c b/libc/nptl/pt-allocrtsig.c
new file mode 100644
index 000000000..347bf139a
--- /dev/null
+++ b/libc/nptl/pt-allocrtsig.c
@@ -0,0 +1,51 @@
+/* Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <signal.h>
+
+
+/* These are defined in libc. We want to have only one definition
+ so we "forward" the calls. */
+extern int __libc_current_sigrtmin_private (void);
+extern int __libc_current_sigrtmax_private (void);
+extern int __libc_allocate_rtsig_private (int high);
+
+
+/* We reserve __SIGRTMIN for use as the cancellation signal and
+ __SIGRTMIN+1 to handle setuid et.al. These signals are used
+ internally. */
+int
+__libc_current_sigrtmin (void)
+{
+ return __libc_current_sigrtmin_private ();
+}
+
+
+int
+__libc_current_sigrtmax (void)
+{
+ return __libc_current_sigrtmax_private ();
+}
+
+
+int
+__libc_allocate_rtsig (int high)
+{
+ return __libc_allocate_rtsig_private (high);
+}
diff --git a/libc/nptl/pt-cleanup.c b/libc/nptl/pt-cleanup.c
new file mode 100644
index 000000000..f72ea26e9
--- /dev/null
+++ b/libc/nptl/pt-cleanup.c
@@ -0,0 +1,63 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <setjmp.h>
+#include <stdlib.h>
+#include "pthreadP.h"
+#include <jmpbuf-unwind.h>
+
+void
+__pthread_cleanup_upto (__jmp_buf target, char *targetframe)
+{
+ struct pthread *self = THREAD_SELF;
+ struct _pthread_cleanup_buffer *cbuf;
+
+ /* Adjust all pointers used in comparisons, so that top of thread's
+ stack is at the top of address space. Without that, things break
+ if stack is allocated above the main stack. */
+ uintptr_t adj = (uintptr_t) self->stackblock + self->stackblock_size;
+ uintptr_t targetframe_adj = (uintptr_t) targetframe - adj;
+
+ for (cbuf = THREAD_GETMEM (self, cleanup);
+ cbuf != NULL && _JMPBUF_UNWINDS_ADJ (target, cbuf, adj);
+ cbuf = cbuf->__prev)
+ {
+#if _STACK_GROWS_DOWN
+ if ((uintptr_t) cbuf - adj <= targetframe_adj)
+ {
+ cbuf = NULL;
+ break;
+ }
+#elif _STACK_GROWS_UP
+ if ((uintptr_t) cbuf - adj >= targetframe_adj)
+ {
+ cbuf = NULL;
+ break;
+ }
+#else
+# error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
+#endif
+
+ /* Call the cleanup code. */
+ cbuf->__routine (cbuf->__arg);
+ }
+
+ THREAD_SETMEM (self, cleanup, cbuf);
+}
+hidden_def (__pthread_cleanup_upto)
diff --git a/libc/nptl/pt-raise.c b/libc/nptl/pt-raise.c
new file mode 100644
index 000000000..a72cf8550
--- /dev/null
+++ b/libc/nptl/pt-raise.c
@@ -0,0 +1,31 @@
+/* ISO C raise function for libpthread.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <signal.h>
+
+
+int
+raise (sig)
+ int sig;
+{
+ /* This is what POSIX says must happen. */
+ return pthread_kill (pthread_self (), sig);
+}
diff --git a/libc/nptl/pt-system.c b/libc/nptl/pt-system.c
new file mode 100644
index 000000000..b3b45ab93
--- /dev/null
+++ b/libc/nptl/pt-system.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <stdlib.h>
+#include <sysdep.h>
+#include "pthreadP.h"
+
+
+int
+system (const char *line)
+{
+ return __libc_system (line);
+}
+
+/* __libc_system in libc.so handles cancellation. */
+LIBC_CANCEL_HANDLED ();
diff --git a/libc/nptl/pthread-errnos.sym b/libc/nptl/pthread-errnos.sym
new file mode 100644
index 000000000..2bb4d0d3c
--- /dev/null
+++ b/libc/nptl/pthread-errnos.sym
@@ -0,0 +1,12 @@
+#include <errno.h>
+
+-- These errno codes are used by some assembly code.
+
+EAGAIN EAGAIN
+EBUSY EBUSY
+EDEADLK EDEADLK
+EINTR EINTR
+EINVAL EINVAL
+ENOSYS ENOSYS
+ETIMEDOUT ETIMEDOUT
+EWOULDBLOCK EWOULDBLOCK
diff --git a/libc/nptl/pthreadP.h b/libc/nptl/pthreadP.h
new file mode 100644
index 000000000..503e99b2b
--- /dev/null
+++ b/libc/nptl/pthreadP.h
@@ -0,0 +1,563 @@
+/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+#ifndef _PTHREADP_H
+#define _PTHREADP_H 1
+
+#include <pthread.h>
+#include <setjmp.h>
+#include <stdbool.h>
+#include <sys/syscall.h>
+#include "descr.h"
+#include <tls.h>
+#include <lowlevellock.h>
+#include <stackinfo.h>
+#include <internaltypes.h>
+#include <pthread-functions.h>
+#include <atomic.h>
+#include <kernel-features.h>
+
+
+/* Atomic operations on TLS memory. */
+#ifndef THREAD_ATOMIC_CMPXCHG_VAL
+# define THREAD_ATOMIC_CMPXCHG_VAL(descr, member, new, old) \
+ atomic_compare_and_exchange_val_acq (&(descr)->member, new, old)
+#endif
+
+#ifndef THREAD_ATOMIC_BIT_SET
+# define THREAD_ATOMIC_BIT_SET(descr, member, bit) \
+ atomic_bit_set (&(descr)->member, bit)
+#endif
+
+
+/* Adaptive mutex definitions. */
+#ifndef MAX_ADAPTIVE_COUNT
+# define MAX_ADAPTIVE_COUNT 100
+#endif
+
+
+/* Magic cookie representing robust mutex with dead owner. */
+#define PTHREAD_MUTEX_INCONSISTENT INT_MAX
+/* Magic cookie representing not recoverable robust mutex. */
+#define PTHREAD_MUTEX_NOTRECOVERABLE (INT_MAX - 1)
+
+
+/* Internal mutex type value. */
+enum
+{
+ PTHREAD_MUTEX_KIND_MASK_NP = 3,
+ PTHREAD_MUTEX_ROBUST_NORMAL_NP = 16,
+ PTHREAD_MUTEX_ROBUST_RECURSIVE_NP
+ = PTHREAD_MUTEX_ROBUST_NORMAL_NP | PTHREAD_MUTEX_RECURSIVE_NP,
+ PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP
+ = PTHREAD_MUTEX_ROBUST_NORMAL_NP | PTHREAD_MUTEX_ERRORCHECK_NP,
+ PTHREAD_MUTEX_ROBUST_ADAPTIVE_NP
+ = PTHREAD_MUTEX_ROBUST_NORMAL_NP | PTHREAD_MUTEX_ADAPTIVE_NP,
+ PTHREAD_MUTEX_PRIO_INHERIT_NP = 32,
+ PTHREAD_MUTEX_PI_NORMAL_NP
+ = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_NORMAL,
+ PTHREAD_MUTEX_PI_RECURSIVE_NP
+ = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_RECURSIVE_NP,
+ PTHREAD_MUTEX_PI_ERRORCHECK_NP
+ = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ERRORCHECK_NP,
+ PTHREAD_MUTEX_PI_ADAPTIVE_NP
+ = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ADAPTIVE_NP,
+ PTHREAD_MUTEX_PI_ROBUST_NORMAL_NP
+ = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_NORMAL_NP,
+ PTHREAD_MUTEX_PI_ROBUST_RECURSIVE_NP
+ = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_RECURSIVE_NP,
+ PTHREAD_MUTEX_PI_ROBUST_ERRORCHECK_NP
+ = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP,
+ PTHREAD_MUTEX_PI_ROBUST_ADAPTIVE_NP
+ = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_ADAPTIVE_NP,
+ PTHREAD_MUTEX_PRIO_PROTECT_NP = 64,
+ PTHREAD_MUTEX_PP_NORMAL_NP
+ = PTHREAD_MUTEX_PRIO_PROTECT_NP | PTHREAD_MUTEX_NORMAL,
+ PTHREAD_MUTEX_PP_RECURSIVE_NP
+ = PTHREAD_MUTEX_PRIO_PROTECT_NP | PTHREAD_MUTEX_RECURSIVE_NP,
+ PTHREAD_MUTEX_PP_ERRORCHECK_NP
+ = PTHREAD_MUTEX_PRIO_PROTECT_NP | PTHREAD_MUTEX_ERRORCHECK_NP,
+ PTHREAD_MUTEX_PP_ADAPTIVE_NP
+ = PTHREAD_MUTEX_PRIO_PROTECT_NP | PTHREAD_MUTEX_ADAPTIVE_NP
+};
+
+/* Ceiling in __data.__lock. __data.__lock is signed, so don't
+ use the MSB bit in there, but in the mask also include that bit,
+ so that the compiler can optimize & PTHREAD_MUTEX_PRIO_CEILING_MASK
+ masking if the value is then shifted down by
+ PTHREAD_MUTEX_PRIO_CEILING_SHIFT. */
+#define PTHREAD_MUTEX_PRIO_CEILING_SHIFT 19
+#define PTHREAD_MUTEX_PRIO_CEILING_MASK 0xfff80000
+
+
+/* Flags in mutex attr. */
+#define PTHREAD_MUTEXATTR_PROTOCOL_SHIFT 28
+#define PTHREAD_MUTEXATTR_PROTOCOL_MASK 0x30000000
+#define PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT 12
+#define PTHREAD_MUTEXATTR_PRIO_CEILING_MASK 0x00fff000
+#define PTHREAD_MUTEXATTR_FLAG_ROBUST 0x40000000
+#define PTHREAD_MUTEXATTR_FLAG_PSHARED 0x80000000
+#define PTHREAD_MUTEXATTR_FLAG_BITS \
+ (PTHREAD_MUTEXATTR_FLAG_ROBUST | PTHREAD_MUTEXATTR_FLAG_PSHARED \
+ | PTHREAD_MUTEXATTR_PROTOCOL_MASK | PTHREAD_MUTEXATTR_PRIO_CEILING_MASK)
+
+
+/* Bits used in robust mutex implementation. */
+#define FUTEX_WAITERS 0x80000000
+#define FUTEX_OWNER_DIED 0x40000000
+#define FUTEX_TID_MASK 0x3fffffff
+
+
+/* Internal variables. */
+
+
+/* Default stack size. */
+extern size_t __default_stacksize attribute_hidden;
+
+/* Size and alignment of static TLS block. */
+extern size_t __static_tls_size attribute_hidden;
+extern size_t __static_tls_align_m1 attribute_hidden;
+
+/* Flag whether the machine is SMP or not. */
+extern int __is_smp attribute_hidden;
+
+/* Thread descriptor handling. */
+extern list_t __stack_user;
+hidden_proto (__stack_user)
+
+/* Attribute handling. */
+extern struct pthread_attr *__attr_list attribute_hidden;
+extern lll_lock_t __attr_list_lock attribute_hidden;
+
+/* First available RT signal. */
+extern int __current_sigrtmin attribute_hidden;
+/* Last available RT signal. */
+extern int __current_sigrtmax attribute_hidden;
+
+/* Concurrency handling. */
+extern int __concurrency_level attribute_hidden;
+
+/* Thread-local data key handling. */
+extern struct pthread_key_struct __pthread_keys[PTHREAD_KEYS_MAX];
+hidden_proto (__pthread_keys)
+
+/* Number of threads running. */
+extern unsigned int __nptl_nthreads attribute_hidden;
+
+#ifndef __ASSUME_SET_ROBUST_LIST
+/* Negative if we do not have the system call and we can use it. */
+extern int __set_robust_list_avail attribute_hidden;
+#endif
+
+/* Thread Priority Protection. */
+extern int __sched_fifo_min_prio attribute_hidden;
+extern int __sched_fifo_max_prio attribute_hidden;
+extern void __init_sched_fifo_prio (void) attribute_hidden;
+extern int __pthread_tpp_change_priority (int prev_prio, int new_prio)
+ attribute_hidden;
+extern int __pthread_current_priority (void) attribute_hidden;
+
+/* The library can run in debugging mode where it performs a lot more
+ tests. */
+extern int __pthread_debug attribute_hidden;
+/** For now disable debugging support. */
+#if 0
+# define DEBUGGING_P __builtin_expect (__pthread_debug, 0)
+# define INVALID_TD_P(pd) (DEBUGGING_P && __find_in_stack_list (pd) == NULL)
+# define INVALID_NOT_TERMINATED_TD_P(pd) INVALID_TD_P (pd)
+#else
+# define DEBUGGING_P 0
+/* Simplified test. This will not catch all invalid descriptors but
+ is better than nothing. And if the test triggers the thread
+ descriptor is guaranteed to be invalid. */
+# define INVALID_TD_P(pd) __builtin_expect ((pd)->tid <= 0, 0)
+# define INVALID_NOT_TERMINATED_TD_P(pd) __builtin_expect ((pd)->tid < 0, 0)
+#endif
+
+
+/* Cancellation test. */
+#define CANCELLATION_P(self) \
+ do { \
+ int cancelhandling = THREAD_GETMEM (self, cancelhandling); \
+ if (CANCEL_ENABLED_AND_CANCELED (cancelhandling)) \
+ { \
+ THREAD_SETMEM (self, result, PTHREAD_CANCELED); \
+ __do_cancel (); \
+ } \
+ } while (0)
+
+
+extern void __pthread_unwind (__pthread_unwind_buf_t *__buf)
+ __cleanup_fct_attribute __attribute ((__noreturn__))
+#if !defined SHARED && !defined IS_IN_libpthread
+ weak_function
+#endif
+ ;
+extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf)
+ __cleanup_fct_attribute __attribute ((__noreturn__))
+#ifndef SHARED
+ weak_function
+#endif
+ ;
+extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf)
+ __cleanup_fct_attribute;
+extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf)
+ __cleanup_fct_attribute;
+#if defined NOT_IN_libc && defined IS_IN_libpthread
+hidden_proto (__pthread_unwind)
+hidden_proto (__pthread_unwind_next)
+hidden_proto (__pthread_register_cancel)
+hidden_proto (__pthread_unregister_cancel)
+# ifdef SHARED
+extern void attribute_hidden pthread_cancel_init (void);
+# endif
+#endif
+
+
+/* Called when a thread reacts on a cancellation request. */
+static inline void
+__attribute ((noreturn, always_inline))
+__do_cancel (void)
+{
+ struct pthread *self = THREAD_SELF;
+
+ /* Make sure we get no more cancellations. */
+ THREAD_ATOMIC_BIT_SET (self, cancelhandling, EXITING_BIT);
+
+ __pthread_unwind ((__pthread_unwind_buf_t *)
+ THREAD_GETMEM (self, cleanup_jmp_buf));
+}
+
+
+/* Set cancellation mode to asynchronous. */
+#define CANCEL_ASYNC() \
+ __pthread_enable_asynccancel ()
+/* Reset to previous cancellation mode. */
+#define CANCEL_RESET(oldtype) \
+ __pthread_disable_asynccancel (oldtype)
+
+#if !defined NOT_IN_libc
+/* Same as CANCEL_ASYNC, but for use in libc.so. */
+# define LIBC_CANCEL_ASYNC() \
+ __libc_enable_asynccancel ()
+/* Same as CANCEL_RESET, but for use in libc.so. */
+# define LIBC_CANCEL_RESET(oldtype) \
+ __libc_disable_asynccancel (oldtype)
+# 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
+# define LIBC_CANCEL_ASYNC() CANCEL_ASYNC ()
+# define LIBC_CANCEL_RESET(val) CANCEL_RESET (val)
+# define LIBC_CANCEL_HANDLED() \
+ __asm (".globl " __SYMBOL_PREFIX "__pthread_enable_asynccancel"); \
+ __asm (".globl " __SYMBOL_PREFIX "__pthread_disable_asynccancel")
+#elif defined NOT_IN_libc && defined IS_IN_librt
+# define LIBC_CANCEL_ASYNC() \
+ __librt_enable_asynccancel ()
+# define LIBC_CANCEL_RESET(val) \
+ __librt_disable_asynccancel (val)
+# 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. */
+# define LIBC_CANCEL_HANDLED() /* Nothing. */
+#endif
+
+/* The signal used for asynchronous cancelation. */
+#define SIGCANCEL __SIGRTMIN
+
+
+/* Signal needed for the kernel-supported POSIX timer implementation.
+ We can reuse the cancellation signal since we can distinguish
+ cancellation from timer expirations. */
+#define SIGTIMER SIGCANCEL
+
+
+/* Signal used to implement the setuid et.al. functions. */
+#define SIGSETXID (__SIGRTMIN + 1)
+
+/* Used to communicate with signal handler. */
+extern struct xid_command *__xidcmd attribute_hidden;
+
+
+/* Internal prototypes. */
+
+/* Thread list handling. */
+extern struct pthread *__find_in_stack_list (struct pthread *pd)
+ attribute_hidden internal_function;
+
+/* Deallocate a thread's stack after optionally making sure the thread
+ descriptor is still valid. */
+extern void __free_tcb (struct pthread *pd) attribute_hidden internal_function;
+
+/* Free allocated stack. */
+extern void __deallocate_stack (struct pthread *pd)
+ attribute_hidden internal_function;
+
+/* Mark all the stacks except for the current one as available. This
+ function also re-initializes the lock for the stack cache. */
+extern void __reclaim_stacks (void) attribute_hidden;
+
+/* Make all threads's stacks executable. */
+extern int __make_stacks_executable (void **stack_endp)
+ internal_function attribute_hidden;
+
+/* longjmp handling. */
+extern void __pthread_cleanup_upto (__jmp_buf target, char *targetframe);
+#if defined NOT_IN_libc && defined IS_IN_libpthread
+hidden_proto (__pthread_cleanup_upto)
+#endif
+
+
+/* Functions with versioned interfaces. */
+extern int __pthread_create_2_1 (pthread_t *newthread,
+ const pthread_attr_t *attr,
+ void *(*start_routine) (void *), void *arg);
+extern int __pthread_create_2_0 (pthread_t *newthread,
+ const pthread_attr_t *attr,
+ void *(*start_routine) (void *), void *arg);
+extern int __pthread_attr_init_2_1 (pthread_attr_t *attr);
+extern int __pthread_attr_init_2_0 (pthread_attr_t *attr);
+
+
+/* Event handlers for libthread_db interface. */
+extern void __nptl_create_event (void);
+extern void __nptl_death_event (void);
+hidden_proto (__nptl_create_event)
+hidden_proto (__nptl_death_event)
+
+/* Register the generation counter in the libpthread with the libc. */
+#ifdef TLS_MULTIPLE_THREADS_IN_TCB
+extern void __libc_pthread_init (unsigned long int *ptr,
+ void (*reclaim) (void),
+ const struct pthread_functions *functions)
+ internal_function;
+#else
+extern int *__libc_pthread_init (unsigned long int *ptr,
+ void (*reclaim) (void),
+ const struct pthread_functions *functions)
+ internal_function;
+
+/* Variable set to a nonzero value if more than one thread runs or ran. */
+extern int __pthread_multiple_threads attribute_hidden;
+/* Pointer to the corresponding variable in libc. */
+extern int *__libc_multiple_threads_ptr attribute_hidden;
+#endif
+
+/* Find a thread given its TID. */
+extern struct pthread *__find_thread_by_id (pid_t tid) attribute_hidden
+#ifdef SHARED
+;
+#else
+weak_function;
+#define __find_thread_by_id(tid) \
+ (__find_thread_by_id ? (__find_thread_by_id) (tid) : (struct pthread *) NULL)
+#endif
+
+extern void __pthread_init_static_tls (struct link_map *) attribute_hidden;
+
+
+/* Namespace save aliases. */
+extern int __pthread_getschedparam (pthread_t thread_id, int *policy,
+ struct sched_param *param);
+extern int __pthread_setschedparam (pthread_t thread_id, int policy,
+ const struct sched_param *param);
+extern int __pthread_setcancelstate (int state, int *oldstate);
+extern int __pthread_mutex_init (pthread_mutex_t *__mutex,
+ __const pthread_mutexattr_t *__mutexattr);
+extern int __pthread_mutex_init_internal (pthread_mutex_t *__mutex,
+ __const pthread_mutexattr_t *__mutexattr)
+ attribute_hidden;
+extern int __pthread_mutex_destroy (pthread_mutex_t *__mutex);
+extern int __pthread_mutex_destroy_internal (pthread_mutex_t *__mutex)
+ attribute_hidden;
+extern int __pthread_mutex_trylock (pthread_mutex_t *_mutex);
+extern int __pthread_mutex_lock (pthread_mutex_t *__mutex);
+extern int __pthread_mutex_lock_internal (pthread_mutex_t *__mutex)
+ attribute_hidden;
+extern int __pthread_mutex_cond_lock (pthread_mutex_t *__mutex)
+ attribute_hidden internal_function;
+extern int __pthread_mutex_unlock (pthread_mutex_t *__mutex);
+extern int __pthread_mutex_unlock_internal (pthread_mutex_t *__mutex)
+ attribute_hidden;
+extern int __pthread_mutex_unlock_usercnt (pthread_mutex_t *__mutex,
+ int __decr)
+ attribute_hidden internal_function;
+extern int __pthread_mutexattr_init (pthread_mutexattr_t *attr);
+extern int __pthread_mutexattr_destroy (pthread_mutexattr_t *attr);
+extern int __pthread_mutexattr_settype (pthread_mutexattr_t *attr, int kind);
+extern int __pthread_attr_destroy (pthread_attr_t *attr);
+extern int __pthread_attr_getdetachstate (const pthread_attr_t *attr,
+ int *detachstate);
+extern int __pthread_attr_setdetachstate (pthread_attr_t *attr,
+ int detachstate);
+extern int __pthread_attr_getinheritsched (const pthread_attr_t *attr,
+ int *inherit);
+extern int __pthread_attr_setinheritsched (pthread_attr_t *attr, int inherit);
+extern int __pthread_attr_getschedparam (const pthread_attr_t *attr,
+ struct sched_param *param);
+extern int __pthread_attr_setschedparam (pthread_attr_t *attr,
+ const struct sched_param *param);
+extern int __pthread_attr_getschedpolicy (const pthread_attr_t *attr,
+ int *policy);
+extern int __pthread_attr_setschedpolicy (pthread_attr_t *attr, int policy);
+extern int __pthread_attr_getscope (const pthread_attr_t *attr, int *scope);
+extern int __pthread_attr_setscope (pthread_attr_t *attr, int scope);
+extern int __pthread_attr_getstackaddr (__const pthread_attr_t *__restrict
+ __attr, void **__restrict __stackaddr);
+extern int __pthread_attr_setstackaddr (pthread_attr_t *__attr,
+ void *__stackaddr);
+extern int __pthread_attr_getstacksize (__const pthread_attr_t *__restrict
+ __attr,
+ size_t *__restrict __stacksize);
+extern int __pthread_attr_setstacksize (pthread_attr_t *__attr,
+ size_t __stacksize);
+extern int __pthread_attr_getstack (__const pthread_attr_t *__restrict __attr,
+ void **__restrict __stackaddr,
+ size_t *__restrict __stacksize);
+extern int __pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr,
+ size_t __stacksize);
+extern int __pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock,
+ __const pthread_rwlockattr_t *__restrict
+ __attr);
+extern int __pthread_rwlock_destroy (pthread_rwlock_t *__rwlock);
+extern int __pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock);
+extern int __pthread_rwlock_rdlock_internal (pthread_rwlock_t *__rwlock);
+extern int __pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock);
+extern int __pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock);
+extern int __pthread_rwlock_wrlock_internal (pthread_rwlock_t *__rwlock);
+extern int __pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock);
+extern int __pthread_rwlock_unlock (pthread_rwlock_t *__rwlock);
+extern int __pthread_rwlock_unlock_internal (pthread_rwlock_t *__rwlock);
+extern int __pthread_cond_broadcast (pthread_cond_t *cond);
+extern int __pthread_cond_destroy (pthread_cond_t *cond);
+extern int __pthread_cond_init (pthread_cond_t *cond,
+ const pthread_condattr_t *cond_attr);
+extern int __pthread_cond_signal (pthread_cond_t *cond);
+extern int __pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex);
+extern int __pthread_cond_timedwait (pthread_cond_t *cond,
+ pthread_mutex_t *mutex,
+ const struct timespec *abstime);
+extern int __pthread_condattr_destroy (pthread_condattr_t *attr);
+extern int __pthread_condattr_init (pthread_condattr_t *attr);
+extern int __pthread_key_create (pthread_key_t *key, void (*destr) (void *));
+extern int __pthread_key_create_internal (pthread_key_t *key,
+ void (*destr) (void *));
+extern void *__pthread_getspecific (pthread_key_t key);
+extern void *__pthread_getspecific_internal (pthread_key_t key);
+extern int __pthread_setspecific (pthread_key_t key, const void *value);
+extern int __pthread_setspecific_internal (pthread_key_t key,
+ const void *value);
+extern int __pthread_once (pthread_once_t *once_control,
+ void (*init_routine) (void));
+extern int __pthread_once_internal (pthread_once_t *once_control,
+ void (*init_routine) (void));
+extern int __pthread_atfork (void (*prepare) (void), void (*parent) (void),
+ void (*child) (void));
+extern pthread_t __pthread_self (void);
+extern int __pthread_equal (pthread_t thread1, pthread_t thread2);
+extern int __pthread_kill (pthread_t threadid, int signo);
+extern void __pthread_exit (void *value);
+extern int __pthread_setcanceltype (int type, int *oldtype);
+extern int __pthread_enable_asynccancel (void) attribute_hidden;
+extern void __pthread_disable_asynccancel (int oldtype)
+ internal_function attribute_hidden;
+
+extern int __pthread_cond_broadcast_2_0 (pthread_cond_2_0_t *cond);
+extern int __pthread_cond_destroy_2_0 (pthread_cond_2_0_t *cond);
+extern int __pthread_cond_init_2_0 (pthread_cond_2_0_t *cond,
+ const pthread_condattr_t *cond_attr);
+extern int __pthread_cond_signal_2_0 (pthread_cond_2_0_t *cond);
+extern int __pthread_cond_timedwait_2_0 (pthread_cond_2_0_t *cond,
+ pthread_mutex_t *mutex,
+ const struct timespec *abstime);
+extern int __pthread_cond_wait_2_0 (pthread_cond_2_0_t *cond,
+ pthread_mutex_t *mutex);
+
+extern int __pthread_getaffinity_np (pthread_t th, size_t cpusetsize,
+ cpu_set_t *cpuset);
+
+/* The two functions are in libc.so and not exported. */
+extern int __libc_enable_asynccancel (void) attribute_hidden;
+extern void __libc_disable_asynccancel (int oldtype)
+ internal_function attribute_hidden;
+
+
+/* The two functions are in librt.so and not exported. */
+extern int __librt_enable_asynccancel (void) attribute_hidden;
+extern void __librt_disable_asynccancel (int oldtype)
+ internal_function attribute_hidden;
+
+#ifdef IS_IN_libpthread
+/* Special versions which use non-exported functions. */
+extern void __pthread_cleanup_push (struct _pthread_cleanup_buffer *buffer,
+ void (*routine) (void *), void *arg)
+ attribute_hidden;
+# undef pthread_cleanup_push
+# define pthread_cleanup_push(routine,arg) \
+ { struct _pthread_cleanup_buffer _buffer; \
+ __pthread_cleanup_push (&_buffer, (routine), (arg));
+
+extern void __pthread_cleanup_pop (struct _pthread_cleanup_buffer *buffer,
+ int execute) attribute_hidden;
+# undef pthread_cleanup_pop
+# define pthread_cleanup_pop(execute) \
+ __pthread_cleanup_pop (&_buffer, (execute)); }
+#endif
+
+extern void __pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer,
+ void (*routine) (void *), void *arg);
+extern void __pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer,
+ int execute);
+
+/* Old cleanup interfaces, still used in libc.so. */
+extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer *buffer,
+ void (*routine) (void *), void *arg);
+extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *buffer,
+ int execute);
+extern void _pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer,
+ void (*routine) (void *), void *arg);
+extern void _pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer,
+ int execute);
+
+extern void __nptl_deallocate_tsd (void) attribute_hidden;
+
+extern int __nptl_setxid (struct xid_command *cmdp) attribute_hidden;
+
+#ifdef SHARED
+# define PTHREAD_STATIC_FN_REQUIRE(name)
+#else
+# define PTHREAD_STATIC_FN_REQUIRE(name) __asm (".globl " #name);
+#endif
+
+
+#ifndef __NR_set_robust_list
+/* XXX For the time being... Once we can rely on the kernel headers
+ having the definition remove these lines. */
+# if defined __i386__
+# define __NR_set_robust_list 311
+# elif defined __x86_64__
+# define __NR_set_robust_list 273
+# endif
+#endif
+
+#endif /* pthreadP.h */
diff --git a/libc/nptl/pthread_atfork.c b/libc/nptl/pthread_atfork.c
new file mode 100644
index 000000000..b2495c702
--- /dev/null
+++ b/libc/nptl/pthread_atfork.c
@@ -0,0 +1,64 @@
+/* Copyright (C) 2002, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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.
+
+ In addition to the permissions in the GNU Lesser General Public
+ License, the Free Software Foundation gives you unlimited
+ permission to link the compiled version of this file with other
+ programs, and to distribute those programs without any restriction
+ coming from the use of this file. (The GNU Lesser General Public
+ License restrictions do apply in other respects; for example, they
+ cover modification of the file, and distribution when not linked
+ into another program.)
+
+ Note that people who make modified versions of this file are not
+ obligated to grant this special exception for their modified
+ versions; it is their choice whether to do so. The GNU Lesser
+ General Public License gives permission to release a modified
+ version without this exception; this exception also makes it
+ possible to release a modified version which carries forward this
+ exception.
+
+ 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 "pthreadP.h"
+#include <fork.h>
+
+/* This is defined by newer gcc version unique for each module. */
+extern void *__dso_handle __attribute__ ((__weak__,
+ __visibility__ ("hidden")));
+
+
+/* Hide the symbol so that no definition but the one locally in the
+ executable or DSO is used. */
+int
+#ifndef __pthread_atfork
+/* Don't mark the compatibility function as hidden. */
+attribute_hidden
+#endif
+__pthread_atfork (prepare, parent, child)
+ void (*prepare) (void);
+ void (*parent) (void);
+ void (*child) (void);
+{
+ return __register_atfork (prepare, parent, child,
+ &__dso_handle == NULL ? NULL : __dso_handle);
+}
+#ifndef __pthread_atfork
+extern int pthread_atfork (void (*prepare) (void), void (*parent) (void),
+ void (*child) (void)) attribute_hidden;
+strong_alias (__pthread_atfork, pthread_atfork)
+#endif
diff --git a/libc/nptl/pthread_attr_destroy.c b/libc/nptl/pthread_attr_destroy.c
new file mode 100644
index 000000000..b8d9a20d3
--- /dev/null
+++ b/libc/nptl/pthread_attr_destroy.c
@@ -0,0 +1,46 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include "pthreadP.h"
+#include <shlib-compat.h>
+
+int
+__pthread_attr_destroy (attr)
+ pthread_attr_t *attr;
+{
+ struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1)
+ /* In old struct pthread_attr, neither next nor cpuset are
+ present. */
+ if (__builtin_expect ((iattr->flags & ATTR_FLAG_OLDATTR), 0) == 0)
+#endif
+ /* The affinity CPU set might be allocated dynamically. */
+ free (iattr->cpuset);
+
+ return 0;
+}
+strong_alias (__pthread_attr_destroy, pthread_attr_destroy)
diff --git a/libc/nptl/pthread_attr_getdetachstate.c b/libc/nptl/pthread_attr_getdetachstate.c
new file mode 100644
index 000000000..502cfa4f1
--- /dev/null
+++ b/libc/nptl/pthread_attr_getdetachstate.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include "pthreadP.h"
+
+
+int
+__pthread_attr_getdetachstate (attr, detachstate)
+ const pthread_attr_t *attr;
+ int *detachstate;
+{
+ struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ *detachstate = (iattr->flags & ATTR_FLAG_DETACHSTATE
+ ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE);
+
+ return 0;
+}
+strong_alias (__pthread_attr_getdetachstate, pthread_attr_getdetachstate)
diff --git a/libc/nptl/pthread_attr_getguardsize.c b/libc/nptl/pthread_attr_getguardsize.c
new file mode 100644
index 000000000..e1d0ed624
--- /dev/null
+++ b/libc/nptl/pthread_attr_getguardsize.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include "pthreadP.h"
+
+
+int
+pthread_attr_getguardsize (attr, guardsize)
+ const pthread_attr_t *attr;
+ size_t *guardsize;
+{
+ struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ *guardsize = iattr->guardsize;
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_attr_getinheritsched.c b/libc/nptl/pthread_attr_getinheritsched.c
new file mode 100644
index 000000000..f47bf7147
--- /dev/null
+++ b/libc/nptl/pthread_attr_getinheritsched.c
@@ -0,0 +1,40 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include "pthreadP.h"
+
+
+int
+__pthread_attr_getinheritsched (attr, inherit)
+ const pthread_attr_t *attr;
+ int *inherit;
+{
+ struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ /* Store the current values. */
+ *inherit = (iattr->flags & ATTR_FLAG_NOTINHERITSCHED
+ ? PTHREAD_EXPLICIT_SCHED : PTHREAD_INHERIT_SCHED);
+
+ return 0;
+}
+strong_alias (__pthread_attr_getinheritsched, pthread_attr_getinheritsched)
diff --git a/libc/nptl/pthread_attr_getschedparam.c b/libc/nptl/pthread_attr_getschedparam.c
new file mode 100644
index 000000000..0ff0c0c4f
--- /dev/null
+++ b/libc/nptl/pthread_attr_getschedparam.c
@@ -0,0 +1,40 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include <string.h>
+#include "pthreadP.h"
+
+
+int
+__pthread_attr_getschedparam (attr, param)
+ const pthread_attr_t *attr;
+ struct sched_param *param;
+{
+ struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ /* Copy the current values. */
+ memcpy (param, &iattr->schedparam, sizeof (struct sched_param));
+
+ return 0;
+}
+strong_alias (__pthread_attr_getschedparam, pthread_attr_getschedparam)
diff --git a/libc/nptl/pthread_attr_getschedpolicy.c b/libc/nptl/pthread_attr_getschedpolicy.c
new file mode 100644
index 000000000..8364f3be0
--- /dev/null
+++ b/libc/nptl/pthread_attr_getschedpolicy.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include "pthreadP.h"
+
+
+int
+__pthread_attr_getschedpolicy (attr, policy)
+ const pthread_attr_t *attr;
+ int *policy;
+{
+ struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ /* Store the current values. */
+ *policy = iattr->schedpolicy;
+
+ return 0;
+}
+strong_alias (__pthread_attr_getschedpolicy, pthread_attr_getschedpolicy)
diff --git a/libc/nptl/pthread_attr_getscope.c b/libc/nptl/pthread_attr_getscope.c
new file mode 100644
index 000000000..b6aa5a213
--- /dev/null
+++ b/libc/nptl/pthread_attr_getscope.c
@@ -0,0 +1,40 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include "pthreadP.h"
+
+
+int
+__pthread_attr_getscope (attr, scope)
+ const pthread_attr_t *attr;
+ int *scope;
+{
+ struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ /* Store the current values. */
+ *scope = (iattr->flags & ATTR_FLAG_SCOPEPROCESS
+ ? PTHREAD_SCOPE_PROCESS : PTHREAD_SCOPE_SYSTEM);
+
+ return 0;
+}
+strong_alias (__pthread_attr_getscope, pthread_attr_getscope)
diff --git a/libc/nptl/pthread_attr_getstack.c b/libc/nptl/pthread_attr_getstack.c
new file mode 100644
index 000000000..1db135e5c
--- /dev/null
+++ b/libc/nptl/pthread_attr_getstack.c
@@ -0,0 +1,41 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include "pthreadP.h"
+
+
+int
+__pthread_attr_getstack (attr, stackaddr, stacksize)
+ const pthread_attr_t *attr;
+ void **stackaddr;
+ size_t *stacksize;
+{
+ struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ /* Store the result. */
+ *stackaddr = (char *) iattr->stackaddr - iattr->stacksize;
+ *stacksize = iattr->stacksize;
+
+ return 0;
+}
+strong_alias (__pthread_attr_getstack, pthread_attr_getstack)
diff --git a/libc/nptl/pthread_attr_getstackaddr.c b/libc/nptl/pthread_attr_getstackaddr.c
new file mode 100644
index 000000000..7656600dd
--- /dev/null
+++ b/libc/nptl/pthread_attr_getstackaddr.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include <errno.h>
+#include "pthreadP.h"
+
+
+int
+__pthread_attr_getstackaddr (attr, stackaddr)
+ const pthread_attr_t *attr;
+ void **stackaddr;
+{
+ struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ /* Some code assumes this function to work even if no stack address
+ has been set. Let them figure it out for themselves what the
+ value means. Simply store the result. */
+ *stackaddr = iattr->stackaddr;
+
+ return 0;
+}
+strong_alias (__pthread_attr_getstackaddr, pthread_attr_getstackaddr)
+
+link_warning (pthread_attr_getstackaddr,
+ "the use of `pthread_attr_getstackaddr' is deprecated, use `pthread_attr_getstack'")
diff --git a/libc/nptl/pthread_attr_getstacksize.c b/libc/nptl/pthread_attr_getstacksize.c
new file mode 100644
index 000000000..d4ff54f38
--- /dev/null
+++ b/libc/nptl/pthread_attr_getstacksize.c
@@ -0,0 +1,40 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include "pthreadP.h"
+
+
+int
+__pthread_attr_getstacksize (attr, stacksize)
+ const pthread_attr_t *attr;
+ size_t *stacksize;
+{
+ struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ /* If the user has not set a stack size we return what the system
+ will use as the default. */
+ *stacksize = iattr->stacksize ?: __default_stacksize;
+
+ return 0;
+}
+strong_alias (__pthread_attr_getstacksize, pthread_attr_getstacksize)
diff --git a/libc/nptl/pthread_attr_init.c b/libc/nptl/pthread_attr_init.c
new file mode 100644
index 000000000..c84b33f31
--- /dev/null
+++ b/libc/nptl/pthread_attr_init.c
@@ -0,0 +1,88 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include "pthreadP.h"
+
+#include <shlib-compat.h>
+
+
+struct pthread_attr *__attr_list;
+lll_lock_t __attr_list_lock = LLL_LOCK_INITIALIZER;
+
+
+int
+__pthread_attr_init_2_1 (attr)
+ pthread_attr_t *attr;
+{
+ struct pthread_attr *iattr;
+
+ /* Many elements are initialized to zero so let us do it all at
+ once. This also takes care of clearing the bytes which are not
+ internally used. */
+ memset (attr, '\0', __SIZEOF_PTHREAD_ATTR_T);
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ /* Default guard size specified by the standard. */
+ iattr->guardsize = __getpagesize ();
+
+ return 0;
+}
+versioned_symbol (libpthread, __pthread_attr_init_2_1, pthread_attr_init,
+ GLIBC_2_1);
+
+
+#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1)
+int
+__pthread_attr_init_2_0 (attr)
+ pthread_attr_t *attr;
+{
+ /* This code is specific to the old LinuxThread code which has a too
+ small pthread_attr_t definition. The struct looked like
+ this: */
+ struct old_attr
+ {
+ int detachstate;
+ int schedpolicy;
+ struct sched_param schedparam;
+ int inheritsched;
+ int scope;
+ };
+ struct pthread_attr *iattr;
+
+ /* Many elements are initialized to zero so let us do it all at
+ once. This also takes care of clearing the bytes which are not
+ internally used. */
+ memset (attr, '\0', sizeof (struct old_attr));
+
+ iattr = (struct pthread_attr *) attr;
+ iattr->flags |= ATTR_FLAG_OLDATTR;
+
+ /* We cannot enqueue the attribute because that member is not in the
+ old attribute structure. */
+ return 0;
+}
+compat_symbol (libpthread, __pthread_attr_init_2_0, pthread_attr_init,
+ GLIBC_2_0);
+#endif
diff --git a/libc/nptl/pthread_attr_setdetachstate.c b/libc/nptl/pthread_attr_setdetachstate.c
new file mode 100644
index 000000000..a0e6c2017
--- /dev/null
+++ b/libc/nptl/pthread_attr_setdetachstate.c
@@ -0,0 +1,48 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include <errno.h>
+#include "pthreadP.h"
+
+
+int
+__pthread_attr_setdetachstate (attr, detachstate)
+ pthread_attr_t *attr;
+ int detachstate;
+{
+ struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ /* Catch invalid values. */
+ if (detachstate != PTHREAD_CREATE_DETACHED
+ && __builtin_expect (detachstate != PTHREAD_CREATE_JOINABLE, 0))
+ return EINVAL;
+
+ /* Set the flag. It is nonzero if threads are created detached. */
+ if (detachstate == PTHREAD_CREATE_DETACHED)
+ iattr->flags |= ATTR_FLAG_DETACHSTATE;
+ else
+ iattr->flags &= ~ATTR_FLAG_DETACHSTATE;
+
+ return 0;
+}
+strong_alias (__pthread_attr_setdetachstate, pthread_attr_setdetachstate)
diff --git a/libc/nptl/pthread_attr_setguardsize.c b/libc/nptl/pthread_attr_setguardsize.c
new file mode 100644
index 000000000..4c674f4df
--- /dev/null
+++ b/libc/nptl/pthread_attr_setguardsize.c
@@ -0,0 +1,40 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include "pthreadP.h"
+
+
+int
+pthread_attr_setguardsize (attr, guardsize)
+ pthread_attr_t *attr;
+ size_t guardsize;
+{
+ struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ /* Note that we don't round the value here. The standard requires
+ that subsequent pthread_attr_getguardsize calls return the value
+ set by the user. */
+ iattr->guardsize = guardsize;
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_attr_setinheritsched.c b/libc/nptl/pthread_attr_setinheritsched.c
new file mode 100644
index 000000000..8a77eeb65
--- /dev/null
+++ b/libc/nptl/pthread_attr_setinheritsched.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include <errno.h>
+#include "pthreadP.h"
+
+
+int
+__pthread_attr_setinheritsched (attr, inherit)
+ pthread_attr_t *attr;
+ int inherit;
+{
+ struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ /* Catch invalid values. */
+ if (inherit != PTHREAD_INHERIT_SCHED && inherit != PTHREAD_EXPLICIT_SCHED)
+ return EINVAL;
+
+ /* Store the new values. */
+ if (inherit != PTHREAD_INHERIT_SCHED)
+ iattr->flags |= ATTR_FLAG_NOTINHERITSCHED;
+ else
+ iattr->flags &= ~ATTR_FLAG_NOTINHERITSCHED;
+
+ return 0;
+}
+strong_alias (__pthread_attr_setinheritsched, pthread_attr_setinheritsched)
diff --git a/libc/nptl/pthread_attr_setschedparam.c b/libc/nptl/pthread_attr_setschedparam.c
new file mode 100644
index 000000000..976ad1387
--- /dev/null
+++ b/libc/nptl/pthread_attr_setschedparam.c
@@ -0,0 +1,42 @@
+/* Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include <errno.h>
+#include <string.h>
+#include "pthreadP.h"
+
+
+int
+__pthread_attr_setschedparam (attr, param)
+ pthread_attr_t *attr;
+ const struct sched_param *param;
+{
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ struct pthread_attr *iattr = (struct pthread_attr *) attr;
+
+ /* Copy the new values. */
+ memcpy (&iattr->schedparam, param, sizeof (struct sched_param));
+
+ /* Remember we set the value. */
+ iattr->flags |= ATTR_FLAG_SCHED_SET;
+
+ return 0;
+}
+strong_alias (__pthread_attr_setschedparam, pthread_attr_setschedparam)
diff --git a/libc/nptl/pthread_attr_setschedpolicy.c b/libc/nptl/pthread_attr_setschedpolicy.c
new file mode 100644
index 000000000..b9710d57a
--- /dev/null
+++ b/libc/nptl/pthread_attr_setschedpolicy.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include <errno.h>
+#include "pthreadP.h"
+
+
+int
+__pthread_attr_setschedpolicy (attr, policy)
+ pthread_attr_t *attr;
+ int policy;
+{
+ struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ /* Catch invalid values. */
+ if (policy != SCHED_OTHER && policy != SCHED_FIFO && policy != SCHED_RR)
+ return EINVAL;
+
+ /* Store the new values. */
+ iattr->schedpolicy = policy;
+
+ /* Remember we set the value. */
+ iattr->flags |= ATTR_FLAG_POLICY_SET;
+
+ return 0;
+}
+strong_alias (__pthread_attr_setschedpolicy, pthread_attr_setschedpolicy)
diff --git a/libc/nptl/pthread_attr_setscope.c b/libc/nptl/pthread_attr_setscope.c
new file mode 100644
index 000000000..8b3e1612e
--- /dev/null
+++ b/libc/nptl/pthread_attr_setscope.c
@@ -0,0 +1,51 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include <errno.h>
+#include "pthreadP.h"
+
+
+int
+__pthread_attr_setscope (attr, scope)
+ pthread_attr_t *attr;
+ int scope;
+{
+ struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ /* Catch invalid values. */
+ switch (scope)
+ {
+ case PTHREAD_SCOPE_SYSTEM:
+ iattr->flags &= ~ATTR_FLAG_SCOPEPROCESS;
+ break;
+
+ case PTHREAD_SCOPE_PROCESS:
+ return ENOTSUP;
+
+ default:
+ return EINVAL;
+ }
+
+ return 0;
+}
+strong_alias (__pthread_attr_setscope, pthread_attr_setscope)
diff --git a/libc/nptl/pthread_attr_setstack.c b/libc/nptl/pthread_attr_setstack.c
new file mode 100644
index 000000000..622e4a225
--- /dev/null
+++ b/libc/nptl/pthread_attr_setstack.c
@@ -0,0 +1,89 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include <errno.h>
+#include <limits.h>
+#include "pthreadP.h"
+
+
+int
+__pthread_attr_setstack (attr, stackaddr, stacksize)
+ pthread_attr_t *attr;
+ void *stackaddr;
+ size_t stacksize;
+{
+ struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ /* Catch invalid sizes. */
+ if (stacksize < PTHREAD_STACK_MIN)
+ return EINVAL;
+
+#ifdef EXTRA_PARAM_CHECKS
+ EXTRA_PARAM_CHECKS;
+#endif
+
+ iattr->stacksize = stacksize;
+ iattr->stackaddr = (char *) stackaddr + stacksize;
+ iattr->flags |= ATTR_FLAG_STACKADDR;
+
+ return 0;
+}
+
+#if PTHREAD_STACK_MIN == 16384
+strong_alias (__pthread_attr_setstack, pthread_attr_setstack)
+#else
+# include <shlib-compat.h>
+versioned_symbol (libpthread, __pthread_attr_setstack, pthread_attr_setstack,
+ GLIBC_2_3_3);
+
+# if SHLIB_COMPAT(libpthread, GLIBC_2_2, GLIBC_2_3_3)
+
+int
+__old_pthread_attr_setstack (pthread_attr_t *attr, void *stackaddr,
+ size_t stacksize)
+{
+ struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ /* Catch invalid sizes. */
+ if (stacksize < 16384)
+ return EINVAL;
+
+# ifdef EXTRA_PARAM_CHECKS
+ EXTRA_PARAM_CHECKS;
+# endif
+
+ iattr->stacksize = stacksize;
+ iattr->stackaddr = (char *) stackaddr + stacksize;
+ iattr->flags |= ATTR_FLAG_STACKADDR;
+
+ return 0;
+}
+
+compat_symbol (libpthread, __old_pthread_attr_setstack, pthread_attr_setstack,
+ GLIBC_2_2);
+# endif
+
+#endif
diff --git a/libc/nptl/pthread_attr_setstackaddr.c b/libc/nptl/pthread_attr_setstackaddr.c
new file mode 100644
index 000000000..0d7a7c0eb
--- /dev/null
+++ b/libc/nptl/pthread_attr_setstackaddr.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include <errno.h>
+#include "pthreadP.h"
+
+
+int
+__pthread_attr_setstackaddr (attr, stackaddr)
+ pthread_attr_t *attr;
+ void *stackaddr;
+{
+ struct pthread_attr *iattr;
+
+#ifdef EXTRA_PARAM_CHECKS
+ EXTRA_PARAM_CHECKS;
+#endif
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ iattr->stackaddr = stackaddr;
+ iattr->flags |= ATTR_FLAG_STACKADDR;
+
+ return 0;
+}
+strong_alias (__pthread_attr_setstackaddr, pthread_attr_setstackaddr)
+
+link_warning (pthread_attr_setstackaddr,
+ "the use of `pthread_attr_setstackaddr' is deprecated, use `pthread_attr_setstack'")
diff --git a/libc/nptl/pthread_attr_setstacksize.c b/libc/nptl/pthread_attr_setstacksize.c
new file mode 100644
index 000000000..f84a9f68e
--- /dev/null
+++ b/libc/nptl/pthread_attr_setstacksize.c
@@ -0,0 +1,75 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include <errno.h>
+#include <limits.h>
+#include "pthreadP.h"
+
+
+int
+__pthread_attr_setstacksize (attr, stacksize)
+ pthread_attr_t *attr;
+ size_t stacksize;
+{
+ struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ /* Catch invalid sizes. */
+ if (stacksize < PTHREAD_STACK_MIN)
+ return EINVAL;
+
+ iattr->stacksize = stacksize;
+
+ return 0;
+}
+
+#if PTHREAD_STACK_MIN == 16384
+strong_alias (__pthread_attr_setstacksize, pthread_attr_setstacksize)
+#else
+# include <shlib-compat.h>
+versioned_symbol (libpthread, __pthread_attr_setstacksize,
+ pthread_attr_setstacksize, GLIBC_2_3_3);
+
+# if SHLIB_COMPAT(libpthread, GLIBC_2_1, GLIBC_2_3_3)
+
+int
+__old_pthread_attr_setstacksize (pthread_attr_t *attr, size_t stacksize)
+{
+ struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ /* Catch invalid sizes. */
+ if (stacksize < 16384)
+ return EINVAL;
+
+ iattr->stacksize = stacksize;
+
+ return 0;
+}
+
+compat_symbol (libpthread, __old_pthread_attr_setstacksize,
+ pthread_attr_setstacksize, GLIBC_2_1);
+# endif
+
+#endif
diff --git a/libc/nptl/pthread_barrier_destroy.c b/libc/nptl/pthread_barrier_destroy.c
new file mode 100644
index 000000000..492b29485
--- /dev/null
+++ b/libc/nptl/pthread_barrier_destroy.c
@@ -0,0 +1,44 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include "pthreadP.h"
+#include <lowlevellock.h>
+
+
+int
+pthread_barrier_destroy (barrier)
+ pthread_barrier_t *barrier;
+{
+ struct pthread_barrier *ibarrier;
+ int result = EBUSY;
+
+ ibarrier = (struct pthread_barrier *) barrier;
+
+ lll_lock (ibarrier->lock);
+
+ if (__builtin_expect (ibarrier->left == ibarrier->init_count, 1))
+ /* The barrier is not used anymore. */
+ result = 0;
+ else
+ /* Still used, return with an error. */
+ lll_unlock (ibarrier->lock);
+
+ return result;
+}
diff --git a/libc/nptl/pthread_barrier_init.c b/libc/nptl/pthread_barrier_init.c
new file mode 100644
index 000000000..19e82fa38
--- /dev/null
+++ b/libc/nptl/pthread_barrier_init.c
@@ -0,0 +1,57 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include "pthreadP.h"
+#include <lowlevellock.h>
+
+
+int
+pthread_barrier_init (barrier, attr, count)
+ pthread_barrier_t *barrier;
+ const pthread_barrierattr_t *attr;
+ unsigned int count;
+{
+ struct pthread_barrier *ibarrier;
+
+ if (__builtin_expect (count == 0, 0))
+ return EINVAL;
+
+ if (attr != NULL)
+ {
+ struct pthread_barrierattr *iattr;
+
+ iattr = (struct pthread_barrierattr *) attr;
+
+ if (iattr->pshared != PTHREAD_PROCESS_PRIVATE
+ && __builtin_expect (iattr->pshared != PTHREAD_PROCESS_SHARED, 0))
+ /* Invalid attribute. */
+ return EINVAL;
+ }
+
+ ibarrier = (struct pthread_barrier *) barrier;
+
+ /* Initialize the individual fields. */
+ ibarrier->lock = LLL_LOCK_INITIALIZER;
+ ibarrier->left = count;
+ ibarrier->init_count = count;
+ ibarrier->curr_event = 0;
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_barrierattr_destroy.c b/libc/nptl/pthread_barrierattr_destroy.c
new file mode 100644
index 000000000..f947daf38
--- /dev/null
+++ b/libc/nptl/pthread_barrierattr_destroy.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "pthreadP.h"
+
+
+int
+pthread_barrierattr_destroy (attr)
+ pthread_barrierattr_t *attr;
+{
+ /* Nothing to do. */
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_barrierattr_getpshared.c b/libc/nptl/pthread_barrierattr_getpshared.c
new file mode 100644
index 000000000..246c8882e
--- /dev/null
+++ b/libc/nptl/pthread_barrierattr_getpshared.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "pthreadP.h"
+
+
+int
+pthread_barrierattr_getpshared (attr, pshared)
+ const pthread_barrierattr_t *attr;
+ int *pshared;
+{
+ *pshared = ((const struct pthread_barrierattr *) attr)->pshared;
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_barrierattr_init.c b/libc/nptl/pthread_barrierattr_init.c
new file mode 100644
index 000000000..a0be9528b
--- /dev/null
+++ b/libc/nptl/pthread_barrierattr_init.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "pthreadP.h"
+
+
+int
+pthread_barrierattr_init (attr)
+ pthread_barrierattr_t *attr;
+{
+ ((struct pthread_barrierattr *) attr)->pshared = PTHREAD_PROCESS_PRIVATE;
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_barrierattr_setpshared.c b/libc/nptl/pthread_barrierattr_setpshared.c
new file mode 100644
index 000000000..b69f23ef1
--- /dev/null
+++ b/libc/nptl/pthread_barrierattr_setpshared.c
@@ -0,0 +1,40 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include "pthreadP.h"
+
+
+int
+pthread_barrierattr_setpshared (attr, pshared)
+ pthread_barrierattr_t *attr;
+ int pshared;
+{
+ struct pthread_barrierattr *iattr;
+
+ if (pshared != PTHREAD_PROCESS_PRIVATE
+ && __builtin_expect (pshared != PTHREAD_PROCESS_SHARED, 0))
+ return EINVAL;
+
+ iattr = (struct pthread_barrierattr *) attr;
+
+ iattr->pshared = pshared;
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_cancel.c b/libc/nptl/pthread_cancel.c
new file mode 100644
index 000000000..a13af56b3
--- /dev/null
+++ b/libc/nptl/pthread_cancel.c
@@ -0,0 +1,104 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <signal.h>
+#include "pthreadP.h"
+#include "atomic.h"
+#include <sysdep.h>
+#include <kernel-features.h>
+
+
+int
+pthread_cancel (th)
+ pthread_t th;
+{
+ volatile struct pthread *pd = (volatile struct pthread *) th;
+
+ /* Make sure the descriptor is valid. */
+ if (INVALID_TD_P (pd))
+ /* Not a valid thread handle. */
+ return ESRCH;
+
+#ifdef SHARED
+ pthread_cancel_init ();
+#endif
+ int result = 0;
+ int oldval;
+ int newval;
+ do
+ {
+ oldval = pd->cancelhandling;
+ newval = oldval | CANCELING_BITMASK | CANCELED_BITMASK;
+
+ /* Avoid doing unnecessary work. The atomic operation can
+ potentially be expensive if the bug has to be locked and
+ remote cache lines have to be invalidated. */
+ if (oldval == newval)
+ break;
+
+ /* If the cancellation is handled asynchronously just send a
+ signal. We avoid this if possible since it's more
+ expensive. */
+ if (CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS (newval))
+ {
+ /* Mark the cancellation as "in progress". */
+ atomic_bit_set (&pd->cancelhandling, CANCELING_BIT);
+
+ /* The cancellation handler will take care of marking the
+ thread as canceled. */
+ INTERNAL_SYSCALL_DECL (err);
+
+ /* One comment: The PID field in the TCB can temporarily be
+ changed (in fork). But this must not affect this code
+ here. Since this function would have to be called while
+ the thread is executing fork, it would have to happen in
+ a signal handler. But this is no allowed, pthread_cancel
+ is not guaranteed to be async-safe. */
+ int val;
+#if __ASSUME_TGKILL
+ val = INTERNAL_SYSCALL (tgkill, err, 3,
+ THREAD_GETMEM (THREAD_SELF, pid), pd->tid,
+ SIGCANCEL);
+#else
+# ifdef __NR_tgkill
+ val = INTERNAL_SYSCALL (tgkill, err, 3,
+ THREAD_GETMEM (THREAD_SELF, pid), pd->tid,
+ SIGCANCEL);
+ if (INTERNAL_SYSCALL_ERROR_P (val, err)
+ && INTERNAL_SYSCALL_ERRNO (val, err) == ENOSYS)
+# endif
+ val = INTERNAL_SYSCALL (tkill, err, 2, pd->tid, SIGCANCEL);
+#endif
+
+ if (INTERNAL_SYSCALL_ERROR_P (val, err))
+ result = INTERNAL_SYSCALL_ERRNO (val, err);
+
+ break;
+ }
+ }
+ /* Mark the thread as canceled. This has to be done
+ atomically since other bits could be modified as well. */
+ while (atomic_compare_and_exchange_bool_acq (&pd->cancelhandling, newval,
+ oldval));
+
+ return result;
+}
+
+PTHREAD_STATIC_FN_REQUIRE (pthread_create)
diff --git a/libc/nptl/pthread_clock_gettime.c b/libc/nptl/pthread_clock_gettime.c
new file mode 100644
index 000000000..a71174c9c
--- /dev/null
+++ b/libc/nptl/pthread_clock_gettime.c
@@ -0,0 +1,69 @@
+/* Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <time.h>
+#include <libc-internal.h>
+#include "pthreadP.h"
+
+
+#if HP_TIMING_AVAIL
+int
+__pthread_clock_gettime (clockid_t clock_id, hp_timing_t freq,
+ struct timespec *tp)
+{
+ hp_timing_t tsc;
+
+ /* Get the current counter. */
+ HP_TIMING_NOW (tsc);
+
+ /* This is the ID of the thread we are looking for. */
+ pid_t tid = ((unsigned int) clock_id) >> CLOCK_IDFIELD_SIZE;
+
+ /* Compute the offset since the start time of the process. */
+ if (tid == 0 || tid == THREAD_GETMEM (THREAD_SELF, tid))
+ /* Our own clock. */
+ tsc -= THREAD_GETMEM (THREAD_SELF, cpuclock_offset);
+ else
+ {
+ /* This is more complicated. We have to locate the thread based
+ on the ID. This means walking the list of existing
+ threads. */
+ struct pthread *thread = __find_thread_by_id (tid);
+ if (thread == NULL)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ /* There is a race here. The thread might terminate and the stack
+ become unusable. But this is the user's problem. */
+ tsc -= thread->cpuclock_offset;
+ }
+
+ /* Compute the seconds. */
+ tp->tv_sec = tsc / freq;
+
+ /* And the nanoseconds. This computation should be stable until
+ we get machines with about 16GHz frequency. */
+ tp->tv_nsec = ((tsc % freq) * 1000000000ull) / freq;
+
+ return 0;
+}
+#endif
diff --git a/libc/nptl/pthread_clock_settime.c b/libc/nptl/pthread_clock_settime.c
new file mode 100644
index 000000000..61002a8f7
--- /dev/null
+++ b/libc/nptl/pthread_clock_settime.c
@@ -0,0 +1,56 @@
+/* Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <time.h>
+#include <libc-internal.h>
+#include "pthreadP.h"
+
+
+#if HP_TIMING_AVAIL
+int
+__pthread_clock_settime (clockid_t clock_id, hp_timing_t offset)
+{
+ /* This is the ID of the thread we are looking for. */
+ pid_t tid = ((unsigned int) clock_id) >> CLOCK_IDFIELD_SIZE;
+
+ /* Compute the offset since the start time of the process. */
+ if (tid == 0 || tid == THREAD_GETMEM (THREAD_SELF, tid))
+ /* Our own clock. */
+ THREAD_SETMEM (THREAD_SELF, cpuclock_offset, offset);
+ else
+ {
+ /* This is more complicated. We have to locate the thread based
+ on the ID. This means walking the list of existing
+ threads. */
+ struct pthread *thread = __find_thread_by_id (tid);
+ if (thread == NULL)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ /* There is a race here. The thread might terminate and the stack
+ become unusable. But this is the user's problem. */
+ thread->cpuclock_offset = offset;
+ }
+
+ return 0;
+}
+#endif
diff --git a/libc/nptl/pthread_cond_destroy.c b/libc/nptl/pthread_cond_destroy.c
new file mode 100644
index 000000000..3e4ec8d0e
--- /dev/null
+++ b/libc/nptl/pthread_cond_destroy.c
@@ -0,0 +1,81 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <shlib-compat.h>
+#include "pthreadP.h"
+
+
+int
+__pthread_cond_destroy (cond)
+ pthread_cond_t *cond;
+{
+ /* Make sure we are alone. */
+ lll_mutex_lock (cond->__data.__lock);
+
+ if (cond->__data.__total_seq > cond->__data.__wakeup_seq)
+ {
+ /* If there are still some waiters which have not been
+ woken up, this is an application bug. */
+ lll_mutex_unlock (cond->__data.__lock);
+ return EBUSY;
+ }
+
+ /* Tell pthread_cond_*wait that this condvar is being destroyed. */
+ cond->__data.__total_seq = -1ULL;
+
+ /* If there are waiters which have been already signalled or
+ broadcasted, but still are using the pthread_cond_t structure,
+ pthread_cond_destroy needs to wait for them. */
+ unsigned int nwaiters = cond->__data.__nwaiters;
+
+ if (nwaiters >= (1 << COND_CLOCK_BITS))
+ {
+ /* Wake everybody on the associated mutex in case there are
+ threads that have been requeued to it.
+ Without this, pthread_cond_destroy could block potentially
+ for a long time or forever, as it would depend on other
+ thread's using the mutex.
+ When all threads waiting on the mutex are woken up, pthread_cond_wait
+ only waits for threads to acquire and release the internal
+ condvar lock. */
+ if (cond->__data.__mutex != NULL
+ && cond->__data.__mutex != (void *) ~0l)
+ {
+ pthread_mutex_t *mut = (pthread_mutex_t *) cond->__data.__mutex;
+ lll_futex_wake (&mut->__data.__lock, INT_MAX);
+ }
+
+ do
+ {
+ lll_mutex_unlock (cond->__data.__lock);
+
+ lll_futex_wait (&cond->__data.__nwaiters, nwaiters);
+
+ lll_mutex_lock (cond->__data.__lock);
+
+ nwaiters = cond->__data.__nwaiters;
+ }
+ while (nwaiters >= (1 << COND_CLOCK_BITS));
+ }
+
+ return 0;
+}
+versioned_symbol (libpthread, __pthread_cond_destroy,
+ pthread_cond_destroy, GLIBC_2_3_2);
diff --git a/libc/nptl/pthread_cond_init.c b/libc/nptl/pthread_cond_init.c
new file mode 100644
index 000000000..5e2e6704a
--- /dev/null
+++ b/libc/nptl/pthread_cond_init.c
@@ -0,0 +1,46 @@
+/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <shlib-compat.h>
+#include "pthreadP.h"
+
+
+int
+__pthread_cond_init (cond, cond_attr)
+ pthread_cond_t *cond;
+ const pthread_condattr_t *cond_attr;
+{
+ struct pthread_condattr *icond_attr = (struct pthread_condattr *) cond_attr;
+
+ cond->__data.__lock = LLL_MUTEX_LOCK_INITIALIZER;
+ cond->__data.__futex = 0;
+ cond->__data.__nwaiters = (icond_attr != NULL
+ && ((icond_attr->value & (COND_CLOCK_BITS << 1))
+ >> 1));
+ cond->__data.__total_seq = 0;
+ cond->__data.__wakeup_seq = 0;
+ cond->__data.__woken_seq = 0;
+ cond->__data.__mutex = (icond_attr == NULL || (icond_attr->value & 1) == 0
+ ? NULL : (void *) ~0l);
+ cond->__data.__broadcast_seq = 0;
+
+ return 0;
+}
+versioned_symbol (libpthread, __pthread_cond_init,
+ pthread_cond_init, GLIBC_2_3_2);
diff --git a/libc/nptl/pthread_condattr_destroy.c b/libc/nptl/pthread_condattr_destroy.c
new file mode 100644
index 000000000..e6d069e40
--- /dev/null
+++ b/libc/nptl/pthread_condattr_destroy.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "pthreadP.h"
+
+
+int
+__pthread_condattr_destroy (attr)
+ pthread_condattr_t *attr;
+{
+ /* Nothing to be done. */
+ return 0;
+}
+strong_alias (__pthread_condattr_destroy, pthread_condattr_destroy)
diff --git a/libc/nptl/pthread_condattr_getclock.c b/libc/nptl/pthread_condattr_getclock.c
new file mode 100644
index 000000000..84de918a5
--- /dev/null
+++ b/libc/nptl/pthread_condattr_getclock.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2003, 2004 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 "pthreadP.h"
+
+
+int
+pthread_condattr_getclock (attr, clock_id)
+ const pthread_condattr_t *attr;
+ clockid_t *clock_id;
+{
+ *clock_id = (((((const struct pthread_condattr *) attr)->value) >> 1)
+ & ((1 << COND_CLOCK_BITS) - 1));
+ return 0;
+}
diff --git a/libc/nptl/pthread_condattr_getpshared.c b/libc/nptl/pthread_condattr_getpshared.c
new file mode 100644
index 000000000..b44eac94e
--- /dev/null
+++ b/libc/nptl/pthread_condattr_getpshared.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "pthreadP.h"
+
+
+int
+pthread_condattr_getpshared (attr, pshared)
+ const pthread_condattr_t *attr;
+ int *pshared;
+{
+ *pshared = ((const struct pthread_condattr *) attr)->value & 1;
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_condattr_init.c b/libc/nptl/pthread_condattr_init.c
new file mode 100644
index 000000000..738deb489
--- /dev/null
+++ b/libc/nptl/pthread_condattr_init.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <string.h>
+#include "pthreadP.h"
+
+
+int
+__pthread_condattr_init (attr)
+ pthread_condattr_t *attr;
+{
+ memset (attr, '\0', sizeof (*attr));
+
+ return 0;
+}
+strong_alias (__pthread_condattr_init, pthread_condattr_init)
diff --git a/libc/nptl/pthread_condattr_setclock.c b/libc/nptl/pthread_condattr_setclock.c
new file mode 100644
index 000000000..04e246b74
--- /dev/null
+++ b/libc/nptl/pthread_condattr_setclock.c
@@ -0,0 +1,72 @@
+/* Copyright (C) 2003, 2004 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 <assert.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <time.h>
+#include <sysdep.h>
+#include "pthreadP.h"
+#include <kernel-features.h>
+
+
+int
+pthread_condattr_setclock (attr, clock_id)
+ pthread_condattr_t *attr;
+ clockid_t clock_id;
+{
+ /* Only a few clocks are allowed. CLOCK_REALTIME is always allowed.
+ CLOCK_MONOTONIC only if the kernel has the necessary support. */
+ if (clock_id == CLOCK_MONOTONIC)
+ {
+#ifndef __ASSUME_POSIX_TIMERS
+# ifdef __NR_clock_getres
+ /* Check whether the clock is available. */
+ static int avail;
+
+ if (avail == 0)
+ {
+ struct timespec ts;
+
+ INTERNAL_SYSCALL_DECL (err);
+ int val;
+ val = INTERNAL_SYSCALL (clock_getres, err, 2, CLOCK_MONOTONIC, &ts);
+ avail = INTERNAL_SYSCALL_ERROR_P (val, err) ? -1 : 1;
+ }
+
+ if (avail < 0)
+# endif
+ /* Not available. */
+ return EINVAL;
+#endif
+ }
+ else if (clock_id != CLOCK_REALTIME)
+ /* If more clocks are allowed some day the storing of the clock ID
+ in the pthread_cond_t structure needs to be adjusted. */
+ return EINVAL;
+
+ /* Make sure the value fits in the bits we reserved. */
+ assert (clock_id < (1 << COND_CLOCK_BITS));
+
+ int *valuep = &((struct pthread_condattr *) attr)->value;
+
+ *valuep = (*valuep & ~(1 << (COND_CLOCK_BITS + 1)) & ~1) | (clock_id << 1);
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_condattr_setpshared.c b/libc/nptl/pthread_condattr_setpshared.c
new file mode 100644
index 000000000..f00858780
--- /dev/null
+++ b/libc/nptl/pthread_condattr_setpshared.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthreadP.h>
+
+int
+pthread_condattr_setpshared (attr, pshared)
+ pthread_condattr_t *attr;
+ int pshared;
+{
+ if (pshared != PTHREAD_PROCESS_PRIVATE
+ && __builtin_expect (pshared != PTHREAD_PROCESS_SHARED, 0))
+ return EINVAL;
+
+ int *valuep = &((struct pthread_condattr *) attr)->value;
+
+ *valuep = (*valuep & ~1) | (pshared != PTHREAD_PROCESS_PRIVATE);
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_create.c b/libc/nptl/pthread_create.c
new file mode 100644
index 000000000..315722643
--- /dev/null
+++ b/libc/nptl/pthread_create.c
@@ -0,0 +1,594 @@
+/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+#include "pthreadP.h"
+#include <hp-timing.h>
+#include <ldsodefs.h>
+#include <atomic.h>
+#include <libc-internal.h>
+#include <resolv.h>
+
+#include <shlib-compat.h>
+
+
+/* Local function to start thread and handle cleanup. */
+static int start_thread (void *arg);
+
+
+/* Nozero if debugging mode is enabled. */
+int __pthread_debug;
+
+/* Globally enabled events. */
+static td_thr_events_t __nptl_threads_events;
+
+/* Pointer to descriptor with the last event. */
+static struct pthread *__nptl_last_event;
+
+/* Number of threads running. */
+unsigned int __nptl_nthreads = 1;
+
+
+/* Code to allocate and deallocate a stack. */
+#include "allocatestack.c"
+
+/* Code to create the thread. */
+#include <createthread.c>
+
+
+struct pthread *
+internal_function
+__find_in_stack_list (pd)
+ struct pthread *pd;
+{
+ list_t *entry;
+ struct pthread *result = NULL;
+
+ lll_lock (stack_cache_lock);
+
+ list_for_each (entry, &stack_used)
+ {
+ struct pthread *curp;
+
+ curp = list_entry (entry, struct pthread, list);
+ if (curp == pd)
+ {
+ result = curp;
+ break;
+ }
+ }
+
+ if (result == NULL)
+ list_for_each (entry, &__stack_user)
+ {
+ struct pthread *curp;
+
+ curp = list_entry (entry, struct pthread, list);
+ if (curp == pd)
+ {
+ result = curp;
+ break;
+ }
+ }
+
+ lll_unlock (stack_cache_lock);
+
+ return result;
+}
+
+
+/* Deallocate POSIX thread-local-storage. */
+void
+attribute_hidden
+__nptl_deallocate_tsd (void)
+{
+ struct pthread *self = THREAD_SELF;
+
+ /* Maybe no data was ever allocated. This happens often so we have
+ a flag for this. */
+ if (THREAD_GETMEM (self, specific_used))
+ {
+ size_t round;
+ size_t cnt;
+
+ round = 0;
+ do
+ {
+ size_t idx;
+
+ /* So far no new nonzero data entry. */
+ THREAD_SETMEM (self, specific_used, false);
+
+ for (cnt = idx = 0; cnt < PTHREAD_KEY_1STLEVEL_SIZE; ++cnt)
+ {
+ struct pthread_key_data *level2;
+
+ level2 = THREAD_GETMEM_NC (self, specific, cnt);
+
+ if (level2 != NULL)
+ {
+ size_t inner;
+
+ for (inner = 0; inner < PTHREAD_KEY_2NDLEVEL_SIZE;
+ ++inner, ++idx)
+ {
+ void *data = level2[inner].data;
+
+ if (data != NULL)
+ {
+ /* Always clear the data. */
+ level2[inner].data = NULL;
+
+ /* Make sure the data corresponds to a valid
+ key. This test fails if the key was
+ deallocated and also if it was
+ re-allocated. It is the user's
+ responsibility to free the memory in this
+ case. */
+ if (level2[inner].seq
+ == __pthread_keys[idx].seq
+ /* It is not necessary to register a destructor
+ function. */
+ && __pthread_keys[idx].destr != NULL)
+ /* Call the user-provided destructor. */
+ __pthread_keys[idx].destr (data);
+ }
+ }
+ }
+ else
+ idx += PTHREAD_KEY_1STLEVEL_SIZE;
+ }
+
+ if (THREAD_GETMEM (self, specific_used) == 0)
+ /* No data has been modified. */
+ goto just_free;
+ }
+ /* We only repeat the process a fixed number of times. */
+ while (__builtin_expect (++round < PTHREAD_DESTRUCTOR_ITERATIONS, 0));
+
+ /* Just clear the memory of the first block for reuse. */
+ memset (&THREAD_SELF->specific_1stblock, '\0',
+ sizeof (self->specific_1stblock));
+
+ just_free:
+ /* Free the memory for the other blocks. */
+ for (cnt = 1; cnt < PTHREAD_KEY_1STLEVEL_SIZE; ++cnt)
+ {
+ struct pthread_key_data *level2;
+
+ level2 = THREAD_GETMEM_NC (self, specific, cnt);
+ if (level2 != NULL)
+ {
+ /* The first block is allocated as part of the thread
+ descriptor. */
+ free (level2);
+ THREAD_SETMEM_NC (self, specific, cnt, NULL);
+ }
+ }
+
+ THREAD_SETMEM (self, specific_used, false);
+ }
+}
+
+
+/* Deallocate a thread's stack after optionally making sure the thread
+ descriptor is still valid. */
+void
+internal_function
+__free_tcb (struct pthread *pd)
+{
+ /* The thread is exiting now. */
+ if (__builtin_expect (atomic_bit_test_set (&pd->cancelhandling,
+ TERMINATED_BIT) == 0, 1))
+ {
+ /* Remove the descriptor from the list. */
+ if (DEBUGGING_P && __find_in_stack_list (pd) == NULL)
+ /* Something is really wrong. The descriptor for a still
+ running thread is gone. */
+ abort ();
+
+ /* Free TPP data. */
+ if (__builtin_expect (pd->tpp != NULL, 0))
+ {
+ struct priority_protection_data *tpp = pd->tpp;
+
+ pd->tpp = NULL;
+ free (tpp);
+ }
+
+ /* Queue the stack memory block for reuse and exit the process. The
+ kernel will signal via writing to the address returned by
+ QUEUE-STACK when the stack is available. */
+ __deallocate_stack (pd);
+ }
+}
+
+
+static int
+start_thread (void *arg)
+{
+ struct pthread *pd = (struct pthread *) arg;
+
+#if HP_TIMING_AVAIL
+ /* Remember the time when the thread was started. */
+ hp_timing_t now;
+ HP_TIMING_NOW (now);
+ THREAD_SETMEM (pd, cpuclock_offset, now);
+#endif
+
+ /* Initialize resolver state pointer. */
+ __resp = &pd->res;
+
+#ifdef __NR_set_robust_list
+# ifndef __ASSUME_SET_ROBUST_LIST
+ if (__set_robust_list_avail >= 0)
+# endif
+ {
+ INTERNAL_SYSCALL_DECL (err);
+ /* This call should never fail because the initial call in init.c
+ succeeded. */
+ INTERNAL_SYSCALL (set_robust_list, err, 2, &pd->robust_head,
+ sizeof (struct robust_list_head));
+ }
+#endif
+
+ /* This is where the try/finally block should be created. For
+ compilers without that support we do use setjmp. */
+ struct pthread_unwind_buf unwind_buf;
+
+ /* No previous handlers. */
+ unwind_buf.priv.data.prev = NULL;
+ unwind_buf.priv.data.cleanup = NULL;
+
+ int not_first_call;
+ not_first_call = setjmp ((struct __jmp_buf_tag *) unwind_buf.cancel_jmp_buf);
+ if (__builtin_expect (! not_first_call, 1))
+ {
+ /* Store the new cleanup handler info. */
+ THREAD_SETMEM (pd, cleanup_jmp_buf, &unwind_buf);
+
+ if (__builtin_expect (pd->stopped_start, 0))
+ {
+ int oldtype = CANCEL_ASYNC ();
+
+ /* Get the lock the parent locked to force synchronization. */
+ lll_lock (pd->lock);
+ /* And give it up right away. */
+ lll_unlock (pd->lock);
+
+ CANCEL_RESET (oldtype);
+ }
+
+ /* Run the code the user provided. */
+#ifdef CALL_THREAD_FCT
+ THREAD_SETMEM (pd, result, CALL_THREAD_FCT (pd));
+#else
+ THREAD_SETMEM (pd, result, pd->start_routine (pd->arg));
+#endif
+ }
+
+ /* Run the destructor for the thread-local data. */
+ __nptl_deallocate_tsd ();
+
+ /* Clean up any state libc stored in thread-local variables. */
+ __libc_thread_freeres ();
+
+ /* If this is the last thread we terminate the process now. We
+ do not notify the debugger, it might just irritate it if there
+ is no thread left. */
+ if (__builtin_expect (atomic_decrement_and_test (&__nptl_nthreads), 0))
+ /* This was the last thread. */
+ exit (0);
+
+ /* Report the death of the thread if this is wanted. */
+ if (__builtin_expect (pd->report_events, 0))
+ {
+ /* See whether TD_DEATH is in any of the mask. */
+ const int idx = __td_eventword (TD_DEATH);
+ const uint32_t mask = __td_eventmask (TD_DEATH);
+
+ if ((mask & (__nptl_threads_events.event_bits[idx]
+ | pd->eventbuf.eventmask.event_bits[idx])) != 0)
+ {
+ /* Yep, we have to signal the death. Add the descriptor to
+ the list but only if it is not already on it. */
+ if (pd->nextevent == NULL)
+ {
+ pd->eventbuf.eventnum = TD_DEATH;
+ pd->eventbuf.eventdata = pd;
+
+ do
+ pd->nextevent = __nptl_last_event;
+ while (atomic_compare_and_exchange_bool_acq (&__nptl_last_event,
+ pd, pd->nextevent));
+ }
+
+ /* Now call the function to signal the event. */
+ __nptl_death_event ();
+ }
+ }
+
+ /* The thread is exiting now. Don't set this bit until after we've hit
+ the event-reporting breakpoint, so that td_thr_get_info on us while at
+ the breakpoint reports TD_THR_RUN state rather than TD_THR_ZOMBIE. */
+ atomic_bit_set (&pd->cancelhandling, EXITING_BIT);
+
+#ifndef __ASSUME_SET_ROBUST_LIST
+ /* If this thread has any robust mutexes locked, handle them now. */
+# if __WORDSIZE == 64
+ void *robust = pd->robust_head.list;
+# else
+ __pthread_slist_t *robust = pd->robust_list.__next;
+# endif
+ /* We let the kernel do the notification if it is able to do so.
+ If we have to do it here there for sure are no PI mutexes involved
+ since the kernel support for them is even more recent. */
+ if (__set_robust_list_avail < 0
+ && __builtin_expect (robust != (void *) &pd->robust_head, 0))
+ {
+ do
+ {
+ struct __pthread_mutex_s *this = (struct __pthread_mutex_s *)
+ ((char *) robust - offsetof (struct __pthread_mutex_s,
+ __list.__next));
+ robust = *((void **) robust);
+
+# ifdef __PTHREAD_MUTEX_HAVE_PREV
+ this->__list.__prev = NULL;
+# endif
+ this->__list.__next = NULL;
+
+ lll_robust_mutex_dead (this->__lock);
+ }
+ while (robust != (void *) &pd->robust_head);
+ }
+#endif
+
+ /* If the thread is detached free the TCB. */
+ if (IS_DETACHED (pd))
+ /* Free the TCB. */
+ __free_tcb (pd);
+ else if (__builtin_expect (pd->cancelhandling & SETXID_BITMASK, 0))
+ {
+ /* Some other thread might call any of the setXid functions and expect
+ us to reply. In this case wait until we did that. */
+ do
+ lll_futex_wait (&pd->setxid_futex, 0);
+ while (pd->cancelhandling & SETXID_BITMASK);
+
+ /* Reset the value so that the stack can be reused. */
+ pd->setxid_futex = 0;
+ }
+
+ /* We cannot call '_exit' here. '_exit' will terminate the process.
+
+ The 'exit' implementation in the kernel will signal when the
+ process is really dead since 'clone' got passed the CLONE_CLEARTID
+ flag. The 'tid' field in the TCB will be set to zero.
+
+ The exit code is zero since in case all threads exit by calling
+ 'pthread_exit' the exit status must be 0 (zero). */
+ __exit_thread_inline (0);
+
+ /* NOTREACHED */
+ return 0;
+}
+
+
+/* Default thread attributes for the case when the user does not
+ provide any. */
+static const struct pthread_attr default_attr =
+ {
+ /* Just some value > 0 which gets rounded to the nearest page size. */
+ .guardsize = 1,
+ };
+
+
+int
+__pthread_create_2_1 (newthread, attr, start_routine, arg)
+ pthread_t *newthread;
+ const pthread_attr_t *attr;
+ void *(*start_routine) (void *);
+ void *arg;
+{
+ STACK_VARIABLES;
+
+ const struct pthread_attr *iattr = (struct pthread_attr *) attr;
+ if (iattr == NULL)
+ /* Is this the best idea? On NUMA machines this could mean
+ accessing far-away memory. */
+ iattr = &default_attr;
+
+ struct pthread *pd = NULL;
+ int err = ALLOCATE_STACK (iattr, &pd);
+ if (__builtin_expect (err != 0, 0))
+ /* Something went wrong. Maybe a parameter of the attributes is
+ invalid or we could not allocate memory. */
+ return err;
+
+
+ /* Initialize the TCB. All initializations with zero should be
+ performed in 'get_cached_stack'. This way we avoid doing this if
+ the stack freshly allocated with 'mmap'. */
+
+#ifdef TLS_TCB_AT_TP
+ /* Reference to the TCB itself. */
+ pd->header.self = pd;
+
+ /* Self-reference for TLS. */
+ pd->header.tcb = pd;
+#endif
+
+ /* Store the address of the start routine and the parameter. Since
+ we do not start the function directly the stillborn thread will
+ get the information from its thread descriptor. */
+ pd->start_routine = start_routine;
+ pd->arg = arg;
+
+ /* Copy the thread attribute flags. */
+ struct pthread *self = THREAD_SELF;
+ pd->flags = ((iattr->flags & ~(ATTR_FLAG_SCHED_SET | ATTR_FLAG_POLICY_SET))
+ | (self->flags & (ATTR_FLAG_SCHED_SET | ATTR_FLAG_POLICY_SET)));
+
+ /* Initialize the field for the ID of the thread which is waiting
+ for us. This is a self-reference in case the thread is created
+ detached. */
+ pd->joinid = iattr->flags & ATTR_FLAG_DETACHSTATE ? pd : NULL;
+
+ /* The debug events are inherited from the parent. */
+ pd->eventbuf = self->eventbuf;
+
+
+ /* Copy the parent's scheduling parameters. The flags will say what
+ is valid and what is not. */
+ pd->schedpolicy = self->schedpolicy;
+ pd->schedparam = self->schedparam;
+
+ /* Copy the stack guard canary. */
+#ifdef THREAD_COPY_STACK_GUARD
+ THREAD_COPY_STACK_GUARD (pd);
+#endif
+
+ /* Copy the pointer guard value. */
+#ifdef THREAD_COPY_POINTER_GUARD
+ THREAD_COPY_POINTER_GUARD (pd);
+#endif
+
+ /* Determine scheduling parameters for the thread. */
+ if (attr != NULL
+ && __builtin_expect ((iattr->flags & ATTR_FLAG_NOTINHERITSCHED) != 0, 0)
+ && (iattr->flags & (ATTR_FLAG_SCHED_SET | ATTR_FLAG_POLICY_SET)) != 0)
+ {
+ INTERNAL_SYSCALL_DECL (scerr);
+
+ /* Use the scheduling parameters the user provided. */
+ if (iattr->flags & ATTR_FLAG_POLICY_SET)
+ pd->schedpolicy = iattr->schedpolicy;
+ else if ((pd->flags & ATTR_FLAG_POLICY_SET) == 0)
+ {
+ pd->schedpolicy = INTERNAL_SYSCALL (sched_getscheduler, scerr, 1, 0);
+ pd->flags |= ATTR_FLAG_POLICY_SET;
+ }
+
+ if (iattr->flags & ATTR_FLAG_SCHED_SET)
+ memcpy (&pd->schedparam, &iattr->schedparam,
+ sizeof (struct sched_param));
+ else if ((pd->flags & ATTR_FLAG_SCHED_SET) == 0)
+ {
+ INTERNAL_SYSCALL (sched_getparam, scerr, 2, 0, &pd->schedparam);
+ pd->flags |= ATTR_FLAG_SCHED_SET;
+ }
+
+ /* Check for valid priorities. */
+ int minprio = INTERNAL_SYSCALL (sched_get_priority_min, scerr, 1,
+ iattr->schedpolicy);
+ int maxprio = INTERNAL_SYSCALL (sched_get_priority_max, scerr, 1,
+ iattr->schedpolicy);
+ if (pd->schedparam.sched_priority < minprio
+ || pd->schedparam.sched_priority > maxprio)
+ {
+ err = EINVAL;
+ goto errout;
+ }
+ }
+
+ /* Pass the descriptor to the caller. */
+ *newthread = (pthread_t) pd;
+
+ /* Remember whether the thread is detached or not. In case of an
+ error we have to free the stacks of non-detached stillborn
+ threads. */
+ bool is_detached = IS_DETACHED (pd);
+
+ /* Start the thread. */
+ err = create_thread (pd, iattr, STACK_VARIABLES_ARGS);
+ if (err != 0)
+ {
+ /* Something went wrong. Free the resources. */
+ if (!is_detached)
+ {
+ errout:
+ __deallocate_stack (pd);
+ }
+ return err;
+ }
+
+ return 0;
+}
+versioned_symbol (libpthread, __pthread_create_2_1, pthread_create, GLIBC_2_1);
+
+
+#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1)
+int
+__pthread_create_2_0 (newthread, attr, start_routine, arg)
+ pthread_t *newthread;
+ const pthread_attr_t *attr;
+ void *(*start_routine) (void *);
+ void *arg;
+{
+ /* The ATTR attribute is not really of type `pthread_attr_t *'. It has
+ the old size and access to the new members might crash the program.
+ We convert the struct now. */
+ struct pthread_attr new_attr;
+
+ if (attr != NULL)
+ {
+ struct pthread_attr *iattr = (struct pthread_attr *) attr;
+ size_t ps = __getpagesize ();
+
+ /* Copy values from the user-provided attributes. */
+ new_attr.schedparam = iattr->schedparam;
+ new_attr.schedpolicy = iattr->schedpolicy;
+ new_attr.flags = iattr->flags;
+
+ /* Fill in default values for the fields not present in the old
+ implementation. */
+ new_attr.guardsize = ps;
+ new_attr.stackaddr = NULL;
+ new_attr.stacksize = 0;
+ new_attr.cpuset = NULL;
+
+ /* We will pass this value on to the real implementation. */
+ attr = (pthread_attr_t *) &new_attr;
+ }
+
+ return __pthread_create_2_1 (newthread, attr, start_routine, arg);
+}
+compat_symbol (libpthread, __pthread_create_2_0, pthread_create,
+ GLIBC_2_0);
+#endif
+
+/* Information for libthread_db. */
+
+#include "../nptl_db/db_info.c"
+
+/* If pthread_create is present, libgcc_eh.a and libsupc++.a expects some other POSIX thread
+ functions to be present as well. */
+PTHREAD_STATIC_FN_REQUIRE (pthread_mutex_lock)
+PTHREAD_STATIC_FN_REQUIRE (pthread_mutex_unlock)
+
+PTHREAD_STATIC_FN_REQUIRE (pthread_once)
+PTHREAD_STATIC_FN_REQUIRE (pthread_cancel)
+
+PTHREAD_STATIC_FN_REQUIRE (pthread_key_create)
+PTHREAD_STATIC_FN_REQUIRE (pthread_setspecific)
+PTHREAD_STATIC_FN_REQUIRE (pthread_getspecific)
diff --git a/libc/nptl/pthread_detach.c b/libc/nptl/pthread_detach.c
new file mode 100644
index 000000000..1f0c2fe7c
--- /dev/null
+++ b/libc/nptl/pthread_detach.c
@@ -0,0 +1,57 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include "pthreadP.h"
+#include <atomic.h>
+
+
+int
+pthread_detach (th)
+ pthread_t th;
+{
+ struct pthread *pd = (struct pthread *) th;
+
+ /* Make sure the descriptor is valid. */
+ if (INVALID_NOT_TERMINATED_TD_P (pd))
+ /* Not a valid thread handle. */
+ return ESRCH;
+
+ int result = 0;
+
+ /* Mark the thread as detached. */
+ if (atomic_compare_and_exchange_bool_acq (&pd->joinid, pd, NULL))
+ {
+ /* There are two possibilities here. First, the thread might
+ already be detached. In this case we return EINVAL.
+ Otherwise there might already be a waiter. The standard does
+ not mention what happens in this case. */
+ if (IS_DETACHED (pd))
+ result = EINVAL;
+ }
+ else
+ /* Check whether the thread terminated meanwhile. In this case we
+ will just free the TCB. */
+ if ((pd->cancelhandling & EXITING_BITMASK) != 0)
+ /* Note that the code in __free_tcb makes sure each thread
+ control block is freed only once. */
+ __free_tcb (pd);
+
+ return result;
+}
diff --git a/libc/nptl/pthread_equal.c b/libc/nptl/pthread_equal.c
new file mode 100644
index 000000000..c9986096f
--- /dev/null
+++ b/libc/nptl/pthread_equal.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "pthreadP.h"
+
+
+int
+__pthread_equal (thread1, thread2)
+ pthread_t thread1;
+ pthread_t thread2;
+{
+ return thread1 == thread2;
+}
+strong_alias (__pthread_equal, pthread_equal)
diff --git a/libc/nptl/pthread_exit.c b/libc/nptl/pthread_exit.c
new file mode 100644
index 000000000..85d8fd456
--- /dev/null
+++ b/libc/nptl/pthread_exit.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <stdlib.h>
+#include "pthreadP.h"
+
+
+void
+__pthread_exit (value)
+ void *value;
+{
+ THREAD_SETMEM (THREAD_SELF, result, value);
+
+ __do_cancel ();
+}
+strong_alias (__pthread_exit, pthread_exit)
diff --git a/libc/nptl/pthread_getattr_np.c b/libc/nptl/pthread_getattr_np.c
new file mode 100644
index 000000000..4bdc7b5b1
--- /dev/null
+++ b/libc/nptl/pthread_getattr_np.c
@@ -0,0 +1,181 @@
+/* Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdio_ext.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/resource.h>
+#include "pthreadP.h"
+#include <lowlevellock.h>
+#include <ldsodefs.h>
+
+
+int
+pthread_getattr_np (thread_id, attr)
+ pthread_t thread_id;
+ pthread_attr_t *attr;
+{
+ struct pthread *thread = (struct pthread *) thread_id;
+ struct pthread_attr *iattr = (struct pthread_attr *) attr;
+ int ret = 0;
+
+ /* We have to handle cancellation in the following code since we are
+ locking another threads desriptor. */
+ pthread_cleanup_push ((void (*) (void *)) lll_unlock_wake_cb, &thread->lock);
+
+ lll_lock (thread->lock);
+
+ /* The thread library is responsible for keeping the values in the
+ thread desriptor up-to-date in case the user changes them. */
+ memcpy (&iattr->schedparam, &thread->schedparam,
+ sizeof (struct sched_param));
+ iattr->schedpolicy = thread->schedpolicy;
+
+ /* Clear the flags work. */
+ iattr->flags = thread->flags;
+
+ /* The thread might be detached by now. */
+ if (IS_DETACHED (thread))
+ iattr->flags |= ATTR_FLAG_DETACHSTATE;
+
+ /* This is the guardsize after adjusting it. */
+ iattr->guardsize = thread->reported_guardsize;
+
+ /* The sizes are subject to alignment. */
+ if (__builtin_expect (thread->stackblock != NULL, 1))
+ {
+ iattr->stacksize = thread->stackblock_size;
+ iattr->stackaddr = (char *) thread->stackblock + iattr->stacksize;
+ }
+ else
+ {
+ /* No stack information available. This must be for the initial
+ thread. Get the info in some magical way. */
+ assert (abs (thread->pid) == thread->tid);
+
+ /* Stack size limit. */
+ struct rlimit rl;
+
+ /* The safest way to get the top of the stack is to read
+ /proc/self/maps and locate the line into which
+ __libc_stack_end falls. */
+ FILE *fp = fopen ("/proc/self/maps", "rc");
+ if (fp == NULL)
+ ret = errno;
+ /* We need the limit of the stack in any case. */
+ else
+ {
+ if (getrlimit (RLIMIT_STACK, &rl) != 0)
+ ret = errno;
+ else
+ {
+ /* We need no locking. */
+ __fsetlocking (fp, FSETLOCKING_BYCALLER);
+
+ /* Until we found an entry (which should always be the case)
+ mark the result as a failure. */
+ ret = ENOENT;
+
+ char *line = NULL;
+ size_t linelen = 0;
+ uintptr_t last_to = 0;
+
+ while (! feof_unlocked (fp))
+ {
+ if (__getdelim (&line, &linelen, '\n', fp) <= 0)
+ break;
+
+ uintptr_t from;
+ uintptr_t to;
+ if (sscanf (line, "%" SCNxPTR "-%" SCNxPTR, &from, &to) != 2)
+ continue;
+ if (from <= (uintptr_t) __libc_stack_end
+ && (uintptr_t) __libc_stack_end < to)
+ {
+ /* Found the entry. Now we have the info we need. */
+ iattr->stacksize = rl.rlim_cur;
+ iattr->stackaddr = (void *) to;
+
+ /* The limit might be too high. */
+ if ((size_t) iattr->stacksize
+ > (size_t) iattr->stackaddr - last_to)
+ iattr->stacksize = (size_t) iattr->stackaddr - last_to;
+
+ /* We succeed and no need to look further. */
+ ret = 0;
+ break;
+ }
+ last_to = to;
+ }
+
+ free (line);
+ }
+
+ fclose (fp);
+ }
+ }
+
+ iattr->flags |= ATTR_FLAG_STACKADDR;
+
+ if (ret == 0)
+ {
+ size_t size = 16;
+ cpu_set_t *cpuset = NULL;
+
+ do
+ {
+ size <<= 1;
+
+ void *newp = realloc (cpuset, size);
+ if (newp == NULL)
+ {
+ ret = ENOMEM;
+ break;
+ }
+ cpuset = (cpu_set_t *) newp;
+
+ ret = __pthread_getaffinity_np (thread_id, size, cpuset);
+ }
+ /* Pick some ridiculous upper limit. Is 8 million CPUs enough? */
+ while (ret == EINVAL && size < 1024 * 1024);
+
+ if (ret == 0)
+ {
+ iattr->cpuset = cpuset;
+ iattr->cpusetsize = size;
+ }
+ else
+ {
+ free (cpuset);
+ if (ret == ENOSYS)
+ /* There is no such functionality. */
+ ret = 0;
+ }
+ }
+
+ lll_unlock (thread->lock);
+
+ pthread_cleanup_pop (0);
+
+ return ret;
+}
diff --git a/libc/nptl/pthread_getconcurrency.c b/libc/nptl/pthread_getconcurrency.c
new file mode 100644
index 000000000..52c0c7cbe
--- /dev/null
+++ b/libc/nptl/pthread_getconcurrency.c
@@ -0,0 +1,27 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "pthreadP.h"
+
+
+int
+pthread_getconcurrency (void)
+{
+ return __concurrency_level;
+}
diff --git a/libc/nptl/pthread_getschedparam.c b/libc/nptl/pthread_getschedparam.c
new file mode 100644
index 000000000..434d86777
--- /dev/null
+++ b/libc/nptl/pthread_getschedparam.c
@@ -0,0 +1,81 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <string.h>
+#include "pthreadP.h"
+#include <lowlevellock.h>
+
+
+int
+__pthread_getschedparam (threadid, policy, param)
+ pthread_t threadid;
+ int *policy;
+ struct sched_param *param;
+{
+ struct pthread *pd = (struct pthread *) threadid;
+
+ /* Make sure the descriptor is valid. */
+ if (INVALID_TD_P (pd))
+ /* Not a valid thread handle. */
+ return ESRCH;
+
+ int result = 0;
+
+ /* We have to handle cancellation in the following code since we are
+ locking another threads descriptor. */
+ pthread_cleanup_push ((void (*) (void *)) lll_unlock_wake_cb, &pd->lock);
+
+ lll_lock (pd->lock);
+
+ /* The library is responsible for maintaining the values at all
+ times. If the user uses a interface other than
+ pthread_setschedparam to modify the scheduler setting it is not
+ the library's problem. In case the descriptor's values have
+ not yet been retrieved do it now. */
+ if ((pd->flags & ATTR_FLAG_SCHED_SET) == 0)
+ {
+ if (__sched_getparam (pd->tid, &pd->schedparam) != 0)
+ result = 1;
+ else
+ pd->flags |= ATTR_FLAG_SCHED_SET;
+ }
+
+ if ((pd->flags & ATTR_FLAG_POLICY_SET) == 0)
+ {
+ pd->schedpolicy = __sched_getscheduler (pd->tid);
+ if (pd->schedpolicy == -1)
+ result = 1;
+ else
+ pd->flags |= ATTR_FLAG_POLICY_SET;
+ }
+
+ if (result == 0)
+ {
+ *policy = pd->schedpolicy;
+ memcpy (param, &pd->schedparam, sizeof (struct sched_param));
+ }
+
+ lll_unlock (pd->lock);
+
+ pthread_cleanup_pop (0);
+
+ return result;
+}
+strong_alias (__pthread_getschedparam, pthread_getschedparam)
diff --git a/libc/nptl/pthread_getspecific.c b/libc/nptl/pthread_getspecific.c
new file mode 100644
index 000000000..afb4d26ff
--- /dev/null
+++ b/libc/nptl/pthread_getspecific.c
@@ -0,0 +1,69 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <stdlib.h>
+#include "pthreadP.h"
+
+
+void *
+__pthread_getspecific (key)
+ pthread_key_t key;
+{
+ struct pthread_key_data *data;
+
+ /* Special case access to the first 2nd-level block. This is the
+ usual case. */
+ if (__builtin_expect (key < PTHREAD_KEY_2NDLEVEL_SIZE, 1))
+ data = &THREAD_SELF->specific_1stblock[key];
+ else
+ {
+ /* Verify the key is sane. */
+ if (key >= PTHREAD_KEYS_MAX)
+ /* Not valid. */
+ return NULL;
+
+ unsigned int idx1st = key / PTHREAD_KEY_2NDLEVEL_SIZE;
+ unsigned int idx2nd = key % PTHREAD_KEY_2NDLEVEL_SIZE;
+
+ /* If the sequence number doesn't match or the key cannot be defined
+ for this thread since the second level array is not allocated
+ return NULL, too. */
+ struct pthread_key_data *level2 = THREAD_GETMEM_NC (THREAD_SELF,
+ specific, idx1st);
+ if (level2 == NULL)
+ /* Not allocated, therefore no data. */
+ return NULL;
+
+ /* There is data. */
+ data = &level2[idx2nd];
+ }
+
+ void *result = data->data;
+ if (result != NULL)
+ {
+ uintptr_t seq = data->seq;
+
+ if (__builtin_expect (seq != __pthread_keys[key].seq, 0))
+ result = data->data = NULL;
+ }
+
+ return result;
+}
+strong_alias (__pthread_getspecific, pthread_getspecific)
+strong_alias (__pthread_getspecific, __pthread_getspecific_internal)
diff --git a/libc/nptl/pthread_join.c b/libc/nptl/pthread_join.c
new file mode 100644
index 000000000..c88d85b52
--- /dev/null
+++ b/libc/nptl/pthread_join.c
@@ -0,0 +1,114 @@
+/* Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <stdlib.h>
+
+#include <atomic.h>
+#include "pthreadP.h"
+
+
+static void
+cleanup (void *arg)
+{
+ /* If we already changed the waiter ID, reset it. The call cannot
+ fail for any reason but the thread not having done that yet so
+ there is no reason for a loop. */
+ atomic_compare_and_exchange_bool_acq ((struct pthread **) arg, NULL,
+ THREAD_SELF);
+}
+
+
+int
+pthread_join (threadid, thread_return)
+ pthread_t threadid;
+ void **thread_return;
+{
+ struct pthread *pd = (struct pthread *) threadid;
+
+ /* Make sure the descriptor is valid. */
+ if (INVALID_NOT_TERMINATED_TD_P (pd))
+ /* Not a valid thread handle. */
+ return ESRCH;
+
+ /* Is the thread joinable?. */
+ if (IS_DETACHED (pd))
+ /* We cannot wait for the thread. */
+ return EINVAL;
+
+ struct pthread *self = THREAD_SELF;
+ int result = 0;
+
+ /* During the wait we change to asynchronous cancellation. If we
+ are canceled the thread we are waiting for must be marked as
+ un-wait-ed for again. */
+ pthread_cleanup_push (cleanup, &pd->joinid);
+
+ /* Switch to asynchronous cancellation. */
+ int oldtype = CANCEL_ASYNC ();
+
+ if ((pd == self
+ || (self->joinid == pd
+ && (pd->cancelhandling
+ & (CANCELING_BITMASK | CANCELED_BITMASK | EXITING_BITMASK
+ | TERMINATED_BITMASK)) == 0))
+ && !CANCEL_ENABLED_AND_CANCELED (self->cancelhandling))
+ /* This is a deadlock situation. The threads are waiting for each
+ other to finish. Note that this is a "may" error. To be 100%
+ sure we catch this error we would have to lock the data
+ structures but it is not necessary. In the unlikely case that
+ two threads are really caught in this situation they will
+ deadlock. It is the programmer's problem to figure this
+ out. */
+ result = EDEADLK;
+ /* Wait for the thread to finish. If it is already locked something
+ is wrong. There can only be one waiter. */
+ else if (__builtin_expect (atomic_compare_and_exchange_bool_acq (&pd->joinid,
+ self,
+ NULL), 0))
+ /* There is already somebody waiting for the thread. */
+ result = EINVAL;
+ else
+ /* Wait for the child. */
+ lll_wait_tid (pd->tid);
+
+
+ /* Restore cancellation mode. */
+ CANCEL_RESET (oldtype);
+
+ /* Remove the handler. */
+ pthread_cleanup_pop (0);
+
+
+ if (__builtin_expect (result == 0, 1))
+ {
+ /* We mark the thread as terminated and as joined. */
+ pd->tid = -1;
+
+ /* Store the return value if the caller is interested. */
+ if (thread_return != NULL)
+ *thread_return = pd->result;
+
+
+ /* Free the TCB. */
+ __free_tcb (pd);
+ }
+
+ return result;
+}
diff --git a/libc/nptl/pthread_key_create.c b/libc/nptl/pthread_key_create.c
new file mode 100644
index 000000000..5fc884624
--- /dev/null
+++ b/libc/nptl/pthread_key_create.c
@@ -0,0 +1,54 @@
+/* Copyright (C) 2002, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include "pthreadP.h"
+#include <atomic.h>
+
+
+int
+__pthread_key_create (key, destr)
+ pthread_key_t *key;
+ void (*destr) (void *);
+{
+ /* Find a slot in __pthread_kyes which is unused. */
+ for (size_t cnt = 0; cnt < PTHREAD_KEYS_MAX; ++cnt)
+ {
+ uintptr_t seq = __pthread_keys[cnt].seq;
+
+ if (KEY_UNUSED (seq) && KEY_USABLE (seq)
+ /* We found an unused slot. Try to allocate it. */
+ && ! atomic_compare_and_exchange_bool_acq (&__pthread_keys[cnt].seq,
+ seq + 1, seq))
+ {
+ /* Remember the destructor. */
+ __pthread_keys[cnt].destr = destr;
+
+ /* Return the key to the caller. */
+ *key = cnt;
+
+ /* The call succeeded. */
+ return 0;
+ }
+ }
+
+ return EAGAIN;
+}
+strong_alias (__pthread_key_create, pthread_key_create)
+strong_alias (__pthread_key_create, __pthread_key_create_internal)
diff --git a/libc/nptl/pthread_key_delete.c b/libc/nptl/pthread_key_delete.c
new file mode 100644
index 000000000..ae7d7c459
--- /dev/null
+++ b/libc/nptl/pthread_key_delete.c
@@ -0,0 +1,43 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include "pthreadP.h"
+#include <atomic.h>
+
+
+int
+pthread_key_delete (key)
+ pthread_key_t key;
+{
+ int result = EINVAL;
+
+ if (__builtin_expect (key < PTHREAD_KEYS_MAX, 1))
+ {
+ unsigned int seq = __pthread_keys[key].seq;
+
+ if (__builtin_expect (! KEY_UNUSED (seq), 1)
+ && ! atomic_compare_and_exchange_bool_acq (&__pthread_keys[key].seq,
+ seq + 1, seq))
+ /* We deleted a valid key. */
+ result = 0;
+ }
+
+ return result;
+}
diff --git a/libc/nptl/pthread_kill_other_threads.c b/libc/nptl/pthread_kill_other_threads.c
new file mode 100644
index 000000000..a4464233a
--- /dev/null
+++ b/libc/nptl/pthread_kill_other_threads.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <shlib-compat.h>
+
+
+#ifdef SHARED
+/* This function does not serve a useful purpose in the thread library
+ implementation anymore. It used to be necessary when then kernel
+ could not shut down "processes" but this is not the case anymore.
+
+ We could theoretically provide an equivalent implementation but
+ this is not necessary since the kernel already does a much better
+ job than we ever could. */
+void
+__pthread_kill_other_threads_np (void)
+{
+}
+compat_symbol (libpthread, __pthread_kill_other_threads_np,
+ pthread_kill_other_threads_np, GLIBC_2_0);
+#endif
diff --git a/libc/nptl/pthread_mutex_consistent.c b/libc/nptl/pthread_mutex_consistent.c
new file mode 100644
index 000000000..d4f287b75
--- /dev/null
+++ b/libc/nptl/pthread_mutex_consistent.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2005.
+
+ 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 <errno.h>
+#include <pthreadP.h>
+
+
+int
+pthread_mutex_consistent_np (mutex)
+ pthread_mutex_t *mutex;
+{
+ /* Test whether this is a robust mutex with a dead owner. */
+ if ((mutex->__data.__kind & PTHREAD_MUTEX_ROBUST_NORMAL_NP) == 0
+ || mutex->__data.__owner != PTHREAD_MUTEX_INCONSISTENT)
+ return EINVAL;
+
+ mutex->__data.__owner = THREAD_GETMEM (THREAD_SELF, tid);
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_mutex_destroy.c b/libc/nptl/pthread_mutex_destroy.c
new file mode 100644
index 000000000..e2c9f8a39
--- /dev/null
+++ b/libc/nptl/pthread_mutex_destroy.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include "pthreadP.h"
+
+
+int
+__pthread_mutex_destroy (mutex)
+ pthread_mutex_t *mutex;
+{
+ if ((mutex->__data.__kind & PTHREAD_MUTEX_ROBUST_NORMAL_NP) == 0
+ && mutex->__data.__nusers != 0)
+ return EBUSY;
+
+ /* Set to an invalid value. */
+ mutex->__data.__kind = -1;
+
+ return 0;
+}
+strong_alias (__pthread_mutex_destroy, pthread_mutex_destroy)
+INTDEF(__pthread_mutex_destroy)
diff --git a/libc/nptl/pthread_mutex_getprioceiling.c b/libc/nptl/pthread_mutex_getprioceiling.c
new file mode 100644
index 000000000..1ce5eaebe
--- /dev/null
+++ b/libc/nptl/pthread_mutex_getprioceiling.c
@@ -0,0 +1,38 @@
+/* Get current priority ceiling of pthread_mutex_t.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2006.
+
+ 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 <errno.h>
+#include <pthreadP.h>
+
+
+int
+pthread_mutex_getprioceiling (mutex, prioceiling)
+ const pthread_mutex_t *mutex;
+ int *prioceiling;
+{
+ if (__builtin_expect ((mutex->__data.__kind
+ & PTHREAD_MUTEX_PRIO_PROTECT_NP) == 0, 0))
+ return EINVAL;
+
+ *prioceiling = (mutex->__data.__lock & PTHREAD_MUTEX_PRIO_CEILING_MASK)
+ >> PTHREAD_MUTEX_PRIO_CEILING_SHIFT;
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_mutex_init.c b/libc/nptl/pthread_mutex_init.c
new file mode 100644
index 000000000..96f1fb00f
--- /dev/null
+++ b/libc/nptl/pthread_mutex_init.c
@@ -0,0 +1,133 @@
+/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include <errno.h>
+#include <string.h>
+#include "pthreadP.h"
+
+static const struct pthread_mutexattr default_attr =
+ {
+ /* Default is a normal mutex, not shared between processes. */
+ .mutexkind = PTHREAD_MUTEX_NORMAL
+ };
+
+
+#ifndef __ASSUME_FUTEX_LOCK_PI
+static int tpi_supported;
+#endif
+
+
+int
+__pthread_mutex_init (mutex, mutexattr)
+ pthread_mutex_t *mutex;
+ const pthread_mutexattr_t *mutexattr;
+{
+ const struct pthread_mutexattr *imutexattr;
+
+ assert (sizeof (pthread_mutex_t) <= __SIZEOF_PTHREAD_MUTEX_T);
+
+ imutexattr = (const struct pthread_mutexattr *) mutexattr ?: &default_attr;
+
+ /* Sanity checks. */
+ switch (__builtin_expect (imutexattr->mutexkind
+ & PTHREAD_MUTEXATTR_PROTOCOL_MASK,
+ PTHREAD_PRIO_NONE
+ << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT))
+ {
+ case PTHREAD_PRIO_NONE << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT:
+ break;
+
+ case PTHREAD_PRIO_INHERIT << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT:
+#ifndef __ASSUME_FUTEX_LOCK_PI
+ if (__builtin_expect (tpi_supported == 0, 0))
+ {
+ int lock = 0;
+ INTERNAL_SYSCALL_DECL (err);
+ int ret = INTERNAL_SYSCALL (futex, err, 4, &lock, FUTEX_UNLOCK_PI,
+ 0, 0);
+ assert (INTERNAL_SYSCALL_ERROR_P (ret, err));
+ tpi_supported = INTERNAL_SYSCALL_ERRNO (ret, err) == ENOSYS ? -1 : 1;
+ }
+ if (__builtin_expect (tpi_supported < 0, 0))
+ return ENOTSUP;
+#endif
+ break;
+
+ default:
+ /* XXX: For now we don't support robust priority protected mutexes. */
+ if (imutexattr->mutexkind & PTHREAD_MUTEXATTR_FLAG_ROBUST)
+ return ENOTSUP;
+ break;
+ }
+
+ /* Clear the whole variable. */
+ memset (mutex, '\0', __SIZEOF_PTHREAD_MUTEX_T);
+
+ /* Copy the values from the attribute. */
+ mutex->__data.__kind = imutexattr->mutexkind & ~PTHREAD_MUTEXATTR_FLAG_BITS;
+
+ if ((imutexattr->mutexkind & PTHREAD_MUTEXATTR_FLAG_ROBUST) != 0)
+ {
+#ifndef __ASSUME_SET_ROBUST_LIST
+ if ((imutexattr->mutexkind & PTHREAD_MUTEXATTR_FLAG_PSHARED) != 0
+ && __set_robust_list_avail < 0)
+ return ENOTSUP;
+#endif
+
+ mutex->__data.__kind |= PTHREAD_MUTEX_ROBUST_NORMAL_NP;
+ }
+
+ switch (imutexattr->mutexkind & PTHREAD_MUTEXATTR_PROTOCOL_MASK)
+ {
+ case PTHREAD_PRIO_INHERIT << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT:
+ mutex->__data.__kind |= PTHREAD_MUTEX_PRIO_INHERIT_NP;
+ break;
+
+ case PTHREAD_PRIO_PROTECT << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT:
+ mutex->__data.__kind |= PTHREAD_MUTEX_PRIO_PROTECT_NP;
+
+ int ceiling = (imutexattr->mutexkind
+ & PTHREAD_MUTEXATTR_PRIO_CEILING_MASK)
+ >> PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT;
+ if (! ceiling)
+ {
+ if (__sched_fifo_min_prio == -1)
+ __init_sched_fifo_prio ();
+ if (ceiling < __sched_fifo_min_prio)
+ ceiling = __sched_fifo_min_prio;
+ }
+ mutex->__data.__lock = ceiling << PTHREAD_MUTEX_PRIO_CEILING_SHIFT;
+ break;
+
+ default:
+ break;
+ }
+
+ /* Default values: mutex not used yet. */
+ // mutex->__count = 0; already done by memset
+ // mutex->__owner = 0; already done by memset
+ // mutex->__nusers = 0; already done by memset
+ // mutex->__spins = 0; already done by memset
+ // mutex->__next = NULL; already done by memset
+
+ return 0;
+}
+strong_alias (__pthread_mutex_init, pthread_mutex_init)
+INTDEF(__pthread_mutex_init)
diff --git a/libc/nptl/pthread_mutex_lock.c b/libc/nptl/pthread_mutex_lock.c
new file mode 100644
index 000000000..52cc47f4c
--- /dev/null
+++ b/libc/nptl/pthread_mutex_lock.c
@@ -0,0 +1,438 @@
+/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <not-cancel.h>
+#include "pthreadP.h"
+#include <lowlevellock.h>
+
+
+#ifndef LLL_MUTEX_LOCK
+# define LLL_MUTEX_LOCK(mutex) lll_mutex_lock (mutex)
+# define LLL_MUTEX_TRYLOCK(mutex) lll_mutex_trylock (mutex)
+# define LLL_ROBUST_MUTEX_LOCK(mutex, id) lll_robust_mutex_lock (mutex, id)
+#endif
+
+
+int
+__pthread_mutex_lock (mutex)
+ pthread_mutex_t *mutex;
+{
+ assert (sizeof (mutex->__size) >= sizeof (mutex->__data));
+
+ int oldval;
+ pid_t id = THREAD_GETMEM (THREAD_SELF, tid);
+
+ int retval = 0;
+ switch (__builtin_expect (mutex->__data.__kind, PTHREAD_MUTEX_TIMED_NP))
+ {
+ /* Recursive mutex. */
+ case PTHREAD_MUTEX_RECURSIVE_NP:
+ /* Check whether we already hold the mutex. */
+ if (mutex->__data.__owner == id)
+ {
+ /* Just bump the counter. */
+ if (__builtin_expect (mutex->__data.__count + 1 == 0, 0))
+ /* Overflow of the counter. */
+ return EAGAIN;
+
+ ++mutex->__data.__count;
+
+ return 0;
+ }
+
+ /* We have to get the mutex. */
+ LLL_MUTEX_LOCK (mutex->__data.__lock);
+
+ assert (mutex->__data.__owner == 0);
+ mutex->__data.__count = 1;
+ break;
+
+ /* Error checking mutex. */
+ case PTHREAD_MUTEX_ERRORCHECK_NP:
+ /* Check whether we already hold the mutex. */
+ if (__builtin_expect (mutex->__data.__owner == id, 0))
+ return EDEADLK;
+
+ /* FALLTHROUGH */
+
+ case PTHREAD_MUTEX_TIMED_NP:
+ simple:
+ /* Normal mutex. */
+ LLL_MUTEX_LOCK (mutex->__data.__lock);
+ assert (mutex->__data.__owner == 0);
+ break;
+
+ case PTHREAD_MUTEX_ADAPTIVE_NP:
+ if (! __is_smp)
+ goto simple;
+
+ if (LLL_MUTEX_TRYLOCK (mutex->__data.__lock) != 0)
+ {
+ int cnt = 0;
+ int max_cnt = MIN (MAX_ADAPTIVE_COUNT,
+ mutex->__data.__spins * 2 + 10);
+ do
+ {
+ if (cnt++ >= max_cnt)
+ {
+ LLL_MUTEX_LOCK (mutex->__data.__lock);
+ break;
+ }
+
+#ifdef BUSY_WAIT_NOP
+ BUSY_WAIT_NOP;
+#endif
+ }
+ while (LLL_MUTEX_TRYLOCK (mutex->__data.__lock) != 0);
+
+ mutex->__data.__spins += (cnt - mutex->__data.__spins) / 8;
+ }
+ assert (mutex->__data.__owner == 0);
+ break;
+
+ case PTHREAD_MUTEX_ROBUST_RECURSIVE_NP:
+ case PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP:
+ case PTHREAD_MUTEX_ROBUST_NORMAL_NP:
+ case PTHREAD_MUTEX_ROBUST_ADAPTIVE_NP:
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending,
+ &mutex->__data.__list.__next);
+
+ oldval = mutex->__data.__lock;
+ do
+ {
+ again:
+ if ((oldval & FUTEX_OWNER_DIED) != 0)
+ {
+ /* The previous owner died. Try locking the mutex. */
+ int newval = id;
+#ifdef NO_INCR
+ newval |= FUTEX_WAITERS;
+#endif
+
+ newval
+ = atomic_compare_and_exchange_val_acq (&mutex->__data.__lock,
+ newval, oldval);
+
+ if (newval != oldval)
+ {
+ oldval = newval;
+ goto again;
+ }
+
+ /* We got the mutex. */
+ mutex->__data.__count = 1;
+ /* But it is inconsistent unless marked otherwise. */
+ mutex->__data.__owner = PTHREAD_MUTEX_INCONSISTENT;
+
+ ENQUEUE_MUTEX (mutex);
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+
+ /* Note that we deliberately exit here. If we fall
+ through to the end of the function __nusers would be
+ incremented which is not correct because the old
+ owner has to be discounted. If we are not supposed
+ to increment __nusers we actually have to decrement
+ it here. */
+#ifdef NO_INCR
+ --mutex->__data.__nusers;
+#endif
+
+ return EOWNERDEAD;
+ }
+
+ /* Check whether we already hold the mutex. */
+ if (__builtin_expect ((oldval & FUTEX_TID_MASK) == id, 0))
+ {
+ if (mutex->__data.__kind
+ == PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP)
+ {
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending,
+ NULL);
+ return EDEADLK;
+ }
+
+ if (mutex->__data.__kind
+ == PTHREAD_MUTEX_ROBUST_RECURSIVE_NP)
+ {
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending,
+ NULL);
+
+ /* Just bump the counter. */
+ if (__builtin_expect (mutex->__data.__count + 1 == 0, 0))
+ /* Overflow of the counter. */
+ return EAGAIN;
+
+ ++mutex->__data.__count;
+
+ return 0;
+ }
+ }
+
+ oldval = LLL_ROBUST_MUTEX_LOCK (mutex->__data.__lock, id);
+
+ if (__builtin_expect (mutex->__data.__owner
+ == PTHREAD_MUTEX_NOTRECOVERABLE, 0))
+ {
+ /* This mutex is now not recoverable. */
+ mutex->__data.__count = 0;
+ lll_mutex_unlock (mutex->__data.__lock);
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+ return ENOTRECOVERABLE;
+ }
+ }
+ while ((oldval & FUTEX_OWNER_DIED) != 0);
+
+ mutex->__data.__count = 1;
+ ENQUEUE_MUTEX (mutex);
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+ break;
+
+ case PTHREAD_MUTEX_PI_RECURSIVE_NP:
+ case PTHREAD_MUTEX_PI_ERRORCHECK_NP:
+ case PTHREAD_MUTEX_PI_NORMAL_NP:
+ case PTHREAD_MUTEX_PI_ADAPTIVE_NP:
+ case PTHREAD_MUTEX_PI_ROBUST_RECURSIVE_NP:
+ case PTHREAD_MUTEX_PI_ROBUST_ERRORCHECK_NP:
+ case PTHREAD_MUTEX_PI_ROBUST_NORMAL_NP:
+ case PTHREAD_MUTEX_PI_ROBUST_ADAPTIVE_NP:
+ {
+ int kind = mutex->__data.__kind & PTHREAD_MUTEX_KIND_MASK_NP;
+ int robust = mutex->__data.__kind & PTHREAD_MUTEX_ROBUST_NORMAL_NP;
+
+ if (robust)
+ /* Note: robust PI futexes are signaled by setting bit 0. */
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending,
+ (void *) (((uintptr_t) &mutex->__data.__list.__next)
+ | 1));
+
+ oldval = mutex->__data.__lock;
+
+ /* Check whether we already hold the mutex. */
+ if (__builtin_expect ((oldval & FUTEX_TID_MASK) == id, 0))
+ {
+ if (kind == PTHREAD_MUTEX_ERRORCHECK_NP)
+ {
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+ return EDEADLK;
+ }
+
+ if (kind == PTHREAD_MUTEX_RECURSIVE_NP)
+ {
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+
+ /* Just bump the counter. */
+ if (__builtin_expect (mutex->__data.__count + 1 == 0, 0))
+ /* Overflow of the counter. */
+ return EAGAIN;
+
+ ++mutex->__data.__count;
+
+ return 0;
+ }
+ }
+
+ int newval = id;
+#ifdef NO_INCR
+ newval |= FUTEX_WAITERS;
+#endif
+ oldval = atomic_compare_and_exchange_val_acq (&mutex->__data.__lock,
+ newval, 0);
+
+ if (oldval != 0)
+ {
+ /* The mutex is locked. The kernel will now take care of
+ everything. */
+ INTERNAL_SYSCALL_DECL (__err);
+ int e = INTERNAL_SYSCALL (futex, __err, 4, &mutex->__data.__lock,
+ FUTEX_LOCK_PI, 1, 0);
+
+ if (INTERNAL_SYSCALL_ERROR_P (e, __err)
+ && (INTERNAL_SYSCALL_ERRNO (e, __err) == ESRCH
+ || INTERNAL_SYSCALL_ERRNO (e, __err) == EDEADLK))
+ {
+ assert (INTERNAL_SYSCALL_ERRNO (e, __err) != EDEADLK
+ || (kind != PTHREAD_MUTEX_ERRORCHECK_NP
+ && kind != PTHREAD_MUTEX_RECURSIVE_NP));
+ /* ESRCH can happen only for non-robust PI mutexes where
+ the owner of the lock died. */
+ assert (INTERNAL_SYSCALL_ERRNO (e, __err) != ESRCH || !robust);
+
+ /* Delay the thread indefinitely. */
+ while (1)
+ pause_not_cancel ();
+ }
+
+ oldval = mutex->__data.__lock;
+
+ assert (robust || (oldval & FUTEX_OWNER_DIED) == 0);
+ }
+
+ if (__builtin_expect (oldval & FUTEX_OWNER_DIED, 0))
+ {
+ atomic_and (&mutex->__data.__lock, ~FUTEX_OWNER_DIED);
+
+ /* We got the mutex. */
+ mutex->__data.__count = 1;
+ /* But it is inconsistent unless marked otherwise. */
+ mutex->__data.__owner = PTHREAD_MUTEX_INCONSISTENT;
+
+ ENQUEUE_MUTEX_PI (mutex);
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+
+ /* Note that we deliberately exit here. If we fall
+ through to the end of the function __nusers would be
+ incremented which is not correct because the old owner
+ has to be discounted. If we are not supposed to
+ increment __nusers we actually have to decrement it here. */
+#ifdef NO_INCR
+ --mutex->__data.__nusers;
+#endif
+
+ return EOWNERDEAD;
+ }
+
+ if (robust
+ && __builtin_expect (mutex->__data.__owner
+ == PTHREAD_MUTEX_NOTRECOVERABLE, 0))
+ {
+ /* This mutex is now not recoverable. */
+ mutex->__data.__count = 0;
+
+ INTERNAL_SYSCALL_DECL (__err);
+ INTERNAL_SYSCALL (futex, __err, 4, &mutex->__data.__lock,
+ FUTEX_UNLOCK_PI, 0, 0);
+
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+ return ENOTRECOVERABLE;
+ }
+
+ mutex->__data.__count = 1;
+ if (robust)
+ {
+ ENQUEUE_MUTEX_PI (mutex);
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+ }
+ }
+ break;
+
+ case PTHREAD_MUTEX_PP_RECURSIVE_NP:
+ case PTHREAD_MUTEX_PP_ERRORCHECK_NP:
+ case PTHREAD_MUTEX_PP_NORMAL_NP:
+ case PTHREAD_MUTEX_PP_ADAPTIVE_NP:
+ {
+ int kind = mutex->__data.__kind & PTHREAD_MUTEX_KIND_MASK_NP;
+
+ oldval = mutex->__data.__lock;
+
+ /* Check whether we already hold the mutex. */
+ if (mutex->__data.__owner == id)
+ {
+ if (kind == PTHREAD_MUTEX_ERRORCHECK_NP)
+ return EDEADLK;
+
+ if (kind == PTHREAD_MUTEX_RECURSIVE_NP)
+ {
+ /* Just bump the counter. */
+ if (__builtin_expect (mutex->__data.__count + 1 == 0, 0))
+ /* Overflow of the counter. */
+ return EAGAIN;
+
+ ++mutex->__data.__count;
+
+ return 0;
+ }
+ }
+
+ int oldprio = -1, ceilval;
+ do
+ {
+ int ceiling = (oldval & PTHREAD_MUTEX_PRIO_CEILING_MASK)
+ >> PTHREAD_MUTEX_PRIO_CEILING_SHIFT;
+
+ if (__pthread_current_priority () > ceiling)
+ {
+ if (oldprio != -1)
+ __pthread_tpp_change_priority (oldprio, -1);
+ return EINVAL;
+ }
+
+ retval = __pthread_tpp_change_priority (oldprio, ceiling);
+ if (retval)
+ return retval;
+
+ ceilval = ceiling << PTHREAD_MUTEX_PRIO_CEILING_SHIFT;
+ oldprio = ceiling;
+
+ oldval
+ = atomic_compare_and_exchange_val_acq (&mutex->__data.__lock,
+#ifdef NO_INCR
+ ceilval | 2,
+#else
+ ceilval | 1,
+#endif
+ ceilval);
+
+ if (oldval == ceilval)
+ break;
+
+ do
+ {
+ oldval
+ = atomic_compare_and_exchange_val_acq (&mutex->__data.__lock,
+ ceilval | 2,
+ ceilval | 1);
+
+ if ((oldval & PTHREAD_MUTEX_PRIO_CEILING_MASK) != ceilval)
+ break;
+
+ if (oldval != ceilval)
+ lll_futex_wait (&mutex->__data.__lock, ceilval | 2);
+ }
+ while (atomic_compare_and_exchange_val_acq (&mutex->__data.__lock,
+ ceilval | 2, ceilval)
+ != ceilval);
+ }
+ while ((oldval & PTHREAD_MUTEX_PRIO_CEILING_MASK) != ceilval);
+
+ assert (mutex->__data.__owner == 0);
+ mutex->__data.__count = 1;
+ }
+ break;
+
+ default:
+ /* Correct code cannot set any other type. */
+ return EINVAL;
+ }
+
+ /* Record the ownership. */
+ mutex->__data.__owner = id;
+#ifndef NO_INCR
+ ++mutex->__data.__nusers;
+#endif
+
+ return retval;
+}
+#ifndef __pthread_mutex_lock
+strong_alias (__pthread_mutex_lock, pthread_mutex_lock)
+strong_alias (__pthread_mutex_lock, __pthread_mutex_lock_internal)
+#endif
diff --git a/libc/nptl/pthread_mutex_setprioceiling.c b/libc/nptl/pthread_mutex_setprioceiling.c
new file mode 100644
index 000000000..cd13d1c14
--- /dev/null
+++ b/libc/nptl/pthread_mutex_setprioceiling.c
@@ -0,0 +1,116 @@
+/* Set current priority ceiling of pthread_mutex_t.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2006.
+
+ 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 <stdbool.h>
+#include <errno.h>
+#include <pthreadP.h>
+
+
+int
+pthread_mutex_setprioceiling (mutex, prioceiling, old_ceiling)
+ pthread_mutex_t *mutex;
+ int prioceiling;
+ int *old_ceiling;
+{
+ /* The low bits of __kind aren't ever changed after pthread_mutex_init,
+ so we don't need a lock yet. */
+ if ((mutex->__data.__kind & PTHREAD_MUTEX_PRIO_PROTECT_NP) == 0)
+ return EINVAL;
+
+ if (__sched_fifo_min_prio == -1)
+ __init_sched_fifo_prio ();
+
+ if (__builtin_expect (prioceiling < __sched_fifo_min_prio, 0)
+ || __builtin_expect (prioceiling > __sched_fifo_max_prio, 0)
+ || __builtin_expect ((prioceiling
+ & (PTHREAD_MUTEXATTR_PRIO_CEILING_MASK
+ >> PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT))
+ != prioceiling, 0))
+ return EINVAL;
+
+ /* Check whether we already hold the mutex. */
+ bool locked = false;
+ if (mutex->__data.__owner == THREAD_GETMEM (THREAD_SELF, tid))
+ {
+ if (mutex->__data.__kind == PTHREAD_MUTEX_PP_ERRORCHECK_NP)
+ return EDEADLK;
+
+ if (mutex->__data.__kind == PTHREAD_MUTEX_PP_RECURSIVE_NP)
+ locked = true;
+ }
+
+ int oldval = mutex->__data.__lock;
+ if (! locked)
+ do
+ {
+ /* Need to lock the mutex, but without obeying the priority
+ protect protocol. */
+ int ceilval = (oldval & PTHREAD_MUTEX_PRIO_CEILING_MASK);
+
+ oldval = atomic_compare_and_exchange_val_acq (&mutex->__data.__lock,
+ ceilval | 1, ceilval);
+ if (oldval == ceilval)
+ break;
+
+ do
+ {
+ oldval
+ = atomic_compare_and_exchange_val_acq (&mutex->__data.__lock,
+ ceilval | 2,
+ ceilval | 1);
+
+ if ((oldval & PTHREAD_MUTEX_PRIO_CEILING_MASK) != ceilval)
+ break;
+
+ if (oldval != ceilval)
+ lll_futex_wait (&mutex->__data.__lock, ceilval | 2);
+ }
+ while (atomic_compare_and_exchange_val_acq (&mutex->__data.__lock,
+ ceilval | 2, ceilval)
+ != ceilval);
+
+ if ((oldval & PTHREAD_MUTEX_PRIO_CEILING_MASK) != ceilval)
+ continue;
+ }
+ while (0);
+
+ int oldprio = (oldval & PTHREAD_MUTEX_PRIO_CEILING_MASK)
+ >> PTHREAD_MUTEX_PRIO_CEILING_SHIFT;
+ if (locked)
+ {
+ int ret = __pthread_tpp_change_priority (oldprio, prioceiling);
+ if (ret)
+ return ret;
+ }
+
+ if (old_ceiling != NULL)
+ *old_ceiling = oldprio;
+
+ int newlock = 0;
+ if (locked)
+ newlock = (mutex->__data.__lock & ~PTHREAD_MUTEX_PRIO_CEILING_MASK);
+ mutex->__data.__lock = newlock
+ | (prioceiling << PTHREAD_MUTEX_PRIO_CEILING_SHIFT);
+ atomic_full_barrier ();
+
+ lll_futex_wake (&mutex->__data.__lock, INT_MAX);
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_mutex_timedlock.c b/libc/nptl/pthread_mutex_timedlock.c
new file mode 100644
index 000000000..c8e6b8507
--- /dev/null
+++ b/libc/nptl/pthread_mutex_timedlock.c
@@ -0,0 +1,470 @@
+/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include <errno.h>
+#include <time.h>
+#include "pthreadP.h"
+#include <lowlevellock.h>
+#include <not-cancel.h>
+
+
+int
+pthread_mutex_timedlock (mutex, abstime)
+ pthread_mutex_t *mutex;
+ const struct timespec *abstime;
+{
+ int oldval;
+ pid_t id = THREAD_GETMEM (THREAD_SELF, tid);
+ int result = 0;
+
+ /* We must not check ABSTIME here. If the thread does not block
+ abstime must not be checked for a valid value. */
+
+ switch (__builtin_expect (mutex->__data.__kind, PTHREAD_MUTEX_TIMED_NP))
+ {
+ /* Recursive mutex. */
+ case PTHREAD_MUTEX_RECURSIVE_NP:
+ /* Check whether we already hold the mutex. */
+ if (mutex->__data.__owner == id)
+ {
+ /* Just bump the counter. */
+ if (__builtin_expect (mutex->__data.__count + 1 == 0, 0))
+ /* Overflow of the counter. */
+ return EAGAIN;
+
+ ++mutex->__data.__count;
+
+ goto out;
+ }
+
+ /* We have to get the mutex. */
+ result = lll_mutex_timedlock (mutex->__data.__lock, abstime);
+
+ if (result != 0)
+ goto out;
+
+ /* Only locked once so far. */
+ mutex->__data.__count = 1;
+ break;
+
+ /* Error checking mutex. */
+ case PTHREAD_MUTEX_ERRORCHECK_NP:
+ /* Check whether we already hold the mutex. */
+ if (__builtin_expect (mutex->__data.__owner == id, 0))
+ return EDEADLK;
+
+ /* FALLTHROUGH */
+
+ case PTHREAD_MUTEX_TIMED_NP:
+ simple:
+ /* Normal mutex. */
+ result = lll_mutex_timedlock (mutex->__data.__lock, abstime);
+ break;
+
+ case PTHREAD_MUTEX_ADAPTIVE_NP:
+ if (! __is_smp)
+ goto simple;
+
+ if (lll_mutex_trylock (mutex->__data.__lock) != 0)
+ {
+ int cnt = 0;
+ int max_cnt = MIN (MAX_ADAPTIVE_COUNT,
+ mutex->__data.__spins * 2 + 10);
+ do
+ {
+ if (cnt++ >= max_cnt)
+ {
+ result = lll_mutex_timedlock (mutex->__data.__lock, abstime);
+ break;
+ }
+
+#ifdef BUSY_WAIT_NOP
+ BUSY_WAIT_NOP;
+#endif
+ }
+ while (lll_mutex_trylock (mutex->__data.__lock) != 0);
+
+ mutex->__data.__spins += (cnt - mutex->__data.__spins) / 8;
+ }
+ break;
+
+ case PTHREAD_MUTEX_ROBUST_RECURSIVE_NP:
+ case PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP:
+ case PTHREAD_MUTEX_ROBUST_NORMAL_NP:
+ case PTHREAD_MUTEX_ROBUST_ADAPTIVE_NP:
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending,
+ &mutex->__data.__list.__next);
+
+ oldval = mutex->__data.__lock;
+ do
+ {
+ again:
+ if ((oldval & FUTEX_OWNER_DIED) != 0)
+ {
+ /* The previous owner died. Try locking the mutex. */
+ int newval
+ = atomic_compare_and_exchange_val_acq (&mutex->__data.__lock,
+ id, oldval);
+ if (newval != oldval)
+ {
+ oldval = newval;
+ goto again;
+ }
+
+ /* We got the mutex. */
+ mutex->__data.__count = 1;
+ /* But it is inconsistent unless marked otherwise. */
+ mutex->__data.__owner = PTHREAD_MUTEX_INCONSISTENT;
+
+ ENQUEUE_MUTEX (mutex);
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+
+ /* Note that we deliberately exit here. If we fall
+ through to the end of the function __nusers would be
+ incremented which is not correct because the old
+ owner has to be discounted. */
+ return EOWNERDEAD;
+ }
+
+ /* Check whether we already hold the mutex. */
+ if (__builtin_expect ((oldval & FUTEX_TID_MASK) == id, 0))
+ {
+ if (mutex->__data.__kind
+ == PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP)
+ {
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending,
+ NULL);
+ return EDEADLK;
+ }
+
+ if (mutex->__data.__kind
+ == PTHREAD_MUTEX_ROBUST_RECURSIVE_NP)
+ {
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending,
+ NULL);
+
+ /* Just bump the counter. */
+ if (__builtin_expect (mutex->__data.__count + 1 == 0, 0))
+ /* Overflow of the counter. */
+ return EAGAIN;
+
+ ++mutex->__data.__count;
+
+ return 0;
+ }
+ }
+
+ result = lll_robust_mutex_timedlock (mutex->__data.__lock, abstime,
+ id);
+
+ if (__builtin_expect (mutex->__data.__owner
+ == PTHREAD_MUTEX_NOTRECOVERABLE, 0))
+ {
+ /* This mutex is now not recoverable. */
+ mutex->__data.__count = 0;
+ lll_mutex_unlock (mutex->__data.__lock);
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+ return ENOTRECOVERABLE;
+ }
+
+ if (result == ETIMEDOUT || result == EINVAL)
+ goto out;
+
+ oldval = result;
+ }
+ while ((oldval & FUTEX_OWNER_DIED) != 0);
+
+ mutex->__data.__count = 1;
+ ENQUEUE_MUTEX (mutex);
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+ break;
+
+ case PTHREAD_MUTEX_PI_RECURSIVE_NP:
+ case PTHREAD_MUTEX_PI_ERRORCHECK_NP:
+ case PTHREAD_MUTEX_PI_NORMAL_NP:
+ case PTHREAD_MUTEX_PI_ADAPTIVE_NP:
+ case PTHREAD_MUTEX_PI_ROBUST_RECURSIVE_NP:
+ case PTHREAD_MUTEX_PI_ROBUST_ERRORCHECK_NP:
+ case PTHREAD_MUTEX_PI_ROBUST_NORMAL_NP:
+ case PTHREAD_MUTEX_PI_ROBUST_ADAPTIVE_NP:
+ {
+ int kind = mutex->__data.__kind & PTHREAD_MUTEX_KIND_MASK_NP;
+ int robust = mutex->__data.__kind & PTHREAD_MUTEX_ROBUST_NORMAL_NP;
+
+ if (robust)
+ /* Note: robust PI futexes are signaled by setting bit 0. */
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending,
+ (void *) (((uintptr_t) &mutex->__data.__list.__next)
+ | 1));
+
+ oldval = mutex->__data.__lock;
+
+ /* Check whether we already hold the mutex. */
+ if (__builtin_expect ((oldval & FUTEX_TID_MASK) == id, 0))
+ {
+ if (kind == PTHREAD_MUTEX_ERRORCHECK_NP)
+ {
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+ return EDEADLK;
+ }
+
+ if (kind == PTHREAD_MUTEX_RECURSIVE_NP)
+ {
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+
+ /* Just bump the counter. */
+ if (__builtin_expect (mutex->__data.__count + 1 == 0, 0))
+ /* Overflow of the counter. */
+ return EAGAIN;
+
+ ++mutex->__data.__count;
+
+ return 0;
+ }
+ }
+
+ oldval = atomic_compare_and_exchange_val_acq (&mutex->__data.__lock,
+ id, 0);
+
+ if (oldval != 0)
+ {
+ /* The mutex is locked. The kernel will now take care of
+ everything. The timeout value must be a relative value.
+ Convert it. */
+ INTERNAL_SYSCALL_DECL (__err);
+
+ int e = INTERNAL_SYSCALL (futex, __err, 4, &mutex->__data.__lock,
+ FUTEX_LOCK_PI, 1, abstime);
+ if (INTERNAL_SYSCALL_ERROR_P (e, __err))
+ {
+ if (INTERNAL_SYSCALL_ERRNO (e, __err) == ETIMEDOUT)
+ return ETIMEDOUT;
+
+ if (INTERNAL_SYSCALL_ERRNO (e, __err) == ESRCH
+ || INTERNAL_SYSCALL_ERRNO (e, __err) == EDEADLK)
+ {
+ assert (INTERNAL_SYSCALL_ERRNO (e, __err) != EDEADLK
+ || (kind != PTHREAD_MUTEX_ERRORCHECK_NP
+ && kind != PTHREAD_MUTEX_RECURSIVE_NP));
+ /* ESRCH can happen only for non-robust PI mutexes where
+ the owner of the lock died. */
+ assert (INTERNAL_SYSCALL_ERRNO (e, __err) != ESRCH
+ || !robust);
+
+ /* Delay the thread until the timeout is reached.
+ Then return ETIMEDOUT. */
+ struct timespec reltime;
+ struct timespec now;
+
+ INTERNAL_SYSCALL (clock_gettime, __err, 2, CLOCK_REALTIME,
+ &now);
+ reltime.tv_sec = abstime->tv_sec - now.tv_sec;
+ reltime.tv_nsec = abstime->tv_nsec - now.tv_nsec;
+ if (reltime.tv_nsec < 0)
+ {
+ reltime.tv_nsec += 1000000000;
+ --reltime.tv_sec;
+ }
+ if (reltime.tv_sec >= 0)
+ while (nanosleep_not_cancel (&reltime, &reltime) != 0)
+ continue;
+
+ return ETIMEDOUT;
+ }
+
+ return INTERNAL_SYSCALL_ERRNO (e, __err);
+ }
+
+ oldval = mutex->__data.__lock;
+
+ assert (robust || (oldval & FUTEX_OWNER_DIED) == 0);
+ }
+
+ if (__builtin_expect (oldval & FUTEX_OWNER_DIED, 0))
+ {
+ atomic_and (&mutex->__data.__lock, ~FUTEX_OWNER_DIED);
+
+ /* We got the mutex. */
+ mutex->__data.__count = 1;
+ /* But it is inconsistent unless marked otherwise. */
+ mutex->__data.__owner = PTHREAD_MUTEX_INCONSISTENT;
+
+ ENQUEUE_MUTEX_PI (mutex);
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+
+ /* Note that we deliberately exit here. If we fall
+ through to the end of the function __nusers would be
+ incremented which is not correct because the old owner
+ has to be discounted. */
+ return EOWNERDEAD;
+ }
+
+ if (robust
+ && __builtin_expect (mutex->__data.__owner
+ == PTHREAD_MUTEX_NOTRECOVERABLE, 0))
+ {
+ /* This mutex is now not recoverable. */
+ mutex->__data.__count = 0;
+
+ INTERNAL_SYSCALL_DECL (__err);
+ INTERNAL_SYSCALL (futex, __err, 4, &mutex->__data.__lock,
+ FUTEX_UNLOCK_PI, 0, 0);
+
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+ return ENOTRECOVERABLE;
+ }
+
+ mutex->__data.__count = 1;
+ if (robust)
+ {
+ ENQUEUE_MUTEX_PI (mutex);
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+ }
+ }
+ break;
+
+ case PTHREAD_MUTEX_PP_RECURSIVE_NP:
+ case PTHREAD_MUTEX_PP_ERRORCHECK_NP:
+ case PTHREAD_MUTEX_PP_NORMAL_NP:
+ case PTHREAD_MUTEX_PP_ADAPTIVE_NP:
+ {
+ int kind = mutex->__data.__kind & PTHREAD_MUTEX_KIND_MASK_NP;
+
+ oldval = mutex->__data.__lock;
+
+ /* Check whether we already hold the mutex. */
+ if (mutex->__data.__owner == id)
+ {
+ if (kind == PTHREAD_MUTEX_ERRORCHECK_NP)
+ return EDEADLK;
+
+ if (kind == PTHREAD_MUTEX_RECURSIVE_NP)
+ {
+ /* Just bump the counter. */
+ if (__builtin_expect (mutex->__data.__count + 1 == 0, 0))
+ /* Overflow of the counter. */
+ return EAGAIN;
+
+ ++mutex->__data.__count;
+
+ return 0;
+ }
+ }
+
+ int oldprio = -1, ceilval;
+ do
+ {
+ int ceiling = (oldval & PTHREAD_MUTEX_PRIO_CEILING_MASK)
+ >> PTHREAD_MUTEX_PRIO_CEILING_SHIFT;
+
+ if (__pthread_current_priority () > ceiling)
+ {
+ result = EINVAL;
+ failpp:
+ if (oldprio != -1)
+ __pthread_tpp_change_priority (oldprio, -1);
+ return result;
+ }
+
+ result = __pthread_tpp_change_priority (oldprio, ceiling);
+ if (result)
+ return result;
+
+ ceilval = ceiling << PTHREAD_MUTEX_PRIO_CEILING_SHIFT;
+ oldprio = ceiling;
+
+ oldval
+ = atomic_compare_and_exchange_val_acq (&mutex->__data.__lock,
+ ceilval | 1, ceilval);
+
+ if (oldval == ceilval)
+ break;
+
+ do
+ {
+ oldval
+ = atomic_compare_and_exchange_val_acq (&mutex->__data.__lock,
+ ceilval | 2,
+ ceilval | 1);
+
+ if ((oldval & PTHREAD_MUTEX_PRIO_CEILING_MASK) != ceilval)
+ break;
+
+ if (oldval != ceilval)
+ {
+ /* Reject invalid timeouts. */
+ if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)
+ {
+ result = EINVAL;
+ goto failpp;
+ }
+
+ struct timeval tv;
+ struct timespec rt;
+
+ /* Get the current time. */
+ (void) __gettimeofday (&tv, NULL);
+
+ /* Compute relative timeout. */
+ rt.tv_sec = abstime->tv_sec - tv.tv_sec;
+ rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
+ if (rt.tv_nsec < 0)
+ {
+ rt.tv_nsec += 1000000000;
+ --rt.tv_sec;
+ }
+
+ /* Already timed out? */
+ if (rt.tv_sec < 0)
+ {
+ result = ETIMEDOUT;
+ goto failpp;
+ }
+
+ lll_futex_timed_wait (&mutex->__data.__lock,
+ ceilval | 2, &rt);
+ }
+ }
+ while (atomic_compare_and_exchange_val_acq (&mutex->__data.__lock,
+ ceilval | 2, ceilval)
+ != ceilval);
+ }
+ while ((oldval & PTHREAD_MUTEX_PRIO_CEILING_MASK) != ceilval);
+
+ assert (mutex->__data.__owner == 0);
+ mutex->__data.__count = 1;
+ }
+ break;
+
+ default:
+ /* Correct code cannot set any other type. */
+ return EINVAL;
+ }
+
+ if (result == 0)
+ {
+ /* Record the ownership. */
+ mutex->__data.__owner = id;
+ ++mutex->__data.__nusers;
+ }
+
+ out:
+ return result;
+}
diff --git a/libc/nptl/pthread_mutex_trylock.c b/libc/nptl/pthread_mutex_trylock.c
new file mode 100644
index 000000000..94d519233
--- /dev/null
+++ b/libc/nptl/pthread_mutex_trylock.c
@@ -0,0 +1,380 @@
+/* Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include <errno.h>
+#include <stdlib.h>
+#include "pthreadP.h"
+#include <lowlevellock.h>
+
+
+int
+__pthread_mutex_trylock (mutex)
+ pthread_mutex_t *mutex;
+{
+ int oldval;
+ pid_t id = THREAD_GETMEM (THREAD_SELF, tid);
+
+ switch (__builtin_expect (mutex->__data.__kind, PTHREAD_MUTEX_TIMED_NP))
+ {
+ /* Recursive mutex. */
+ case PTHREAD_MUTEX_RECURSIVE_NP:
+ /* Check whether we already hold the mutex. */
+ if (mutex->__data.__owner == id)
+ {
+ /* Just bump the counter. */
+ if (__builtin_expect (mutex->__data.__count + 1 == 0, 0))
+ /* Overflow of the counter. */
+ return EAGAIN;
+
+ ++mutex->__data.__count;
+ return 0;
+ }
+
+ if (lll_mutex_trylock (mutex->__data.__lock) == 0)
+ {
+ /* Record the ownership. */
+ mutex->__data.__owner = id;
+ mutex->__data.__count = 1;
+ ++mutex->__data.__nusers;
+ return 0;
+ }
+ break;
+
+ case PTHREAD_MUTEX_ERRORCHECK_NP:
+ /* Check whether we already hold the mutex. */
+ if (__builtin_expect (mutex->__data.__owner == id, 0))
+ return EDEADLK;
+
+ /* FALLTHROUGH */
+
+ case PTHREAD_MUTEX_TIMED_NP:
+ case PTHREAD_MUTEX_ADAPTIVE_NP:
+ /* Normal mutex. */
+ if (lll_mutex_trylock (mutex->__data.__lock) != 0)
+ break;
+
+ /* Record the ownership. */
+ mutex->__data.__owner = id;
+ ++mutex->__data.__nusers;
+
+ return 0;
+
+
+ case PTHREAD_MUTEX_ROBUST_RECURSIVE_NP:
+ case PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP:
+ case PTHREAD_MUTEX_ROBUST_NORMAL_NP:
+ case PTHREAD_MUTEX_ROBUST_ADAPTIVE_NP:
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending,
+ &mutex->__data.__list.__next);
+
+ oldval = mutex->__data.__lock;
+ do
+ {
+ again:
+ if ((oldval & FUTEX_OWNER_DIED) != 0)
+ {
+ /* The previous owner died. Try locking the mutex. */
+ int newval
+ = atomic_compare_and_exchange_val_acq (&mutex->__data.__lock,
+ id, oldval);
+
+ if (newval != oldval)
+ {
+ oldval = newval;
+ goto again;
+ }
+
+ /* We got the mutex. */
+ mutex->__data.__count = 1;
+ /* But it is inconsistent unless marked otherwise. */
+ mutex->__data.__owner = PTHREAD_MUTEX_INCONSISTENT;
+
+ ENQUEUE_MUTEX (mutex);
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+
+ /* Note that we deliberately exist here. If we fall
+ through to the end of the function __nusers would be
+ incremented which is not correct because the old
+ owner has to be discounted. */
+ return EOWNERDEAD;
+ }
+
+ /* Check whether we already hold the mutex. */
+ if (__builtin_expect ((oldval & FUTEX_TID_MASK) == id, 0))
+ {
+ if (mutex->__data.__kind
+ == PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP)
+ {
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending,
+ NULL);
+ return EDEADLK;
+ }
+
+ if (mutex->__data.__kind
+ == PTHREAD_MUTEX_ROBUST_RECURSIVE_NP)
+ {
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending,
+ NULL);
+
+ /* Just bump the counter. */
+ if (__builtin_expect (mutex->__data.__count + 1 == 0, 0))
+ /* Overflow of the counter. */
+ return EAGAIN;
+
+ ++mutex->__data.__count;
+
+ return 0;
+ }
+ }
+
+ oldval = lll_robust_mutex_trylock (mutex->__data.__lock, id);
+ if (oldval != 0 && (oldval & FUTEX_OWNER_DIED) == 0)
+ {
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+
+ return EBUSY;
+ }
+
+ if (__builtin_expect (mutex->__data.__owner
+ == PTHREAD_MUTEX_NOTRECOVERABLE, 0))
+ {
+ /* This mutex is now not recoverable. */
+ mutex->__data.__count = 0;
+ if (oldval == id)
+ lll_mutex_unlock (mutex->__data.__lock);
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+ return ENOTRECOVERABLE;
+ }
+ }
+ while ((oldval & FUTEX_OWNER_DIED) != 0);
+
+ ENQUEUE_MUTEX (mutex);
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+
+ mutex->__data.__owner = id;
+ ++mutex->__data.__nusers;
+ mutex->__data.__count = 1;
+
+ return 0;
+
+ case PTHREAD_MUTEX_PI_RECURSIVE_NP:
+ case PTHREAD_MUTEX_PI_ERRORCHECK_NP:
+ case PTHREAD_MUTEX_PI_NORMAL_NP:
+ case PTHREAD_MUTEX_PI_ADAPTIVE_NP:
+ case PTHREAD_MUTEX_PI_ROBUST_RECURSIVE_NP:
+ case PTHREAD_MUTEX_PI_ROBUST_ERRORCHECK_NP:
+ case PTHREAD_MUTEX_PI_ROBUST_NORMAL_NP:
+ case PTHREAD_MUTEX_PI_ROBUST_ADAPTIVE_NP:
+ {
+ int kind = mutex->__data.__kind & PTHREAD_MUTEX_KIND_MASK_NP;
+ int robust = mutex->__data.__kind & PTHREAD_MUTEX_ROBUST_NORMAL_NP;
+
+ if (robust)
+ /* Note: robust PI futexes are signaled by setting bit 0. */
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending,
+ (void *) (((uintptr_t) &mutex->__data.__list.__next)
+ | 1));
+
+ oldval = mutex->__data.__lock;
+
+ /* Check whether we already hold the mutex. */
+ if (__builtin_expect ((oldval & FUTEX_TID_MASK) == id, 0))
+ {
+ if (kind == PTHREAD_MUTEX_ERRORCHECK_NP)
+ {
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+ return EDEADLK;
+ }
+
+ if (kind == PTHREAD_MUTEX_RECURSIVE_NP)
+ {
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+
+ /* Just bump the counter. */
+ if (__builtin_expect (mutex->__data.__count + 1 == 0, 0))
+ /* Overflow of the counter. */
+ return EAGAIN;
+
+ ++mutex->__data.__count;
+
+ return 0;
+ }
+ }
+
+ oldval
+ = atomic_compare_and_exchange_val_acq (&mutex->__data.__lock,
+ id, 0);
+
+ if (oldval != 0)
+ {
+ if ((oldval & FUTEX_OWNER_DIED) == 0)
+ {
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+
+ return EBUSY;
+ }
+
+ assert (robust);
+
+ /* The mutex owner died. The kernel will now take care of
+ everything. */
+ INTERNAL_SYSCALL_DECL (__err);
+ int e = INTERNAL_SYSCALL (futex, __err, 4, &mutex->__data.__lock,
+ FUTEX_TRYLOCK_PI, 0, 0);
+
+ if (INTERNAL_SYSCALL_ERROR_P (e, __err)
+ && INTERNAL_SYSCALL_ERRNO (e, __err) == EWOULDBLOCK)
+ {
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+
+ return EBUSY;
+ }
+
+ oldval = mutex->__data.__lock;
+ }
+
+ if (__builtin_expect (oldval & FUTEX_OWNER_DIED, 0))
+ {
+ atomic_and (&mutex->__data.__lock, ~FUTEX_OWNER_DIED);
+
+ /* We got the mutex. */
+ mutex->__data.__count = 1;
+ /* But it is inconsistent unless marked otherwise. */
+ mutex->__data.__owner = PTHREAD_MUTEX_INCONSISTENT;
+
+ ENQUEUE_MUTEX (mutex);
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+
+ /* Note that we deliberately exit here. If we fall
+ through to the end of the function __nusers would be
+ incremented which is not correct because the old owner
+ has to be discounted. */
+ return EOWNERDEAD;
+ }
+
+ if (robust
+ && __builtin_expect (mutex->__data.__owner
+ == PTHREAD_MUTEX_NOTRECOVERABLE, 0))
+ {
+ /* This mutex is now not recoverable. */
+ mutex->__data.__count = 0;
+
+ INTERNAL_SYSCALL_DECL (__err);
+ INTERNAL_SYSCALL (futex, __err, 4, &mutex->__data.__lock,
+ FUTEX_UNLOCK_PI, 0, 0);
+
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+ return ENOTRECOVERABLE;
+ }
+
+ if (robust)
+ {
+ ENQUEUE_MUTEX_PI (mutex);
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+ }
+
+ mutex->__data.__owner = id;
+ ++mutex->__data.__nusers;
+ mutex->__data.__count = 1;
+
+ return 0;
+ }
+
+ case PTHREAD_MUTEX_PP_RECURSIVE_NP:
+ case PTHREAD_MUTEX_PP_ERRORCHECK_NP:
+ case PTHREAD_MUTEX_PP_NORMAL_NP:
+ case PTHREAD_MUTEX_PP_ADAPTIVE_NP:
+ {
+ int kind = mutex->__data.__kind & PTHREAD_MUTEX_KIND_MASK_NP;
+
+ oldval = mutex->__data.__lock;
+
+ /* Check whether we already hold the mutex. */
+ if (mutex->__data.__owner == id)
+ {
+ if (kind == PTHREAD_MUTEX_ERRORCHECK_NP)
+ return EDEADLK;
+
+ if (kind == PTHREAD_MUTEX_RECURSIVE_NP)
+ {
+ /* Just bump the counter. */
+ if (__builtin_expect (mutex->__data.__count + 1 == 0, 0))
+ /* Overflow of the counter. */
+ return EAGAIN;
+
+ ++mutex->__data.__count;
+
+ return 0;
+ }
+ }
+
+ int oldprio = -1, ceilval;
+ do
+ {
+ int ceiling = (oldval & PTHREAD_MUTEX_PRIO_CEILING_MASK)
+ >> PTHREAD_MUTEX_PRIO_CEILING_SHIFT;
+
+ if (__pthread_current_priority () > ceiling)
+ {
+ if (oldprio != -1)
+ __pthread_tpp_change_priority (oldprio, -1);
+ return EINVAL;
+ }
+
+ int retval = __pthread_tpp_change_priority (oldprio, ceiling);
+ if (retval)
+ return retval;
+
+ ceilval = ceiling << PTHREAD_MUTEX_PRIO_CEILING_SHIFT;
+ oldprio = ceiling;
+
+ oldval
+ = atomic_compare_and_exchange_val_acq (&mutex->__data.__lock,
+ ceilval | 1, ceilval);
+
+ if (oldval == ceilval)
+ break;
+ }
+ while ((oldval & PTHREAD_MUTEX_PRIO_CEILING_MASK) != ceilval);
+
+ if (oldval != ceilval)
+ {
+ __pthread_tpp_change_priority (oldprio, -1);
+ break;
+ }
+
+ assert (mutex->__data.__owner == 0);
+ /* Record the ownership. */
+ mutex->__data.__owner = id;
+ ++mutex->__data.__nusers;
+ mutex->__data.__count = 1;
+
+ return 0;
+ }
+ break;
+
+ default:
+ /* Correct code cannot set any other type. */
+ return EINVAL;
+ }
+
+ return EBUSY;
+}
+strong_alias (__pthread_mutex_trylock, pthread_mutex_trylock)
diff --git a/libc/nptl/pthread_mutex_unlock.c b/libc/nptl/pthread_mutex_unlock.c
new file mode 100644
index 000000000..33919d60a
--- /dev/null
+++ b/libc/nptl/pthread_mutex_unlock.c
@@ -0,0 +1,264 @@
+/* Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <stdlib.h>
+#include "pthreadP.h"
+#include <lowlevellock.h>
+
+
+int
+internal_function attribute_hidden
+__pthread_mutex_unlock_usercnt (mutex, decr)
+ pthread_mutex_t *mutex;
+ int decr;
+{
+ int newowner = 0;
+
+ switch (__builtin_expect (mutex->__data.__kind, PTHREAD_MUTEX_TIMED_NP))
+ {
+ case PTHREAD_MUTEX_RECURSIVE_NP:
+ /* Recursive mutex. */
+ if (mutex->__data.__owner != THREAD_GETMEM (THREAD_SELF, tid))
+ return EPERM;
+
+ if (--mutex->__data.__count != 0)
+ /* We still hold the mutex. */
+ return 0;
+ goto normal;
+
+ case PTHREAD_MUTEX_ERRORCHECK_NP:
+ /* Error checking mutex. */
+ if (mutex->__data.__owner != THREAD_GETMEM (THREAD_SELF, tid)
+ || ! lll_mutex_islocked (mutex->__data.__lock))
+ return EPERM;
+ /* FALLTHROUGH */
+
+ case PTHREAD_MUTEX_TIMED_NP:
+ case PTHREAD_MUTEX_ADAPTIVE_NP:
+ /* Always reset the owner field. */
+ normal:
+ mutex->__data.__owner = 0;
+ if (decr)
+ /* One less user. */
+ --mutex->__data.__nusers;
+
+ /* Unlock. */
+ lll_mutex_unlock (mutex->__data.__lock);
+ break;
+
+ case PTHREAD_MUTEX_ROBUST_RECURSIVE_NP:
+ /* Recursive mutex. */
+ if ((mutex->__data.__lock & FUTEX_TID_MASK)
+ == THREAD_GETMEM (THREAD_SELF, tid)
+ && __builtin_expect (mutex->__data.__owner
+ == PTHREAD_MUTEX_INCONSISTENT, 0))
+ {
+ if (--mutex->__data.__count != 0)
+ /* We still hold the mutex. */
+ return ENOTRECOVERABLE;
+
+ goto notrecoverable;
+ }
+
+ if (mutex->__data.__owner != THREAD_GETMEM (THREAD_SELF, tid))
+ return EPERM;
+
+ if (--mutex->__data.__count != 0)
+ /* We still hold the mutex. */
+ return 0;
+
+ goto robust;
+
+ case PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP:
+ case PTHREAD_MUTEX_ROBUST_NORMAL_NP:
+ case PTHREAD_MUTEX_ROBUST_ADAPTIVE_NP:
+ if ((mutex->__data.__lock & FUTEX_TID_MASK)
+ != THREAD_GETMEM (THREAD_SELF, tid)
+ || ! lll_mutex_islocked (mutex->__data.__lock))
+ return EPERM;
+
+ /* If the previous owner died and the caller did not succeed in
+ making the state consistent, mark the mutex as unrecoverable
+ and make all waiters. */
+ if (__builtin_expect (mutex->__data.__owner
+ == PTHREAD_MUTEX_INCONSISTENT, 0))
+ notrecoverable:
+ newowner = PTHREAD_MUTEX_NOTRECOVERABLE;
+
+ robust:
+ /* Remove mutex from the list. */
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending,
+ &mutex->__data.__list.__next);
+ DEQUEUE_MUTEX (mutex);
+
+ mutex->__data.__owner = newowner;
+ if (decr)
+ /* One less user. */
+ --mutex->__data.__nusers;
+
+ /* Unlock. */
+ lll_robust_mutex_unlock (mutex->__data.__lock);
+
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+ break;
+
+ case PTHREAD_MUTEX_PI_RECURSIVE_NP:
+ /* Recursive mutex. */
+ if (mutex->__data.__owner != THREAD_GETMEM (THREAD_SELF, tid))
+ return EPERM;
+
+ if (--mutex->__data.__count != 0)
+ /* We still hold the mutex. */
+ return 0;
+ goto continue_pi;
+
+ case PTHREAD_MUTEX_PI_ROBUST_RECURSIVE_NP:
+ /* Recursive mutex. */
+ if ((mutex->__data.__lock & FUTEX_TID_MASK)
+ == THREAD_GETMEM (THREAD_SELF, tid)
+ && __builtin_expect (mutex->__data.__owner
+ == PTHREAD_MUTEX_INCONSISTENT, 0))
+ {
+ if (--mutex->__data.__count != 0)
+ /* We still hold the mutex. */
+ return ENOTRECOVERABLE;
+
+ goto pi_notrecoverable;
+ }
+
+ if (mutex->__data.__owner != THREAD_GETMEM (THREAD_SELF, tid))
+ return EPERM;
+
+ if (--mutex->__data.__count != 0)
+ /* We still hold the mutex. */
+ return 0;
+
+ goto continue_pi;
+
+ case PTHREAD_MUTEX_PI_ERRORCHECK_NP:
+ case PTHREAD_MUTEX_PI_NORMAL_NP:
+ case PTHREAD_MUTEX_PI_ADAPTIVE_NP:
+ case PTHREAD_MUTEX_PI_ROBUST_ERRORCHECK_NP:
+ case PTHREAD_MUTEX_PI_ROBUST_NORMAL_NP:
+ case PTHREAD_MUTEX_PI_ROBUST_ADAPTIVE_NP:
+ if ((mutex->__data.__lock & FUTEX_TID_MASK)
+ != THREAD_GETMEM (THREAD_SELF, tid)
+ || ! lll_mutex_islocked (mutex->__data.__lock))
+ return EPERM;
+
+ /* If the previous owner died and the caller did not succeed in
+ making the state consistent, mark the mutex as unrecoverable
+ and make all waiters. */
+ if ((mutex->__data.__kind & PTHREAD_MUTEX_ROBUST_NORMAL_NP) != 0
+ && __builtin_expect (mutex->__data.__owner
+ == PTHREAD_MUTEX_INCONSISTENT, 0))
+ pi_notrecoverable:
+ newowner = PTHREAD_MUTEX_NOTRECOVERABLE;
+
+ continue_pi:
+ if ((mutex->__data.__kind & PTHREAD_MUTEX_ROBUST_NORMAL_NP) != 0)
+ {
+ /* Remove mutex from the list.
+ Note: robust PI futexes are signaled by setting bit 0. */
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending,
+ (void *) (((uintptr_t) &mutex->__data.__list.__next)
+ | 1));
+ DEQUEUE_MUTEX (mutex);
+ }
+
+ mutex->__data.__owner = newowner;
+ if (decr)
+ /* One less user. */
+ --mutex->__data.__nusers;
+
+ /* Unlock. */
+ if ((mutex->__data.__lock & FUTEX_WAITERS) != 0
+ || atomic_compare_and_exchange_bool_acq (&mutex->__data.__lock, 0,
+ THREAD_GETMEM (THREAD_SELF,
+ tid)))
+ {
+ INTERNAL_SYSCALL_DECL (__err);
+ INTERNAL_SYSCALL (futex, __err, 2, &mutex->__data.__lock,
+ FUTEX_UNLOCK_PI);
+ }
+
+ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
+ break;
+
+ case PTHREAD_MUTEX_PP_RECURSIVE_NP:
+ /* Recursive mutex. */
+ if (mutex->__data.__owner != THREAD_GETMEM (THREAD_SELF, tid))
+ return EPERM;
+
+ if (--mutex->__data.__count != 0)
+ /* We still hold the mutex. */
+ return 0;
+ goto pp;
+
+ case PTHREAD_MUTEX_PP_ERRORCHECK_NP:
+ /* Error checking mutex. */
+ if (mutex->__data.__owner != THREAD_GETMEM (THREAD_SELF, tid)
+ || (mutex->__data.__lock & ~ PTHREAD_MUTEX_PRIO_CEILING_MASK) == 0)
+ return EPERM;
+ /* FALLTHROUGH */
+
+ case PTHREAD_MUTEX_PP_NORMAL_NP:
+ case PTHREAD_MUTEX_PP_ADAPTIVE_NP:
+ /* Always reset the owner field. */
+ pp:
+ mutex->__data.__owner = 0;
+
+ if (decr)
+ /* One less user. */
+ --mutex->__data.__nusers;
+
+ /* Unlock. */
+ int newval, oldval;
+ do
+ {
+ oldval = mutex->__data.__lock;
+ newval = oldval & PTHREAD_MUTEX_PRIO_CEILING_MASK;
+ }
+ while (atomic_compare_and_exchange_bool_acq (&mutex->__data.__lock,
+ newval, oldval));
+
+ if ((oldval & ~PTHREAD_MUTEX_PRIO_CEILING_MASK) > 1)
+ lll_futex_wake (&mutex->__data.__lock, 1);
+
+ int oldprio = newval >> PTHREAD_MUTEX_PRIO_CEILING_SHIFT;
+ return __pthread_tpp_change_priority (oldprio, -1);
+
+ default:
+ /* Correct code cannot set any other type. */
+ return EINVAL;
+ }
+
+ return 0;
+}
+
+
+int
+__pthread_mutex_unlock (mutex)
+ pthread_mutex_t *mutex;
+{
+ return __pthread_mutex_unlock_usercnt (mutex, 1);
+}
+strong_alias (__pthread_mutex_unlock, pthread_mutex_unlock)
+strong_alias (__pthread_mutex_unlock, __pthread_mutex_unlock_internal)
diff --git a/libc/nptl/pthread_mutexattr_destroy.c b/libc/nptl/pthread_mutexattr_destroy.c
new file mode 100644
index 000000000..eab27d351
--- /dev/null
+++ b/libc/nptl/pthread_mutexattr_destroy.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <pthreadP.h>
+
+
+int
+__pthread_mutexattr_destroy (attr)
+ pthread_mutexattr_t *attr;
+{
+ return 0;
+}
+strong_alias (__pthread_mutexattr_destroy, pthread_mutexattr_destroy)
diff --git a/libc/nptl/pthread_mutexattr_getprioceiling.c b/libc/nptl/pthread_mutexattr_getprioceiling.c
new file mode 100644
index 000000000..792e9a43d
--- /dev/null
+++ b/libc/nptl/pthread_mutexattr_getprioceiling.c
@@ -0,0 +1,48 @@
+/* Get priority ceiling setting from pthread_mutexattr_t.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2006.
+
+ 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 <pthreadP.h>
+
+
+int
+pthread_mutexattr_getprioceiling (attr, prioceiling)
+ const pthread_mutexattr_t *attr;
+ int *prioceiling;
+{
+ const struct pthread_mutexattr *iattr;
+ int ceiling;
+
+ iattr = (const struct pthread_mutexattr *) attr;
+
+ ceiling = ((iattr->mutexkind & PTHREAD_MUTEXATTR_PRIO_CEILING_MASK)
+ >> PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT);
+
+ if (! ceiling)
+ {
+ if (__sched_fifo_min_prio == -1)
+ __init_sched_fifo_prio ();
+ if (ceiling < __sched_fifo_min_prio)
+ ceiling = __sched_fifo_min_prio;
+ }
+
+ *prioceiling = ceiling;
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_mutexattr_getprotocol.c b/libc/nptl/pthread_mutexattr_getprotocol.c
new file mode 100644
index 000000000..0c28699c8
--- /dev/null
+++ b/libc/nptl/pthread_mutexattr_getprotocol.c
@@ -0,0 +1,37 @@
+/* Get priority protocol setting from pthread_mutexattr_t.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2006.
+
+ 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 <pthreadP.h>
+
+
+int
+pthread_mutexattr_getprotocol (attr, protocol)
+ const pthread_mutexattr_t *attr;
+ int *protocol;
+{
+ const struct pthread_mutexattr *iattr;
+
+ iattr = (const struct pthread_mutexattr *) attr;
+
+ *protocol = ((iattr->mutexkind & PTHREAD_MUTEXATTR_PROTOCOL_MASK)
+ >> PTHREAD_MUTEXATTR_PROTOCOL_SHIFT);
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_mutexattr_getpshared.c b/libc/nptl/pthread_mutexattr_getpshared.c
new file mode 100644
index 000000000..6454125db
--- /dev/null
+++ b/libc/nptl/pthread_mutexattr_getpshared.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <pthreadP.h>
+
+
+int
+pthread_mutexattr_getpshared (attr, pshared)
+ const pthread_mutexattr_t *attr;
+ int *pshared;
+{
+ const struct pthread_mutexattr *iattr;
+
+ iattr = (const struct pthread_mutexattr *) attr;
+
+ *pshared = ((iattr->mutexkind & PTHREAD_MUTEXATTR_FLAG_PSHARED) != 0
+ ? PTHREAD_PROCESS_SHARED : PTHREAD_PROCESS_PRIVATE);
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_mutexattr_getrobust.c b/libc/nptl/pthread_mutexattr_getrobust.c
new file mode 100644
index 000000000..5ec43d1f7
--- /dev/null
+++ b/libc/nptl/pthread_mutexattr_getrobust.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2005.
+
+ 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 <pthreadP.h>
+
+
+int
+pthread_mutexattr_getrobust_np (attr, robustness)
+ const pthread_mutexattr_t *attr;
+ int *robustness;
+{
+ const struct pthread_mutexattr *iattr;
+
+ iattr = (const struct pthread_mutexattr *) attr;
+
+ *robustness = ((iattr->mutexkind & PTHREAD_MUTEXATTR_FLAG_ROBUST) != 0
+ ? PTHREAD_MUTEX_ROBUST_NP : PTHREAD_MUTEX_STALLED_NP);
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_mutexattr_gettype.c b/libc/nptl/pthread_mutexattr_gettype.c
new file mode 100644
index 000000000..7303703bf
--- /dev/null
+++ b/libc/nptl/pthread_mutexattr_gettype.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <pthreadP.h>
+
+
+int
+pthread_mutexattr_gettype (attr, kind)
+ const pthread_mutexattr_t *attr;
+ int *kind;
+{
+ const struct pthread_mutexattr *iattr;
+
+ iattr = (const struct pthread_mutexattr *) attr;
+
+ *kind = iattr->mutexkind & ~PTHREAD_MUTEXATTR_FLAG_BITS;
+
+ return 0;
+}
+weak_alias (pthread_mutexattr_gettype, pthread_mutexattr_getkind_np)
diff --git a/libc/nptl/pthread_mutexattr_init.c b/libc/nptl/pthread_mutexattr_init.c
new file mode 100644
index 000000000..ee026c654
--- /dev/null
+++ b/libc/nptl/pthread_mutexattr_init.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <string.h>
+#include <pthreadP.h>
+
+
+int
+__pthread_mutexattr_init (attr)
+ pthread_mutexattr_t *attr;
+{
+ if (sizeof (struct pthread_mutexattr) != sizeof (pthread_mutexattr_t))
+ memset (attr, '\0', sizeof (*attr));
+
+ /* We use bit 31 to signal whether the mutex is going to be
+ process-shared or not. By default it is zero, i.e., the mutex is
+ not process-shared. */
+ ((struct pthread_mutexattr *) attr)->mutexkind = PTHREAD_MUTEX_NORMAL;
+
+ return 0;
+}
+strong_alias (__pthread_mutexattr_init, pthread_mutexattr_init)
diff --git a/libc/nptl/pthread_mutexattr_setprioceiling.c b/libc/nptl/pthread_mutexattr_setprioceiling.c
new file mode 100644
index 000000000..9b7874f73
--- /dev/null
+++ b/libc/nptl/pthread_mutexattr_setprioceiling.c
@@ -0,0 +1,47 @@
+/* Change priority ceiling setting in pthread_mutexattr_t.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2006.
+
+ 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 <errno.h>
+#include <pthreadP.h>
+
+
+int
+pthread_mutexattr_setprioceiling (attr, prioceiling)
+ pthread_mutexattr_t *attr;
+ int prioceiling;
+{
+ if (__sched_fifo_min_prio == -1)
+ __init_sched_fifo_prio ();
+
+ if (__builtin_expect (prioceiling < __sched_fifo_min_prio, 0)
+ || __builtin_expect (prioceiling > __sched_fifo_max_prio, 0)
+ || __builtin_expect ((prioceiling
+ & (PTHREAD_MUTEXATTR_PRIO_CEILING_MASK
+ >> PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT))
+ != prioceiling, 0))
+ return EINVAL;
+
+ struct pthread_mutexattr *iattr = (struct pthread_mutexattr *) attr;
+
+ iattr->mutexkind = ((iattr->mutexkind & ~PTHREAD_MUTEXATTR_PRIO_CEILING_MASK)
+ | (prioceiling << PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT));
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_mutexattr_setprotocol.c b/libc/nptl/pthread_mutexattr_setprotocol.c
new file mode 100644
index 000000000..191231244
--- /dev/null
+++ b/libc/nptl/pthread_mutexattr_setprotocol.c
@@ -0,0 +1,41 @@
+/* Change priority protocol setting in pthread_mutexattr_t.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2006.
+
+ 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 <errno.h>
+#include <pthreadP.h>
+
+
+int
+pthread_mutexattr_setprotocol (attr, protocol)
+ pthread_mutexattr_t *attr;
+ int protocol;
+{
+ if (protocol != PTHREAD_PRIO_NONE
+ && protocol != PTHREAD_PRIO_INHERIT
+ && __builtin_expect (protocol != PTHREAD_PRIO_PROTECT, 0))
+ return EINVAL;
+
+ struct pthread_mutexattr *iattr = (struct pthread_mutexattr *) attr;
+
+ iattr->mutexkind = ((iattr->mutexkind & ~PTHREAD_MUTEXATTR_PROTOCOL_MASK)
+ | (protocol << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT));
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_mutexattr_setpshared.c b/libc/nptl/pthread_mutexattr_setpshared.c
new file mode 100644
index 000000000..8e08b9e16
--- /dev/null
+++ b/libc/nptl/pthread_mutexattr_setpshared.c
@@ -0,0 +1,43 @@
+/* Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthreadP.h>
+
+
+int
+pthread_mutexattr_setpshared (attr, pshared)
+ pthread_mutexattr_t *attr;
+ int pshared;
+{
+ struct pthread_mutexattr *iattr;
+
+ if (pshared != PTHREAD_PROCESS_PRIVATE
+ && __builtin_expect (pshared != PTHREAD_PROCESS_SHARED, 0))
+ return EINVAL;
+
+ iattr = (struct pthread_mutexattr *) attr;
+
+ if (pshared == PTHREAD_PROCESS_PRIVATE)
+ iattr->mutexkind &= ~PTHREAD_MUTEXATTR_FLAG_PSHARED;
+ else
+ iattr->mutexkind |= PTHREAD_MUTEXATTR_FLAG_PSHARED;
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_mutexattr_setrobust.c b/libc/nptl/pthread_mutexattr_setrobust.c
new file mode 100644
index 000000000..cf95e35b6
--- /dev/null
+++ b/libc/nptl/pthread_mutexattr_setrobust.c
@@ -0,0 +1,43 @@
+/* Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2005.
+
+ 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 <errno.h>
+#include <pthreadP.h>
+
+
+int
+pthread_mutexattr_setrobust_np (attr, robustness)
+ pthread_mutexattr_t *attr;
+ int robustness;
+{
+ if (robustness != PTHREAD_MUTEX_STALLED_NP
+ && __builtin_expect (robustness != PTHREAD_MUTEX_ROBUST_NP, 0))
+ return EINVAL;
+
+ struct pthread_mutexattr *iattr = (struct pthread_mutexattr *) attr;
+
+ /* We use bit 30 to signal whether the mutex is going to be
+ robust or not. */
+ if (robustness == PTHREAD_MUTEX_STALLED_NP)
+ iattr->mutexkind &= ~PTHREAD_MUTEXATTR_FLAG_ROBUST;
+ else
+ iattr->mutexkind |= PTHREAD_MUTEXATTR_FLAG_ROBUST;
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_mutexattr_settype.c b/libc/nptl/pthread_mutexattr_settype.c
new file mode 100644
index 000000000..fe6b5c22c
--- /dev/null
+++ b/libc/nptl/pthread_mutexattr_settype.c
@@ -0,0 +1,41 @@
+/* Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthreadP.h>
+
+
+int
+__pthread_mutexattr_settype (attr, kind)
+ pthread_mutexattr_t *attr;
+ int kind;
+{
+ struct pthread_mutexattr *iattr;
+
+ if (kind < PTHREAD_MUTEX_NORMAL || kind > PTHREAD_MUTEX_ADAPTIVE_NP)
+ return EINVAL;
+
+ iattr = (struct pthread_mutexattr *) attr;
+
+ iattr->mutexkind = (iattr->mutexkind & PTHREAD_MUTEXATTR_FLAG_BITS) | kind;
+
+ return 0;
+}
+weak_alias (__pthread_mutexattr_settype, pthread_mutexattr_setkind_np)
+strong_alias (__pthread_mutexattr_settype, pthread_mutexattr_settype)
diff --git a/libc/nptl/pthread_rwlock_destroy.c b/libc/nptl/pthread_rwlock_destroy.c
new file mode 100644
index 000000000..28fd24b55
--- /dev/null
+++ b/libc/nptl/pthread_rwlock_destroy.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "pthreadP.h"
+
+
+int
+__pthread_rwlock_destroy (rwlock)
+ pthread_rwlock_t *rwlock;
+{
+ /* Nothing to be done. For now. */
+ return 0;
+}
+strong_alias (__pthread_rwlock_destroy, pthread_rwlock_destroy)
diff --git a/libc/nptl/pthread_rwlock_init.c b/libc/nptl/pthread_rwlock_init.c
new file mode 100644
index 000000000..f664dd810
--- /dev/null
+++ b/libc/nptl/pthread_rwlock_init.c
@@ -0,0 +1,51 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "pthreadP.h"
+
+
+static const struct pthread_rwlockattr default_attr =
+ {
+ .lockkind = PTHREAD_RWLOCK_DEFAULT_NP,
+ .pshared = PTHREAD_PROCESS_PRIVATE
+ };
+
+
+int
+__pthread_rwlock_init (rwlock, attr)
+ pthread_rwlock_t *rwlock;
+ const pthread_rwlockattr_t *attr;
+{
+ const struct pthread_rwlockattr *iattr;
+
+ iattr = ((const struct pthread_rwlockattr *) attr) ?: &default_attr;
+
+ rwlock->__data.__lock = 0;
+ rwlock->__data.__flags
+ = iattr->lockkind == PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP;
+ rwlock->__data.__nr_readers = 0;
+ rwlock->__data.__writer = 0;
+ rwlock->__data.__readers_wakeup = 0;
+ rwlock->__data.__writer_wakeup = 0;
+ rwlock->__data.__nr_readers_queued = 0;
+ rwlock->__data.__nr_writers_queued = 0;
+
+ return 0;
+}
+strong_alias (__pthread_rwlock_init, pthread_rwlock_init)
diff --git a/libc/nptl/pthread_rwlock_tryrdlock.c b/libc/nptl/pthread_rwlock_tryrdlock.c
new file mode 100644
index 000000000..446af0596
--- /dev/null
+++ b/libc/nptl/pthread_rwlock_tryrdlock.c
@@ -0,0 +1,50 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include "pthreadP.h"
+#include <lowlevellock.h>
+
+
+int
+__pthread_rwlock_tryrdlock (rwlock)
+ pthread_rwlock_t *rwlock;
+{
+ int result = EBUSY;
+
+ lll_mutex_lock (rwlock->__data.__lock);
+
+ if (rwlock->__data.__writer == 0
+ && (rwlock->__data.__nr_writers_queued == 0
+ || rwlock->__data.__flags == 0))
+ {
+ if (__builtin_expect (++rwlock->__data.__nr_readers == 0, 0))
+ {
+ --rwlock->__data.__nr_readers;
+ result = EAGAIN;
+ }
+ else
+ result = 0;
+ }
+
+ lll_mutex_unlock (rwlock->__data.__lock);
+
+ return result;
+}
+strong_alias (__pthread_rwlock_tryrdlock, pthread_rwlock_tryrdlock)
diff --git a/libc/nptl/pthread_rwlock_trywrlock.c b/libc/nptl/pthread_rwlock_trywrlock.c
new file mode 100644
index 000000000..b754a1956
--- /dev/null
+++ b/libc/nptl/pthread_rwlock_trywrlock.c
@@ -0,0 +1,43 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include "pthreadP.h"
+#include <lowlevellock.h>
+
+
+int
+__pthread_rwlock_trywrlock (rwlock)
+ pthread_rwlock_t *rwlock;
+{
+ int result = EBUSY;
+
+ lll_mutex_lock (rwlock->__data.__lock);
+
+ if (rwlock->__data.__writer == 0 && rwlock->__data.__nr_readers == 0)
+ {
+ rwlock->__data.__writer = THREAD_GETMEM (THREAD_SELF, tid);
+ result = 0;
+ }
+
+ lll_mutex_unlock (rwlock->__data.__lock);
+
+ return result;
+}
+strong_alias (__pthread_rwlock_trywrlock, pthread_rwlock_trywrlock)
diff --git a/libc/nptl/pthread_rwlockattr_destroy.c b/libc/nptl/pthread_rwlockattr_destroy.c
new file mode 100644
index 000000000..4f0c2c4fe
--- /dev/null
+++ b/libc/nptl/pthread_rwlockattr_destroy.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "pthreadP.h"
+
+
+int
+pthread_rwlockattr_destroy (attr)
+ pthread_rwlockattr_t *attr;
+{
+ /* Nothing to do. For now. */
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_rwlockattr_getkind_np.c b/libc/nptl/pthread_rwlockattr_getkind_np.c
new file mode 100644
index 000000000..aad9468fd
--- /dev/null
+++ b/libc/nptl/pthread_rwlockattr_getkind_np.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "pthreadP.h"
+
+
+int
+pthread_rwlockattr_getkind_np (attr, pref)
+ const pthread_rwlockattr_t *attr;
+ int *pref;
+{
+ *pref = ((const struct pthread_rwlockattr *) attr)->lockkind;
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_rwlockattr_getpshared.c b/libc/nptl/pthread_rwlockattr_getpshared.c
new file mode 100644
index 000000000..3a776835a
--- /dev/null
+++ b/libc/nptl/pthread_rwlockattr_getpshared.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "pthreadP.h"
+
+
+int
+pthread_rwlockattr_getpshared (attr, pshared)
+ const pthread_rwlockattr_t *attr;
+ int *pshared;
+{
+ *pshared = ((const struct pthread_rwlockattr *) attr)->pshared;
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_rwlockattr_init.c b/libc/nptl/pthread_rwlockattr_init.c
new file mode 100644
index 000000000..b29953455
--- /dev/null
+++ b/libc/nptl/pthread_rwlockattr_init.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "pthreadP.h"
+
+
+int
+pthread_rwlockattr_init (attr)
+ pthread_rwlockattr_t *attr;
+{
+ struct pthread_rwlockattr *iattr;
+
+ iattr = (struct pthread_rwlockattr *) attr;
+
+ iattr->lockkind = PTHREAD_RWLOCK_DEFAULT_NP;
+ iattr->pshared = PTHREAD_PROCESS_PRIVATE;
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_rwlockattr_setkind_np.c b/libc/nptl/pthread_rwlockattr_setkind_np.c
new file mode 100644
index 000000000..0311f1b50
--- /dev/null
+++ b/libc/nptl/pthread_rwlockattr_setkind_np.c
@@ -0,0 +1,41 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include "pthreadP.h"
+
+
+int
+pthread_rwlockattr_setkind_np (attr, pref)
+ pthread_rwlockattr_t *attr;
+ int pref;
+{
+ struct pthread_rwlockattr *iattr;
+
+ if (pref != PTHREAD_RWLOCK_PREFER_READER_NP
+ && pref != PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP
+ && __builtin_expect (pref != PTHREAD_RWLOCK_PREFER_WRITER_NP, 0))
+ return EINVAL;
+
+ iattr = (struct pthread_rwlockattr *) attr;
+
+ iattr->lockkind = pref;
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_rwlockattr_setpshared.c b/libc/nptl/pthread_rwlockattr_setpshared.c
new file mode 100644
index 000000000..9438d2931
--- /dev/null
+++ b/libc/nptl/pthread_rwlockattr_setpshared.c
@@ -0,0 +1,40 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include "pthreadP.h"
+
+
+int
+pthread_rwlockattr_setpshared (attr, pshared)
+ pthread_rwlockattr_t *attr;
+ int pshared;
+{
+ struct pthread_rwlockattr *iattr;
+
+ if (pshared != PTHREAD_PROCESS_SHARED
+ && __builtin_expect (pshared != PTHREAD_PROCESS_PRIVATE, 0))
+ return EINVAL;
+
+ iattr = (struct pthread_rwlockattr *) attr;
+
+ iattr->pshared = pshared;
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_self.c b/libc/nptl/pthread_self.c
new file mode 100644
index 000000000..f0e3b3f98
--- /dev/null
+++ b/libc/nptl/pthread_self.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "pthreadP.h"
+#include <tls.h>
+
+
+pthread_t
+__pthread_self (void)
+{
+ return (pthread_t) THREAD_SELF;
+}
+strong_alias (__pthread_self, pthread_self)
diff --git a/libc/nptl/pthread_setcancelstate.c b/libc/nptl/pthread_setcancelstate.c
new file mode 100644
index 000000000..a452c2ec4
--- /dev/null
+++ b/libc/nptl/pthread_setcancelstate.c
@@ -0,0 +1,73 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include "pthreadP.h"
+#include <atomic.h>
+
+
+int
+__pthread_setcancelstate (state, oldstate)
+ int state;
+ int *oldstate;
+{
+ volatile struct pthread *self;
+
+ if (state < PTHREAD_CANCEL_ENABLE || state > PTHREAD_CANCEL_DISABLE)
+ return EINVAL;
+
+ self = THREAD_SELF;
+
+ int oldval = THREAD_GETMEM (self, cancelhandling);
+ while (1)
+ {
+ int newval = (state == PTHREAD_CANCEL_DISABLE
+ ? oldval | CANCELSTATE_BITMASK
+ : oldval & ~CANCELSTATE_BITMASK);
+
+ /* Store the old value. */
+ if (oldstate != NULL)
+ *oldstate = ((oldval & CANCELSTATE_BITMASK)
+ ? PTHREAD_CANCEL_DISABLE : PTHREAD_CANCEL_ENABLE);
+
+ /* Avoid doing unnecessary work. The atomic operation can
+ potentially be expensive if the memory has to be locked and
+ remote cache lines have to be invalidated. */
+ if (oldval == newval)
+ break;
+
+ /* Update the cancel handling word. This has to be done
+ atomically since other bits could be modified as well. */
+ int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
+ oldval);
+ if (__builtin_expect (curval == oldval, 1))
+ {
+ if (CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS (newval))
+ __do_cancel ();
+
+ break;
+ }
+
+ /* Prepare for the next round. */
+ oldval = curval;
+ }
+
+ return 0;
+}
+strong_alias (__pthread_setcancelstate, pthread_setcancelstate)
diff --git a/libc/nptl/pthread_setcanceltype.c b/libc/nptl/pthread_setcanceltype.c
new file mode 100644
index 000000000..bbe87ba64
--- /dev/null
+++ b/libc/nptl/pthread_setcanceltype.c
@@ -0,0 +1,76 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include "pthreadP.h"
+#include <atomic.h>
+
+
+int
+__pthread_setcanceltype (type, oldtype)
+ int type;
+ int *oldtype;
+{
+ volatile struct pthread *self;
+
+ if (type < PTHREAD_CANCEL_DEFERRED || type > PTHREAD_CANCEL_ASYNCHRONOUS)
+ return EINVAL;
+
+ self = THREAD_SELF;
+
+ int oldval = THREAD_GETMEM (self, cancelhandling);
+ while (1)
+ {
+ int newval = (type == PTHREAD_CANCEL_ASYNCHRONOUS
+ ? oldval | CANCELTYPE_BITMASK
+ : oldval & ~CANCELTYPE_BITMASK);
+
+ /* Store the old value. */
+ if (oldtype != NULL)
+ *oldtype = ((oldval & CANCELTYPE_BITMASK)
+ ? PTHREAD_CANCEL_ASYNCHRONOUS : PTHREAD_CANCEL_DEFERRED);
+
+ /* Avoid doing unnecessary work. The atomic operation can
+ potentially be expensive if the memory has to be locked and
+ remote cache lines have to be invalidated. */
+ if (oldval == newval)
+ break;
+
+ /* Update the cancel handling word. This has to be done
+ atomically since other bits could be modified as well. */
+ int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
+ oldval);
+ if (__builtin_expect (curval == oldval, 1))
+ {
+ if (CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS (newval))
+ {
+ THREAD_SETMEM (self, result, PTHREAD_CANCELED);
+ __do_cancel ();
+ }
+
+ break;
+ }
+
+ /* Prepare for the next round. */
+ oldval = curval;
+ }
+
+ return 0;
+}
+strong_alias (__pthread_setcanceltype, pthread_setcanceltype)
diff --git a/libc/nptl/pthread_setconcurrency.c b/libc/nptl/pthread_setconcurrency.c
new file mode 100644
index 000000000..8cf150713
--- /dev/null
+++ b/libc/nptl/pthread_setconcurrency.c
@@ -0,0 +1,41 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include "pthreadP.h"
+
+
+/* Global definition. Needed in pthread_getconcurrency as well. */
+int __concurrency_level;
+
+
+int
+pthread_setconcurrency (level)
+ int level;
+{
+ if (level < 0)
+ return EINVAL;
+
+ __concurrency_level = level;
+
+ /* XXX For ports which actually need to handle the concurrency level
+ some more code is probably needed here. */
+
+ return 0;
+}
diff --git a/libc/nptl/pthread_setegid.c b/libc/nptl/pthread_setegid.c
new file mode 100644
index 000000000..9252dfac7
--- /dev/null
+++ b/libc/nptl/pthread_setegid.c
@@ -0,0 +1,3 @@
+#define SINGLE_THREAD
+#define setegid pthread_setegid_np
+#include <setegid.c>
diff --git a/libc/nptl/pthread_seteuid.c b/libc/nptl/pthread_seteuid.c
new file mode 100644
index 000000000..47bb69802
--- /dev/null
+++ b/libc/nptl/pthread_seteuid.c
@@ -0,0 +1,3 @@
+#define SINGLE_THREAD
+#define seteuid pthread_seteuid_np
+#include <seteuid.c>
diff --git a/libc/nptl/pthread_setgid.c b/libc/nptl/pthread_setgid.c
new file mode 100644
index 000000000..b06bffbf3
--- /dev/null
+++ b/libc/nptl/pthread_setgid.c
@@ -0,0 +1,3 @@
+#define SINGLE_THREAD
+#define __setgid pthread_setgid_np
+#include <setgid.c>
diff --git a/libc/nptl/pthread_setregid.c b/libc/nptl/pthread_setregid.c
new file mode 100644
index 000000000..7461d2b7f
--- /dev/null
+++ b/libc/nptl/pthread_setregid.c
@@ -0,0 +1,3 @@
+#define SINGLE_THREAD
+#define __setregid pthread_setregid_np
+#include <setregid.c>
diff --git a/libc/nptl/pthread_setresgid.c b/libc/nptl/pthread_setresgid.c
new file mode 100644
index 000000000..369fae267
--- /dev/null
+++ b/libc/nptl/pthread_setresgid.c
@@ -0,0 +1,3 @@
+#define SINGLE_THREAD
+#define __setresgid pthread_setresgid_np
+#include <setresgid.c>
diff --git a/libc/nptl/pthread_setresuid.c b/libc/nptl/pthread_setresuid.c
new file mode 100644
index 000000000..ac57c0fa8
--- /dev/null
+++ b/libc/nptl/pthread_setresuid.c
@@ -0,0 +1,3 @@
+#define SINGLE_THREAD
+#define __setresuid pthread_setresuid_np
+#include <setresuid.c>
diff --git a/libc/nptl/pthread_setreuid.c b/libc/nptl/pthread_setreuid.c
new file mode 100644
index 000000000..aa804ab01
--- /dev/null
+++ b/libc/nptl/pthread_setreuid.c
@@ -0,0 +1,3 @@
+#define SINGLE_THREAD
+#define __setreuid pthread_setreuid_np
+#include <setreuid.c>
diff --git a/libc/nptl/pthread_setschedparam.c b/libc/nptl/pthread_setschedparam.c
new file mode 100644
index 000000000..30ac6b3e8
--- /dev/null
+++ b/libc/nptl/pthread_setschedparam.c
@@ -0,0 +1,80 @@
+/* Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <sched.h>
+#include <string.h>
+#include "pthreadP.h"
+#include <lowlevellock.h>
+
+
+int
+__pthread_setschedparam (threadid, policy, param)
+ pthread_t threadid;
+ int policy;
+ const struct sched_param *param;
+{
+ struct pthread *pd = (struct pthread *) threadid;
+
+ /* Make sure the descriptor is valid. */
+ if (INVALID_TD_P (pd))
+ /* Not a valid thread handle. */
+ return ESRCH;
+
+ int result = 0;
+
+ /* We have to handle cancellation in the following code since we are
+ locking another threads desriptor. */
+ pthread_cleanup_push ((void (*) (void *)) lll_unlock_wake_cb, &pd->lock);
+
+ lll_lock (pd->lock);
+
+ struct sched_param p;
+ const struct sched_param *orig_param = param;
+
+ /* If the thread should have higher priority because of some
+ PTHREAD_PRIO_PROTECT mutexes it holds, adjust the priority. */
+ if (__builtin_expect (pd->tpp != NULL, 0)
+ && pd->tpp->priomax > param->sched_priority)
+ {
+ p = *param;
+ p.sched_priority = pd->tpp->priomax;
+ param = &p;
+ }
+
+ /* Try to set the scheduler information. */
+ if (__builtin_expect (__sched_setscheduler (pd->tid, policy,
+ param) == -1, 0))
+ result = errno;
+ else
+ {
+ /* We succeeded changing the kernel information. Reflect this
+ change in the thread descriptor. */
+ pd->schedpolicy = policy;
+ memcpy (&pd->schedparam, orig_param, sizeof (struct sched_param));
+ pd->flags |= ATTR_FLAG_SCHED_SET | ATTR_FLAG_POLICY_SET;
+ }
+
+ lll_unlock (pd->lock);
+
+ pthread_cleanup_pop (0);
+
+ return result;
+}
+strong_alias (__pthread_setschedparam, pthread_setschedparam)
diff --git a/libc/nptl/pthread_setschedprio.c b/libc/nptl/pthread_setschedprio.c
new file mode 100644
index 000000000..4a71f6c7b
--- /dev/null
+++ b/libc/nptl/pthread_setschedprio.c
@@ -0,0 +1,72 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <sched.h>
+#include <string.h>
+#include <sched.h>
+#include "pthreadP.h"
+#include <lowlevellock.h>
+
+
+int
+pthread_setschedprio (threadid, prio)
+ pthread_t threadid;
+ int prio;
+{
+ struct pthread *pd = (struct pthread *) threadid;
+
+ /* Make sure the descriptor is valid. */
+ if (INVALID_TD_P (pd))
+ /* Not a valid thread handle. */
+ return ESRCH;
+
+ int result = 0;
+ struct sched_param param;
+ param.sched_priority = prio;
+
+ /* We have to handle cancellation in the following code since we are
+ locking another threads desriptor. */
+ pthread_cleanup_push ((void (*) (void *)) lll_unlock_wake_cb, &pd->lock);
+
+ lll_lock (pd->lock);
+
+ /* If the thread should have higher priority because of some
+ PTHREAD_PRIO_PROTECT mutexes it holds, adjust the priority. */
+ if (__builtin_expect (pd->tpp != NULL, 0) && pd->tpp->priomax > prio)
+ param.sched_priority = pd->tpp->priomax;
+
+ /* Try to set the scheduler information. */
+ if (__builtin_expect (sched_setparam (pd->tid, &param) == -1, 0))
+ result = errno;
+ else
+ {
+ /* We succeeded changing the kernel information. Reflect this
+ change in the thread descriptor. */
+ param.sched_priority = prio;
+ memcpy (&pd->schedparam, &param, sizeof (struct sched_param));
+ pd->flags |= ATTR_FLAG_SCHED_SET;
+ }
+
+ lll_unlock (pd->lock);
+
+ pthread_cleanup_pop (0);
+
+ return result;
+}
diff --git a/libc/nptl/pthread_setspecific.c b/libc/nptl/pthread_setspecific.c
new file mode 100644
index 000000000..152f5590e
--- /dev/null
+++ b/libc/nptl/pthread_setspecific.c
@@ -0,0 +1,96 @@
+/* Copyright (C) 2002, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <stdlib.h>
+#include "pthreadP.h"
+
+
+int
+__pthread_setspecific (key, value)
+ pthread_key_t key;
+ const void *value;
+{
+ struct pthread *self;
+ unsigned int idx1st;
+ unsigned int idx2nd;
+ struct pthread_key_data *level2;
+ unsigned int seq;
+
+ self = THREAD_SELF;
+
+ /* Special case access to the first 2nd-level block. This is the
+ usual case. */
+ if (__builtin_expect (key < PTHREAD_KEY_2NDLEVEL_SIZE, 1))
+ {
+ /* Verify the key is sane. */
+ if (KEY_UNUSED ((seq = __pthread_keys[key].seq)))
+ /* Not valid. */
+ return EINVAL;
+
+ level2 = &self->specific_1stblock[key];
+
+ /* Remember that we stored at least one set of data. */
+ if (value != NULL)
+ THREAD_SETMEM (self, specific_used, true);
+ }
+ else
+ {
+ if (key >= PTHREAD_KEYS_MAX
+ || KEY_UNUSED ((seq = __pthread_keys[key].seq)))
+ /* Not valid. */
+ return EINVAL;
+
+ idx1st = key / PTHREAD_KEY_2NDLEVEL_SIZE;
+ idx2nd = key % PTHREAD_KEY_2NDLEVEL_SIZE;
+
+ /* This is the second level array. Allocate it if necessary. */
+ level2 = THREAD_GETMEM_NC (self, specific, idx1st);
+ if (level2 == NULL)
+ {
+ if (value == NULL)
+ /* We don't have to do anything. The value would in any case
+ be NULL. We can save the memory allocation. */
+ return 0;
+
+ level2
+ = (struct pthread_key_data *) calloc (PTHREAD_KEY_2NDLEVEL_SIZE,
+ sizeof (*level2));
+ if (level2 == NULL)
+ return ENOMEM;
+
+ THREAD_SETMEM_NC (self, specific, idx1st, level2);
+ }
+
+ /* Pointer to the right array element. */
+ level2 = &level2[idx2nd];
+
+ /* Remember that we stored at least one set of data. */
+ THREAD_SETMEM (self, specific_used, true);
+ }
+
+ /* Store the data and the sequence number so that we can recognize
+ stale data. */
+ level2->seq = seq;
+ level2->data = (void *) value;
+
+ return 0;
+}
+strong_alias (__pthread_setspecific, pthread_setspecific)
+strong_alias (__pthread_setspecific, __pthread_setspecific_internal)
diff --git a/libc/nptl/pthread_setuid.c b/libc/nptl/pthread_setuid.c
new file mode 100644
index 000000000..ff949c850
--- /dev/null
+++ b/libc/nptl/pthread_setuid.c
@@ -0,0 +1,3 @@
+#define SINGLE_THREAD
+#define __setuid pthread_setuid_np
+#include <setuid.c>
diff --git a/libc/nptl/pthread_testcancel.c b/libc/nptl/pthread_testcancel.c
new file mode 100644
index 000000000..e9b17b493
--- /dev/null
+++ b/libc/nptl/pthread_testcancel.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <stdlib.h>
+#include "pthreadP.h"
+
+
+void
+pthread_testcancel (void)
+{
+ CANCELLATION_P (THREAD_SELF);
+}
diff --git a/libc/nptl/pthread_timedjoin.c b/libc/nptl/pthread_timedjoin.c
new file mode 100644
index 000000000..5df6ab6a8
--- /dev/null
+++ b/libc/nptl/pthread_timedjoin.c
@@ -0,0 +1,107 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <stdlib.h>
+#include <atomic.h>
+#include "pthreadP.h"
+
+
+static void
+cleanup (void *arg)
+{
+ *(void **) arg = NULL;
+}
+
+
+int
+pthread_timedjoin_np (threadid, thread_return, abstime)
+ pthread_t threadid;
+ void **thread_return;
+ const struct timespec *abstime;
+{
+ struct pthread *self;
+ struct pthread *pd = (struct pthread *) threadid;
+ int result;
+
+ /* Make sure the descriptor is valid. */
+ if (INVALID_NOT_TERMINATED_TD_P (pd))
+ /* Not a valid thread handle. */
+ return ESRCH;
+
+ /* Is the thread joinable?. */
+ if (IS_DETACHED (pd))
+ /* We cannot wait for the thread. */
+ return EINVAL;
+
+ self = THREAD_SELF;
+ if (pd == self || self->joinid == pd)
+ /* This is a deadlock situation. The threads are waiting for each
+ other to finish. Note that this is a "may" error. To be 100%
+ sure we catch this error we would have to lock the data
+ structures but it is not necessary. In the unlikely case that
+ two threads are really caught in this situation they will
+ deadlock. It is the programmer's problem to figure this
+ out. */
+ return EDEADLK;
+
+ /* Wait for the thread to finish. If it is already locked something
+ is wrong. There can only be one waiter. */
+ if (__builtin_expect (atomic_compare_and_exchange_bool_acq (&pd->joinid,
+ self, NULL), 0))
+ /* There is already somebody waiting for the thread. */
+ return EINVAL;
+
+
+ /* During the wait we change to asynchronous cancellation. If we
+ are cancelled the thread we are waiting for must be marked as
+ un-wait-ed for again. */
+ pthread_cleanup_push (cleanup, &pd->joinid);
+
+ /* Switch to asynchronous cancellation. */
+ int oldtype = CANCEL_ASYNC ();
+
+
+ /* Wait for the child. */
+ result = lll_timedwait_tid (pd->tid, abstime);
+
+
+ /* Restore cancellation mode. */
+ CANCEL_RESET (oldtype);
+
+ /* Remove the handler. */
+ pthread_cleanup_pop (0);
+
+
+ /* We might have timed out. */
+ if (result == 0)
+ {
+ /* Store the return value if the caller is interested. */
+ if (thread_return != NULL)
+ *thread_return = pd->result;
+
+
+ /* Free the TCB. */
+ __free_tcb (pd);
+ }
+ else
+ pd->joinid = NULL;
+
+ return result;
+}
diff --git a/libc/nptl/pthread_tryjoin.c b/libc/nptl/pthread_tryjoin.c
new file mode 100644
index 000000000..fc363dd77
--- /dev/null
+++ b/libc/nptl/pthread_tryjoin.c
@@ -0,0 +1,75 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <stdlib.h>
+
+#include <atomic.h>
+#include "pthreadP.h"
+
+
+int
+pthread_tryjoin_np (threadid, thread_return)
+ pthread_t threadid;
+ void **thread_return;
+{
+ struct pthread *self;
+ struct pthread *pd = (struct pthread *) threadid;
+
+ /* Make sure the descriptor is valid. */
+ if (DEBUGGING_P && __find_in_stack_list (pd) == NULL)
+ /* Not a valid thread handle. */
+ return ESRCH;
+
+ /* Is the thread joinable?. */
+ if (IS_DETACHED (pd))
+ /* We cannot wait for the thread. */
+ return EINVAL;
+
+ self = THREAD_SELF;
+ if (pd == self || self->joinid == pd)
+ /* This is a deadlock situation. The threads are waiting for each
+ other to finish. Note that this is a "may" error. To be 100%
+ sure we catch this error we would have to lock the data
+ structures but it is not necessary. In the unlikely case that
+ two threads are really caught in this situation they will
+ deadlock. It is the programmer's problem to figure this
+ out. */
+ return EDEADLK;
+
+ /* Return right away if the thread hasn't terminated yet. */
+ if (pd->tid != 0)
+ return EBUSY;
+
+ /* Wait for the thread to finish. If it is already locked something
+ is wrong. There can only be one waiter. */
+ if (atomic_compare_and_exchange_bool_acq (&pd->joinid, self, NULL))
+ /* There is already somebody waiting for the thread. */
+ return EINVAL;
+
+ /* Store the return value if the caller is interested. */
+ if (thread_return != NULL)
+ *thread_return = pd->result;
+
+
+ /* Free the TCB. */
+ __free_tcb (pd);
+
+ return 0;
+}
diff --git a/libc/nptl/res.c b/libc/nptl/res.c
new file mode 100644
index 000000000..ba4f81d06
--- /dev/null
+++ b/libc/nptl/res.c
@@ -0,0 +1,27 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <features.h>
+#include <resolv.h>
+#include <tls.h>
+
+struct __res_state *
+__res_state (void)
+{
+ return __resp;
+}
diff --git a/libc/nptl/sem_close.c b/libc/nptl/sem_close.c
new file mode 100644
index 000000000..279522d08
--- /dev/null
+++ b/libc/nptl/sem_close.c
@@ -0,0 +1,81 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <search.h>
+#include <sys/mman.h>
+#include "semaphoreP.h"
+
+
+/* Global variables to parametrize the walk function. This works
+ since we always have to use locks. And we have to use the twalk
+ function since the entries are not sorted wrt the mapping
+ address. */
+static sem_t *the_sem;
+static struct inuse_sem *rec;
+
+static void
+walker (const void *inodep, const VISIT which, const int depth)
+{
+ struct inuse_sem *nodep = *(struct inuse_sem **) inodep;
+
+ if (nodep->sem == the_sem)
+ rec = nodep;
+}
+
+
+int
+sem_close (sem)
+ sem_t *sem;
+{
+ int result = 0;
+
+ /* Get the lock. */
+ lll_lock (__sem_mappings_lock);
+
+ /* Locate the entry for the mapping the caller provided. */
+ rec = NULL;
+ the_sem = sem;
+ twalk (__sem_mappings, walker);
+ if (rec != NULL)
+ {
+ /* Check the reference counter. If it is going to be zero, free
+ all the resources. */
+ if (--rec->refcnt == 0)
+ {
+ /* Remove the record from the tree. */
+ (void) tdelete (rec, &__sem_mappings, __sem_search);
+
+ result = munmap (rec->sem, sizeof (sem_t));
+
+ free (rec);
+ }
+ }
+ else
+ {
+ /* This is no valid semaphore. */
+ result = -1;
+ __set_errno (EINVAL);
+ }
+
+ /* Release the lock. */
+ lll_unlock (__sem_mappings_lock);
+
+ return result;
+}
diff --git a/libc/nptl/sem_destroy.c b/libc/nptl/sem_destroy.c
new file mode 100644
index 000000000..1c823dc51
--- /dev/null
+++ b/libc/nptl/sem_destroy.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <semaphore.h>
+#include <shlib-compat.h>
+#include "semaphoreP.h"
+
+
+int
+__new_sem_destroy (sem)
+ sem_t *sem;
+{
+ /* XXX Check for valid parameter. */
+
+ /* Nothing to do. */
+ return 0;
+}
+versioned_symbol (libpthread, __new_sem_destroy, sem_destroy, GLIBC_2_1);
+#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1)
+strong_alias (__new_sem_destroy, __old_sem_destroy)
+compat_symbol (libpthread, __old_sem_destroy, sem_destroy, GLIBC_2_0);
+#endif
diff --git a/libc/nptl/sem_getvalue.c b/libc/nptl/sem_getvalue.c
new file mode 100644
index 000000000..6bc7ea82b
--- /dev/null
+++ b/libc/nptl/sem_getvalue.c
@@ -0,0 +1,42 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <semaphore.h>
+#include <shlib-compat.h>
+#include "semaphoreP.h"
+
+
+int
+__new_sem_getvalue (sem, sval)
+ sem_t *sem;
+ int *sval;
+{
+ struct sem *isem = (struct sem *) sem;
+
+ /* XXX Check for valid SEM parameter. */
+
+ *sval = isem->count;
+
+ return 0;
+}
+versioned_symbol (libpthread, __new_sem_getvalue, sem_getvalue, GLIBC_2_1);
+#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1)
+strong_alias (__new_sem_getvalue, __old_sem_getvalue)
+compat_symbol (libpthread, __old_sem_getvalue, sem_getvalue, GLIBC_2_0);
+#endif
diff --git a/libc/nptl/sem_init.c b/libc/nptl/sem_init.c
new file mode 100644
index 000000000..8709911ac
--- /dev/null
+++ b/libc/nptl/sem_init.c
@@ -0,0 +1,55 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <semaphore.h>
+#include <lowlevellock.h>
+#include <shlib-compat.h>
+#include "semaphoreP.h"
+
+
+int
+__new_sem_init (sem, pshared, value)
+ sem_t *sem;
+ int pshared;
+ unsigned int value;
+{
+ /* Parameter sanity check. */
+ if (__builtin_expect (value > SEM_VALUE_MAX, 0))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ /* Map to the internal type. */
+ struct sem *isem = (struct sem *) sem;
+
+ /* Use the value the user provided. */
+ isem->count = value;
+
+ /* We can completely ignore the PSHARED parameter since inter-process
+ use needs no special preparation. */
+
+ return 0;
+}
+versioned_symbol (libpthread, __new_sem_init, sem_init, GLIBC_2_1);
+#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1)
+strong_alias (__new_sem_init, __old_sem_init)
+compat_symbol (libpthread, __old_sem_init, sem_init, GLIBC_2_0);
+#endif
diff --git a/libc/nptl/sem_open.c b/libc/nptl/sem_open.c
new file mode 100644
index 000000000..66bcb13ae
--- /dev/null
+++ b/libc/nptl/sem_open.c
@@ -0,0 +1,404 @@
+/* Copyright (C) 2002, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <fcntl.h>
+#include <mntent.h>
+#include <paths.h>
+#include <pthread.h>
+#include <search.h>
+#include <semaphore.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/statfs.h>
+#include <linux_fsinfo.h>
+#include "semaphoreP.h"
+
+
+
+/* Information about the mount point. */
+struct mountpoint_info mountpoint attribute_hidden;
+
+/* This is the default mount point. */
+static const char defaultmount[] = "/dev/shm";
+/* This is the default directory. */
+static const char defaultdir[] = "/dev/shm/sem.";
+
+/* Protect the `mountpoint' variable above. */
+pthread_once_t __namedsem_once attribute_hidden = PTHREAD_ONCE_INIT;
+
+
+/* Determine where the shmfs is mounted (if at all). */
+void
+attribute_hidden
+__where_is_shmfs (void)
+{
+ char buf[512];
+ struct statfs f;
+ struct mntent resmem;
+ struct mntent *mp;
+ FILE *fp;
+
+ /* The canonical place is /dev/shm. This is at least what the
+ documentation tells everybody to do. */
+ if (__statfs (defaultmount, &f) == 0 && f.f_type == SHMFS_SUPER_MAGIC)
+ {
+ /* It is in the normal place. */
+ mountpoint.dir = (char *) defaultdir;
+ mountpoint.dirlen = sizeof (defaultdir) - 1;
+
+ return;
+ }
+
+ /* OK, do it the hard way. Look through the /proc/mounts file and if
+ this does not exist through /etc/fstab to find the mount point. */
+ fp = __setmntent ("/proc/mounts", "r");
+ if (__builtin_expect (fp == NULL, 0))
+ {
+ fp = __setmntent (_PATH_MNTTAB, "r");
+ if (__builtin_expect (fp == NULL, 0))
+ /* There is nothing we can do. Blind guesses are not helpful. */
+ return;
+ }
+
+ /* Now read the entries. */
+ while ((mp = __getmntent_r (fp, &resmem, buf, sizeof buf)) != NULL)
+ /* The original name is "shm" but this got changed in early Linux
+ 2.4.x to "tmpfs". */
+ if (strcmp (mp->mnt_type, "tmpfs") == 0
+ || strcmp (mp->mnt_type, "shm") == 0)
+ {
+ /* Found it. There might be more than one place where the
+ filesystem is mounted but one is enough for us. */
+ size_t namelen;
+
+ /* First make sure this really is the correct entry. At least
+ some versions of the kernel give wrong information because
+ of the implicit mount of the shmfs for SysV IPC. */
+ if (__statfs (mp->mnt_dir, &f) != 0 || f.f_type != SHMFS_SUPER_MAGIC)
+ continue;
+
+ namelen = strlen (mp->mnt_dir);
+
+ if (namelen == 0)
+ /* Hum, maybe some crippled entry. Keep on searching. */
+ continue;
+
+ mountpoint.dir = (char *) malloc (namelen + 4 + 2);
+ if (mountpoint.dir != NULL)
+ {
+ char *cp = __mempcpy (mountpoint.dir, mp->mnt_dir, namelen);
+ if (cp[-1] != '/')
+ *cp++ = '/';
+ cp = stpcpy (cp, "sem.");
+ mountpoint.dirlen = cp - mountpoint.dir;
+ }
+
+ break;
+ }
+
+ /* Close the stream. */
+ __endmntent (fp);
+}
+
+
+/* Comparison function for search of existing mapping. */
+int
+attribute_hidden
+__sem_search (const void *a, const void *b)
+{
+ const struct inuse_sem *as = (const struct inuse_sem *) a;
+ const struct inuse_sem *bs = (const struct inuse_sem *) b;
+
+ if (as->ino != bs->ino)
+ /* Cannot return the difference the type is larger than int. */
+ return as->ino < bs->ino ? -1 : (as->ino == bs->ino ? 0 : 1);
+
+ if (as->dev != bs->dev)
+ /* Cannot return the difference the type is larger than int. */
+ return as->dev < bs->dev ? -1 : (as->dev == bs->dev ? 0 : 1);
+
+ return strcmp (as->name, bs->name);
+}
+
+
+/* The search tree for existing mappings. */
+void *__sem_mappings attribute_hidden;
+
+/* Lock to protect the search tree. */
+lll_lock_t __sem_mappings_lock attribute_hidden = LLL_LOCK_INITIALIZER;
+
+
+/* Search for existing mapping and if possible add the one provided. */
+static sem_t *
+check_add_mapping (const char *name, size_t namelen, int fd, sem_t *existing)
+{
+ sem_t *result = SEM_FAILED;
+
+ /* Get the information about the file. */
+ struct stat64 st;
+ if (__fxstat64 (_STAT_VER, fd, &st) == 0)
+ {
+ /* Get the lock. */
+ lll_lock (__sem_mappings_lock);
+
+ /* Search for an existing mapping given the information we have. */
+ struct inuse_sem *fake;
+ fake = (struct inuse_sem *) alloca (sizeof (*fake) + namelen);
+ memcpy (fake->name, name, namelen);
+ fake->dev = st.st_dev;
+ fake->ino = st.st_ino;
+
+ struct inuse_sem **foundp = tfind (fake, &__sem_mappings, __sem_search);
+ if (foundp != NULL)
+ {
+ /* There is already a mapping. Use it. */
+ result = (*foundp)->sem;
+ ++(*foundp)->refcnt;
+ }
+ else
+ {
+ /* We haven't found a mapping. Install ione. */
+ struct inuse_sem *newp;
+
+ newp = (struct inuse_sem *) malloc (sizeof (*newp) + namelen);
+ if (newp != NULL)
+ {
+ /* If the caller hasn't provided any map it now. */
+ if (existing == SEM_FAILED)
+ existing = (sem_t *) mmap (NULL, sizeof (sem_t),
+ PROT_READ | PROT_WRITE, MAP_SHARED,
+ fd, 0);
+
+ newp->dev = st.st_dev;
+ newp->ino = st.st_ino;
+ newp->refcnt = 1;
+ newp->sem = existing;
+ memcpy (newp->name, name, namelen);
+
+ /* Insert the new value. */
+ if (existing != MAP_FAILED
+ && tsearch (newp, &__sem_mappings, __sem_search) != NULL)
+ /* Successful. */
+ result = existing;
+ else
+ /* Something went wrong while inserting the new
+ value. We fail completely. */
+ free (newp);
+ }
+ }
+
+ /* Release the lock. */
+ lll_unlock (__sem_mappings_lock);
+ }
+
+ if (result != existing && existing != SEM_FAILED && existing != MAP_FAILED)
+ {
+ /* Do not disturb errno. */
+ INTERNAL_SYSCALL_DECL (err);
+ INTERNAL_SYSCALL (munmap, err, 2, existing, sizeof (sem_t));
+ }
+
+ return result;
+}
+
+
+sem_t *
+sem_open (const char *name, int oflag, ...)
+{
+ char *finalname;
+ sem_t *result = SEM_FAILED;
+ int fd;
+
+ /* Determine where the shmfs is mounted. */
+ INTUSE(__pthread_once) (&__namedsem_once, __where_is_shmfs);
+
+ /* If we don't know the mount points there is nothing we can do. Ever. */
+ if (mountpoint.dir == NULL)
+ {
+ __set_errno (ENOSYS);
+ return SEM_FAILED;
+ }
+
+ /* Construct the filename. */
+ while (name[0] == '/')
+ ++name;
+
+ if (name[0] == '\0')
+ {
+ /* The name "/" is not supported. */
+ __set_errno (EINVAL);
+ return SEM_FAILED;
+ }
+ size_t namelen = strlen (name) + 1;
+
+ /* Create the name of the final file. */
+ finalname = (char *) alloca (mountpoint.dirlen + namelen);
+ __mempcpy (__mempcpy (finalname, mountpoint.dir, mountpoint.dirlen),
+ name, namelen);
+
+ /* If the semaphore object has to exist simply open it. */
+ if ((oflag & O_CREAT) == 0 || (oflag & O_EXCL) == 0)
+ {
+ try_again:
+ fd = __libc_open (finalname,
+ (oflag & ~(O_CREAT|O_ACCMODE)) | O_NOFOLLOW | O_RDWR);
+
+ if (fd == -1)
+ {
+ /* If we are supposed to create the file try this next. */
+ if ((oflag & O_CREAT) != 0 && errno == ENOENT)
+ goto try_create;
+
+ /* Return. errno is already set. */
+ }
+ else
+ /* Check whether we already have this semaphore mapped and
+ create one if necessary. */
+ result = check_add_mapping (name, namelen, fd, SEM_FAILED);
+ }
+ else
+ {
+ /* We have to open a temporary file first since it must have the
+ correct form before we can start using it. */
+ char *tmpfname;
+ mode_t mode;
+ unsigned int value;
+ va_list ap;
+
+ try_create:
+ va_start (ap, oflag);
+
+ mode = va_arg (ap, mode_t);
+ value = va_arg (ap, unsigned int);
+
+ va_end (ap);
+
+ if (value > SEM_VALUE_MAX)
+ {
+ __set_errno (EINVAL);
+ return SEM_FAILED;
+ }
+
+ /* Create the initial file content. */
+ sem_t initsem;
+
+ struct sem *iinitsem = (struct sem *) &initsem;
+ iinitsem->count = value;
+
+ /* Initialize the remaining bytes as well. */
+ memset ((char *) &initsem + sizeof (struct sem), '\0',
+ sizeof (sem_t) - sizeof (struct sem));
+
+ tmpfname = (char *) alloca (mountpoint.dirlen + 6 + 1);
+ char *xxxxxx = __mempcpy (tmpfname, mountpoint.dir, mountpoint.dirlen);
+
+ int retries = 0;
+#define NRETRIES 50
+ while (1)
+ {
+ /* Add the suffix for mktemp. */
+ strcpy (xxxxxx, "XXXXXX");
+
+ /* We really want to use mktemp here. We cannot use mkstemp
+ since the file must be opened with a specific mode. The
+ mode cannot later be set since then we cannot apply the
+ file create mask. */
+ if (mktemp (tmpfname) == NULL)
+ return SEM_FAILED;
+
+ /* Open the file. Make sure we do not overwrite anything. */
+ fd = __libc_open (tmpfname, O_RDWR | O_CREAT | O_EXCL, mode);
+ if (fd == -1)
+ {
+ if (errno == EEXIST)
+ {
+ if (++retries < NRETRIES)
+ continue;
+
+ __set_errno (EAGAIN);
+ }
+
+ return SEM_FAILED;
+ }
+
+ /* We got a file. */
+ break;
+ }
+
+ if (TEMP_FAILURE_RETRY (__libc_write (fd, &initsem, sizeof (sem_t)))
+ == sizeof (sem_t)
+ /* Map the sem_t structure from the file. */
+ && (result = (sem_t *) mmap (NULL, sizeof (sem_t),
+ PROT_READ | PROT_WRITE, MAP_SHARED,
+ fd, 0)) != MAP_FAILED)
+ {
+ /* Create the file. Don't overwrite an existing file. */
+ if (link (tmpfname, finalname) != 0)
+ {
+ /* Undo the mapping. */
+ (void) munmap (result, sizeof (sem_t));
+
+ /* Reinitialize 'result'. */
+ result = SEM_FAILED;
+
+ /* This failed. If O_EXCL is not set and the problem was
+ that the file exists, try again. */
+ if ((oflag & O_EXCL) == 0 && errno == EEXIST)
+ {
+ /* Remove the file. */
+ (void) unlink (tmpfname);
+
+ /* Close the file. */
+ (void) __libc_close (fd);
+
+ goto try_again;
+ }
+ }
+ else
+ /* Insert the mapping into the search tree. This also
+ determines whether another thread sneaked by and already
+ added such a mapping despite the fact that we created it. */
+ result = check_add_mapping (name, namelen, fd, result);
+ }
+
+ /* Now remove the temporary name. This should never fail. If
+ it fails we leak a file name. Better fix the kernel. */
+ (void) unlink (tmpfname);
+ }
+
+ /* Map the mmap error to the error we need. */
+ if (MAP_FAILED != (void *) SEM_FAILED && result == MAP_FAILED)
+ result = SEM_FAILED;
+
+ /* We don't need the file descriptor anymore. */
+ if (fd != -1)
+ {
+ /* Do not disturb errno. */
+ INTERNAL_SYSCALL_DECL (err);
+ INTERNAL_SYSCALL (close, err, 1, fd);
+ }
+
+ return result;
+}
diff --git a/libc/nptl/sem_unlink.c b/libc/nptl/sem_unlink.c
new file mode 100644
index 000000000..17074774d
--- /dev/null
+++ b/libc/nptl/sem_unlink.c
@@ -0,0 +1,67 @@
+/* Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <semaphore.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "semaphoreP.h"
+
+
+int
+sem_unlink (name)
+ const char *name;
+{
+ char *fname;
+ size_t namelen;
+
+ /* Determine where the shmfs is mounted. */
+ INTUSE(__pthread_once) (&__namedsem_once, __where_is_shmfs);
+
+ /* If we don't know the mount points there is nothing we can do. Ever. */
+ if (mountpoint.dir == NULL)
+ {
+ __set_errno (ENOSYS);
+ return -1;
+ }
+
+ /* Construct the filename. */
+ while (name[0] == '/')
+ ++name;
+
+ if (name[0] == '\0')
+ {
+ /* The name "/" is not supported. */
+ __set_errno (ENOENT);
+ return -1;
+ }
+ namelen = strlen (name);
+
+ /* Create the name of the file. */
+ fname = (char *) alloca (mountpoint.dirlen + namelen + 1);
+ __mempcpy (__mempcpy (fname, mountpoint.dir, mountpoint.dirlen),
+ name, namelen + 1);
+
+ /* Now try removing it. */
+ int ret = unlink (fname);
+ if (ret < 0 && errno == EPERM)
+ __set_errno (EACCES);
+ return ret;
+}
diff --git a/libc/nptl/semaphore.h b/libc/nptl/semaphore.h
new file mode 100644
index 000000000..4f13725b3
--- /dev/null
+++ b/libc/nptl/semaphore.h
@@ -0,0 +1,79 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+#ifndef _SEMAPHORE_H
+#define _SEMAPHORE_H 1
+
+#include <features.h>
+#include <sys/types.h>
+#ifdef __USE_XOPEN2K
+# define __need_timespec
+# include <time.h>
+#endif
+
+/* Get the definition for sem_t. */
+#include <bits/semaphore.h>
+
+
+__BEGIN_DECLS
+
+/* Initialize semaphore object SEM to VALUE. If PSHARED then share it
+ with other processes. */
+extern int sem_init (sem_t *__sem, int __pshared, unsigned int __value)
+ __THROW;
+/* Free resources associated with semaphore object SEM. */
+extern int sem_destroy (sem_t *__sem) __THROW;
+
+/* Open a named semaphore NAME with open flags OFLAG. */
+extern sem_t *sem_open (__const char *__name, int __oflag, ...) __THROW;
+
+/* Close descriptor for named semaphore SEM. */
+extern int sem_close (sem_t *__sem) __THROW;
+
+/* Remove named semaphore NAME. */
+extern int sem_unlink (__const char *__name) __THROW;
+
+/* Wait for SEM being posted.
+
+ This function is a cancellation point and therefore not marked with
+ __THROW. */
+extern int sem_wait (sem_t *__sem);
+
+#ifdef __USE_XOPEN2K
+/* Similar to `sem_wait' but wait only until ABSTIME.
+
+ This function is a cancellation point and therefore not marked with
+ __THROW. */
+extern int sem_timedwait (sem_t *__restrict __sem,
+ __const struct timespec *__restrict __abstime);
+#endif
+
+/* Test whether SEM is posted. */
+extern int sem_trywait (sem_t *__sem) __THROW;
+
+/* Post SEM. */
+extern int sem_post (sem_t *__sem) __THROW;
+
+/* Get current value of SEM and store it in *SVAL. */
+extern int sem_getvalue (sem_t *__restrict __sem, int *__restrict __sval)
+ __THROW;
+
+
+__END_DECLS
+
+#endif /* semaphore.h */
diff --git a/libc/nptl/semaphoreP.h b/libc/nptl/semaphoreP.h
new file mode 100644
index 000000000..754609a1a
--- /dev/null
+++ b/libc/nptl/semaphoreP.h
@@ -0,0 +1,67 @@
+/* Copyright (C) 2002, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <semaphore.h>
+#include "pthreadP.h"
+
+
+/* Mount point of the shared memory filesystem. */
+struct mountpoint_info
+{
+ char *dir;
+ size_t dirlen;
+};
+
+/* Keeping track of currently used mappings. */
+struct inuse_sem
+{
+ dev_t dev;
+ ino_t ino;
+ int refcnt;
+ sem_t *sem;
+ char name[0];
+};
+
+
+/* Variables used in multiple interfaces. */
+extern struct mountpoint_info mountpoint attribute_hidden;
+
+extern pthread_once_t __namedsem_once attribute_hidden;
+
+/* The search tree for existing mappings. */
+extern void *__sem_mappings attribute_hidden;
+
+/* Lock to protect the search tree. */
+extern lll_lock_t __sem_mappings_lock attribute_hidden;
+
+
+/* Initializer for mountpoint. */
+extern void __where_is_shmfs (void) attribute_hidden;
+
+/* Comparison function for search in tree with existing mappings. */
+extern int __sem_search (const void *a, const void *b) attribute_hidden;
+
+
+/* Prototypes of functions with multiple interfaces. */
+extern int __new_sem_init (sem_t *sem, int pshared, unsigned int value);
+extern int __new_sem_destroy (sem_t *sem);
+extern int __new_sem_post (sem_t *sem);
+extern int __new_sem_wait (sem_t *sem);
+extern int __new_sem_trywait (sem_t *sem);
+extern int __new_sem_getvalue (sem_t *sem, int *sval);
diff --git a/libc/nptl/shlib-versions b/libc/nptl/shlib-versions
new file mode 100644
index 000000000..5e18753be
--- /dev/null
+++ b/libc/nptl/shlib-versions
@@ -0,0 +1,10 @@
+mips.*-.*-linux.* libpthread=0 GLIBC_2.0 GLIBC_2.2
+sparc64-.*-linux.* libpthread=0 GLIBC_2.2
+sh.*-.*-linux.* libpthread=0 GLIBC_2.2
+ia64.*-.*-linux.* libpthread=0 GLIBC_2.2
+hppa.*-.*-linux.* libpthread=0 GLIBC_2.2
+s390x-.*-linux.* libpthread=0 GLIBC_2.2
+cris-.*-linux.* libpthread=0 GLIBC_2.2
+x86_64-.*-linux.* libpthread=0 GLIBC_2.2.5
+powerpc64-.*-linux.* libpthread=0 GLIBC_2.3
+.*-.*-linux.* libpthread=0
diff --git a/libc/nptl/sigaction.c b/libc/nptl/sigaction.c
new file mode 100644
index 000000000..60e1f1d35
--- /dev/null
+++ b/libc/nptl/sigaction.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+
+/* This is no complete implementation. The file is meant to be
+ included in the real implementation to provide the wrapper around
+ __libc_sigaction. */
+
+#include <nptl/pthreadP.h>
+
+/* We use the libc implementation but we tell it to not allow
+ SIGCANCEL or SIGTIMER to be handled. */
+#define LIBC_SIGACTION 1
+
+
+int
+__sigaction (sig, act, oact)
+ int sig;
+ const struct sigaction *act;
+ struct sigaction *oact;
+{
+ if (__builtin_expect (sig == SIGCANCEL || sig == SIGSETXID, 0))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ return __libc_sigaction (sig, act, oact);
+}
+libc_hidden_weak (__sigaction)
+weak_alias (__sigaction, sigaction)
diff --git a/libc/nptl/sockperf.c b/libc/nptl/sockperf.c
new file mode 100644
index 000000000..d29a6ee26
--- /dev/null
+++ b/libc/nptl/sockperf.c
@@ -0,0 +1,594 @@
+#define _GNU_SOURCE
+#include <argp.h>
+#include <complex.h>
+#include <errno.h>
+#include <error.h>
+#include <fcntl.h>
+#include <gd.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/param.h>
+#include <sys/poll.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+
+#define size_x 320
+#define size_y 240
+
+
+#define PATH "/tmp/s.sockperf"
+
+
+struct thread_param
+{
+ unsigned int from;
+ unsigned int to;
+ unsigned int nserv;
+};
+
+struct coord
+{
+ unsigned int x;
+ unsigned int y;
+ complex double z;
+};
+
+
+/* We use 64bit values for the times. */
+typedef unsigned long long int hp_timing_t;
+
+
+static unsigned int nclients = 2;
+static unsigned int nservers = 2;
+
+static bool timing;
+static int points;
+
+
+static complex double top_left = -0.7 + 0.2i;
+static complex double bottom_right = -0.5 - 0.0i;
+
+
+static int colors[256];
+static gdImagePtr image;
+static pthread_mutex_t image_lock;
+
+static int sock;
+
+
+static void *
+client (void *arg)
+{
+ struct thread_param *param = arg;
+ unsigned int cnt;
+ unsigned int nserv = param->nserv;
+ int clisock[nserv];
+ struct pollfd servpoll[nserv];
+ struct sockaddr_un servaddr;
+ socklen_t servlen;
+ struct coord c;
+
+ bool new_coord (void)
+ {
+ if (cnt >= param->to)
+ return false;
+
+ unsigned int row = cnt / size_x;
+ unsigned int col = cnt % size_x;
+
+ c.x = col;
+ c.y = row;
+ c.z = (top_left
+ + ((col
+ * (creal (bottom_right) - creal (top_left))) / size_x)
+ + (_Complex_I * (row * (cimag (bottom_right) - cimag (top_left)))
+ / size_y));
+
+ ++cnt;
+
+ return true;
+ }
+
+
+ for (cnt = 0; cnt < nserv; ++cnt)
+ {
+ servpoll[cnt].fd = socket (AF_UNIX, SOCK_STREAM, 0);
+ if (clisock < 0)
+ {
+ puts ("cannot create socket in client");
+ return NULL;
+ }
+
+ memset (&servaddr, '\0', sizeof (servaddr));
+ servaddr.sun_family = AF_UNIX;
+ strncpy (servaddr.sun_path, PATH, sizeof (servaddr.sun_path));
+ servlen = offsetof (struct sockaddr_un, sun_path) + strlen (PATH) + 1;
+
+
+ int err;
+ while (1)
+ {
+ err = TEMP_FAILURE_RETRY (connect (servpoll[cnt].fd, &servaddr,
+ servlen));
+ if (err != -1 || errno != ECONNREFUSED)
+ break;
+
+ pthread_yield ();
+ }
+
+ if (err == -1)
+ {
+ printf ("cannot connect: %m (%d)\n", errno);
+ exit (1);
+ }
+
+ servpoll[cnt].events = POLLOUT;
+ servpoll[cnt].revents = 0;
+ }
+
+ cnt = param->from;
+
+ new_coord ();
+ bool z_valid = true;
+
+ while (1)
+ {
+ int i;
+ int n = poll (servpoll, nserv, -1);
+ if (n == -1)
+ {
+ puts ("poll returned error");
+ break;
+ }
+
+ bool cont = false;
+ for (i = 0; i < nserv && n > 0; ++i)
+ if (servpoll[i].revents != 0)
+ {
+ if (servpoll[i].revents == POLLIN)
+ {
+ unsigned int vals[3];
+ if (TEMP_FAILURE_RETRY (read (servpoll[i].fd, &vals,
+ sizeof (vals)))
+ != sizeof (vals))
+ {
+ puts ("read error in client");
+ return NULL;
+ }
+
+ pthread_mutex_lock (&image_lock);
+
+ gdImageSetPixel (image, vals[0], vals[1], vals[2]);
+ ++points;
+
+ pthread_mutex_unlock (&image_lock);
+
+ servpoll[i].events = POLLOUT;
+ }
+ else
+ {
+ if (servpoll[i].revents != POLLOUT)
+ printf ("revents: %hd != POLLOUT ???\n",
+ servpoll[i].revents);
+
+ if (z_valid)
+ {
+ if (TEMP_FAILURE_RETRY (write (servpoll[i].fd, &c,
+ sizeof (c))) != sizeof (c))
+ {
+ puts ("write error in client");
+ return NULL;
+ }
+ cont = true;
+ servpoll[i].events = POLLIN;
+
+ z_valid = new_coord ();
+ if (! z_valid)
+ /* No more to do. Clear the event fields. */
+ for (i = 0; i < nserv; ++i)
+ if (servpoll[i].events == POLLOUT)
+ servpoll[i].events = servpoll[i].revents = 0;
+ }
+ else
+ servpoll[i].events = servpoll[i].revents = 0;
+ }
+
+ --n;
+ }
+ else if (servpoll[i].events != 0)
+ cont = true;
+
+ if (! cont && ! z_valid)
+ break;
+ }
+
+ c.x = 0xffffffff;
+ c.y = 0xffffffff;
+ for (cnt = 0; cnt < nserv; ++cnt)
+ {
+ TEMP_FAILURE_RETRY (write (servpoll[cnt].fd, &c, sizeof (c)));
+ close (servpoll[cnt].fd);
+ }
+
+ return NULL;
+}
+
+
+static void *
+server (void *arg)
+{
+ struct sockaddr_un cliaddr;
+ socklen_t clilen;
+ int clisock = TEMP_FAILURE_RETRY (accept (sock, &cliaddr, &clilen));
+
+ if (clisock == -1)
+ {
+ puts ("accept failed");
+ return NULL;
+ }
+
+ while (1)
+ {
+ struct coord c;
+
+ if (TEMP_FAILURE_RETRY (read (clisock, &c, sizeof (c))) != sizeof (c))
+ {
+ printf ("server read failed: %m (%d)\n", errno);
+ break;
+ }
+
+ if (c.x == 0xffffffff && c.y == 0xffffffff)
+ break;
+
+ unsigned int rnds = 0;
+ complex double z = c.z;
+ while (cabs (z) < 4.0)
+ {
+ z = z * z - 1;
+ if (++rnds == 255)
+ break;
+ }
+
+ unsigned int vals[3] = { c.x, c.y, rnds };
+ if (TEMP_FAILURE_RETRY (write (clisock, vals, sizeof (vals)))
+ != sizeof (vals))
+ {
+ puts ("server write error");
+ return NULL;
+ }
+ }
+
+ close (clisock);
+
+ return NULL;
+}
+
+
+static const char *outfilename = "test.png";
+
+
+static const struct argp_option options[] =
+ {
+ { "clients", 'c', "NUMBER", 0, "Number of client threads" },
+ { "servers", 's', "NUMBER", 0, "Number of server threads per client" },
+ { "timing", 'T', NULL, 0,
+ "Measure time from startup to the last thread finishing" },
+ { NULL, 0, NULL, 0, NULL }
+ };
+
+/* Prototype for option handler. */
+static error_t parse_opt (int key, char *arg, struct argp_state *state);
+
+/* Data structure to communicate with argp functions. */
+static struct argp argp =
+{
+ options, parse_opt
+};
+
+
+int
+main (int argc, char *argv[])
+{
+ int cnt;
+ FILE *outfile;
+ struct sockaddr_un servaddr;
+ socklen_t servlen;
+ int remaining;
+
+ /* Parse and process arguments. */
+ argp_parse (&argp, argc, argv, 0, &remaining, NULL);
+
+
+ pthread_t servth[nservers * nclients];
+ pthread_t clntth[nclients];
+ struct thread_param clntparam[nclients];
+
+
+ image = gdImageCreate (size_x, size_y);
+ if (image == NULL)
+ {
+ puts ("gdImageCreate failed");
+ return 1;
+ }
+
+ for (cnt = 0; cnt < 255; ++cnt)
+ colors[cnt] = gdImageColorAllocate (image, 256 - cnt, 256 - cnt,
+ 256 - cnt);
+ /* Black. */
+ colors[cnt] = gdImageColorAllocate (image, 0, 0, 0);
+
+
+ sock = socket (AF_UNIX, SOCK_STREAM, 0);
+ if (sock < 0)
+ error (EXIT_FAILURE, errno, "cannot create socket");
+
+ memset (&servaddr, '\0', sizeof (servaddr));
+ servaddr.sun_family = AF_UNIX;
+ strncpy (servaddr.sun_path, PATH, sizeof (servaddr.sun_path));
+ servlen = offsetof (struct sockaddr_un, sun_path) + strlen (PATH) + 1;
+
+ if (bind (sock, &servaddr, servlen) == -1)
+ error (EXIT_FAILURE, errno, "bind failed");
+
+ listen (sock, SOMAXCONN);
+
+ pthread_mutex_init (&image_lock, NULL);
+
+
+ struct sigaction sa;
+ sa.sa_handler = SIG_IGN;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = 0;
+
+ clockid_t cl;
+ struct timespec start_time;
+ if (timing)
+ {
+ if (clock_getcpuclockid (0, &cl) != 0
+ || clock_gettime (cl, &start_time) != 0)
+ timing = false;
+ }
+
+ /* Start the servers. */
+ for (cnt = 0; cnt < nservers * nclients; ++cnt)
+ {
+ if (pthread_create (&servth[cnt], NULL, server, NULL) != 0)
+ {
+ puts ("pthread_create for server failed");
+ exit (1);
+ }
+ }
+
+ for (cnt = 0; cnt < nclients; ++cnt)
+ {
+ clntparam[cnt].from = cnt * (size_x * size_y) / nclients;
+ clntparam[cnt].to = MIN ((cnt + 1) * (size_x * size_y) / nclients,
+ size_x * size_y);
+ clntparam[cnt].nserv = nservers;
+
+ if (pthread_create (&clntth[cnt], NULL, client, &clntparam[cnt]) != 0)
+ {
+ puts ("pthread_create for client failed");
+ exit (1);
+ }
+ }
+
+
+ /* Wait for the clients. */
+ for (cnt = 0; cnt < nclients; ++cnt)
+ if (pthread_join (clntth[cnt], NULL) != 0)
+ {
+ puts ("client pthread_join failed");
+ exit (1);
+ }
+
+ /* Wait for the servers. */
+ for (cnt = 0; cnt < nclients * nservers; ++cnt)
+ if (pthread_join (servth[cnt], NULL) != 0)
+ {
+ puts ("server pthread_join failed");
+ exit (1);
+ }
+
+
+ if (timing)
+ {
+ struct timespec end_time;
+
+ if (clock_gettime (cl, &end_time) == 0)
+ {
+ end_time.tv_sec -= start_time.tv_sec;
+ end_time.tv_nsec -= start_time.tv_nsec;
+ if (end_time.tv_nsec < 0)
+ {
+ end_time.tv_nsec += 1000000000;
+ --end_time.tv_sec;
+ }
+
+ printf ("\nRuntime: %lu.%09lu seconds\n%d points computed\n",
+ (unsigned long int) end_time.tv_sec,
+ (unsigned long int) end_time.tv_nsec,
+ points);
+ }
+ }
+
+
+ outfile = fopen (outfilename, "w");
+ if (outfile == NULL)
+ error (EXIT_FAILURE, errno, "cannot open output file '%s'", outfilename);
+
+ gdImagePng (image, outfile);
+
+ fclose (outfile);
+
+ unlink (PATH);
+
+ return 0;
+}
+
+
+/* Handle program arguments. */
+static error_t
+parse_opt (int key, char *arg, struct argp_state *state)
+{
+ switch (key)
+ {
+ case 'c':
+ nclients = strtoul (arg, NULL, 0);
+ break;
+
+ case 's':
+ nservers = strtoul (arg, NULL, 0);
+ break;
+
+ case 'T':
+ timing = true;
+ break;
+
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+
+ return 0;
+}
+
+
+static hp_timing_t
+get_clockfreq (void)
+{
+ /* We read the information from the /proc filesystem. It contains at
+ least one line like
+ cpu MHz : 497.840237
+ or also
+ cpu MHz : 497.841
+ We search for this line and convert the number in an integer. */
+ static hp_timing_t result;
+ int fd;
+
+ /* If this function was called before, we know the result. */
+ if (result != 0)
+ return result;
+
+ fd = open ("/proc/cpuinfo", O_RDONLY);
+ if (__builtin_expect (fd != -1, 1))
+ {
+ /* XXX AFAIK the /proc filesystem can generate "files" only up
+ to a size of 4096 bytes. */
+ char buf[4096];
+ ssize_t n;
+
+ n = read (fd, buf, sizeof buf);
+ if (__builtin_expect (n, 1) > 0)
+ {
+ char *mhz = memmem (buf, n, "cpu MHz", 7);
+
+ if (__builtin_expect (mhz != NULL, 1))
+ {
+ char *endp = buf + n;
+ int seen_decpoint = 0;
+ int ndigits = 0;
+
+ /* Search for the beginning of the string. */
+ while (mhz < endp && (*mhz < '0' || *mhz > '9') && *mhz != '\n')
+ ++mhz;
+
+ while (mhz < endp && *mhz != '\n')
+ {
+ if (*mhz >= '0' && *mhz <= '9')
+ {
+ result *= 10;
+ result += *mhz - '0';
+ if (seen_decpoint)
+ ++ndigits;
+ }
+ else if (*mhz == '.')
+ seen_decpoint = 1;
+
+ ++mhz;
+ }
+
+ /* Compensate for missing digits at the end. */
+ while (ndigits++ < 6)
+ result *= 10;
+ }
+ }
+
+ close (fd);
+ }
+
+ return result;
+}
+
+
+int
+clock_getcpuclockid (pid_t pid, clockid_t *clock_id)
+{
+ /* We don't allow any process ID but our own. */
+ if (pid != 0 && pid != getpid ())
+ return EPERM;
+
+#ifdef CLOCK_PROCESS_CPUTIME_ID
+ /* Store the number. */
+ *clock_id = CLOCK_PROCESS_CPUTIME_ID;
+
+ return 0;
+#else
+ /* We don't have a timer for that. */
+ return ENOENT;
+#endif
+}
+
+
+#define HP_TIMING_NOW(Var) __asm__ __volatile__ ("rdtsc" : "=A" (Var))
+
+/* Get current value of CLOCK and store it in TP. */
+int
+clock_gettime (clockid_t clock_id, struct timespec *tp)
+{
+ int retval = -1;
+
+ switch (clock_id)
+ {
+ case CLOCK_PROCESS_CPUTIME_ID:
+ {
+
+ static hp_timing_t freq;
+ hp_timing_t tsc;
+
+ /* Get the current counter. */
+ HP_TIMING_NOW (tsc);
+
+ if (freq == 0)
+ {
+ freq = get_clockfreq ();
+ if (freq == 0)
+ return EINVAL;
+ }
+
+ /* Compute the seconds. */
+ tp->tv_sec = tsc / freq;
+
+ /* And the nanoseconds. This computation should be stable until
+ we get machines with about 16GHz frequency. */
+ tp->tv_nsec = ((tsc % freq) * UINT64_C (1000000000)) / freq;
+
+ retval = 0;
+ }
+ break;
+
+ default:
+ errno = EINVAL;
+ break;
+ }
+
+ return retval;
+}
diff --git a/libc/nptl/sysdeps/alpha/Makefile b/libc/nptl/sysdeps/alpha/Makefile
new file mode 100644
index 000000000..88c106bbb
--- /dev/null
+++ b/libc/nptl/sysdeps/alpha/Makefile
@@ -0,0 +1,21 @@
+# Copyright (C) 2003 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+#
+# 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.
+
+ifeq ($(subdir),csu)
+gen-as-const-headers += tcb-offsets.sym
+endif
diff --git a/libc/nptl/sysdeps/alpha/elf/pt-initfini.c b/libc/nptl/sysdeps/alpha/elf/pt-initfini.c
new file mode 100644
index 000000000..ba2e419d6
--- /dev/null
+++ b/libc/nptl/sysdeps/alpha/elf/pt-initfini.c
@@ -0,0 +1,89 @@
+/* Special .init and .fini section support for Alpha. NPTL version.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+/* This file is compiled into assembly code which is then munged by a sed
+ script into two files: crti.s and crtn.s.
+
+ * crti.s puts a function prologue at the beginning of the .init and .fini
+ sections and defines global symbols for those addresses, so they can be
+ called as functions.
+
+ * crtn.s puts the corresponding function epilogues in the .init and .fini
+ sections.
+
+ This differs from what would be generated by the generic code in that
+ we save and restore the GP within the function. In order for linker
+ relaxation to work, the value in the GP register on exit from a function
+ must be valid for the function entry point. Normally, a function is
+ contained within one object file and this is not an issue, provided
+ that the function reloads the gp after making any function calls.
+ However, _init and _fini are constructed from pieces of many object
+ files, all of which may have different GP values. So we must reload
+ the GP value from crti.o in crtn.o. */
+
+__asm__ (" \n\
+#include \"defs.h\" \n\
+ \n\
+/*@HEADER_ENDS*/ \n\
+ \n\
+/*@_init_PROLOG_BEGINS*/ \n\
+ .section .init, \"ax\", @progbits \n\
+ .globl _init \n\
+ .type _init,@function \n\
+ .usepv _init,std \n\
+_init: \n\
+ ldgp $29, 0($27) \n\
+ subq $30, 16, $30 \n\
+ stq $26, 0($30) \n\
+ stq $29, 8($30) \n\
+ bsr $26, __pthread_initialize_minimal_internal !samegp \n\
+ .align 3 \n\
+/*@_init_PROLOG_ENDS*/ \n\
+ \n\
+/*@_init_EPILOG_BEGINS*/ \n\
+ .section .init, \"ax\", @progbits \n\
+ ldq $26, 0($30) \n\
+ ldq $29, 8($30) \n\
+ addq $30, 16, $30 \n\
+ ret \n\
+/*@_init_EPILOG_ENDS*/ \n\
+ \n\
+/*@_fini_PROLOG_BEGINS*/ \n\
+ .section .fini, \"ax\", @progbits \n\
+ .globl _fini \n\
+ .type _fini,@function \n\
+ .usepv _fini,std \n\
+_fini: \n\
+ ldgp $29, 0($27) \n\
+ subq $30, 16, $30 \n\
+ stq $26, 0($30) \n\
+ stq $29, 8($30) \n\
+ .align 3 \n\
+/*@_fini_PROLOG_ENDS*/ \n\
+ \n\
+/*@_fini_EPILOG_BEGINS*/ \n\
+ .section .fini, \"ax\", @progbits \n\
+ ldq $26, 0($30) \n\
+ ldq $29, 8($30) \n\
+ addq $30, 16, $30 \n\
+ ret \n\
+/*@_fini_EPILOG_ENDS*/ \n\
+ \n\
+/*@TRAILER_BEGINS*/ \n\
+");
diff --git a/libc/nptl/sysdeps/alpha/pthread_spin_lock.S b/libc/nptl/sysdeps/alpha/pthread_spin_lock.S
new file mode 100644
index 000000000..ce6cd41a4
--- /dev/null
+++ b/libc/nptl/sysdeps/alpha/pthread_spin_lock.S
@@ -0,0 +1,45 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Richard Henderson <rth@twiddle.net>, 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. */
+
+
+ .text
+ .align 4
+
+ .globl pthread_spin_lock
+ .ent pthread_spin_lock
+pthread_spin_lock:
+ .frame $sp, 0, $26, 0
+ .prologue 0
+
+0: ldl_l $1, 0($16)
+ lda $2, 1
+ lda $0, 0
+ bne $1, 1f
+
+ stl_c $2, 0($16)
+ beq $2, 1f
+ mb
+ ret
+
+1: ldl $1, 0($16)
+ bne $1, 1b
+ unop
+ br 0b
+
+ .end pthread_spin_lock
diff --git a/libc/nptl/sysdeps/alpha/pthread_spin_trylock.S b/libc/nptl/sysdeps/alpha/pthread_spin_trylock.S
new file mode 100644
index 000000000..0948da698
--- /dev/null
+++ b/libc/nptl/sysdeps/alpha/pthread_spin_trylock.S
@@ -0,0 +1,46 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Richard Henderson <rth@twiddle.net>, 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. */
+
+
+#define _ERRNO_H 1
+#include <bits/errno.h>
+
+ .text
+ .align 4
+
+ .globl pthread_spin_trylock
+ .ent pthread_spin_trylock
+pthread_spin_trylock:
+ .frame $sp, 0, $26, 0
+ .prologue 0
+
+0: ldl_l $1, 0($16)
+ lda $2, 1
+ lda $0, EBUSY
+ bne $1, 1f
+
+ stl_c $2, 0($16)
+ beq $2, 2f
+ mb
+ lda $0, 0
+
+1: ret
+2: br 0b
+
+ .end pthread_spin_trylock
diff --git a/libc/nptl/sysdeps/alpha/pthreaddef.h b/libc/nptl/sysdeps/alpha/pthreaddef.h
new file mode 100644
index 000000000..26c4daf7b
--- /dev/null
+++ b/libc/nptl/sysdeps/alpha/pthreaddef.h
@@ -0,0 +1,38 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+/* Default stack size. */
+#define ARCH_STACK_DEFAULT_SIZE (4 * 1024 * 1024)
+
+/* Required stack pointer alignment at beginning. The ABI requires 16. */
+#define STACK_ALIGN 16
+
+/* Minimal stack size after allocating thread descriptor and guard size. */
+#define MINIMAL_REST_STACK 4096
+
+/* Alignment requirement for TCB. */
+#define TCB_ALIGNMENT 16
+
+/* Location of current stack frame. */
+#define CURRENT_STACK_FRAME __builtin_frame_address (0)
+
+/* XXX Until we have a better place keep the definitions here. */
+
+/* While there is no such syscall. */
+#define __exit_thread_inline(val) \
+ INLINE_SYSCALL (exit, 1, (val))
diff --git a/libc/nptl/sysdeps/alpha/tcb-offsets.sym b/libc/nptl/sysdeps/alpha/tcb-offsets.sym
new file mode 100644
index 000000000..c21a79104
--- /dev/null
+++ b/libc/nptl/sysdeps/alpha/tcb-offsets.sym
@@ -0,0 +1,14 @@
+#include <sysdep.h>
+#include <tls.h>
+
+--
+
+-- Abuse tls.h macros to derive offsets relative to the thread register.
+-- # define __builtin_thread_pointer() ((void *) 0)
+-- # define thread_offsetof(mem) ((void *) &THREAD_SELF->mem - (void *) 0)
+-- Ho hum, this doesn't work in gcc4, so Know Things about THREAD_SELF
+#define thread_offsetof(mem) (long)(offsetof(struct pthread, mem) - sizeof(struct pthread))
+
+MULTIPLE_THREADS_OFFSET thread_offsetof (header.multiple_threads)
+PID_OFFSET thread_offsetof (pid)
+TID_OFFSET thread_offsetof (tid)
diff --git a/libc/nptl/sysdeps/alpha/tls.h b/libc/nptl/sysdeps/alpha/tls.h
new file mode 100644
index 000000000..20f780c5f
--- /dev/null
+++ b/libc/nptl/sysdeps/alpha/tls.h
@@ -0,0 +1,129 @@
+/* Definition for thread-local data handling. NPTL/Alpha version.
+ Copyright (C) 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+#ifndef _TLS_H
+#define _TLS_H 1
+
+# include <dl-sysdep.h>
+
+#ifndef __ASSEMBLER__
+# include <stdbool.h>
+# include <stddef.h>
+# include <stdint.h>
+
+/* Type for the dtv. */
+typedef union dtv
+{
+ size_t counter;
+ struct
+ {
+ void *val;
+ bool is_static;
+ } pointer;
+} dtv_t;
+
+#else /* __ASSEMBLER__ */
+# include <tcb-offsets.h>
+#endif /* __ASSEMBLER__ */
+
+
+/* We require TLS support in the tools. */
+#ifndef HAVE_TLS_SUPPORT
+# error "TLS support is required."
+#endif
+
+/* Signal that TLS support is available. */
+# define USE_TLS 1
+
+#ifndef __ASSEMBLER__
+
+/* Get system call information. */
+# include <sysdep.h>
+
+/* The TP points to the start of the thread blocks. */
+# define TLS_DTV_AT_TP 1
+
+/* Get the thread descriptor definition. */
+# include <nptl/descr.h>
+
+typedef struct
+{
+ dtv_t *dtv;
+ void *__private;
+} tcbhead_t;
+
+/* This is the size of the initial TCB. */
+# define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
+
+/* Alignment requirements for the initial TCB. */
+# define TLS_INIT_TCB_ALIGN 16
+
+/* This is the size of the TCB. */
+# define TLS_TCB_SIZE sizeof (tcbhead_t)
+
+/* This is the size we need before TCB. */
+# define TLS_PRE_TCB_SIZE sizeof (struct pthread)
+
+/* Alignment requirements for the TCB. */
+# define TLS_TCB_ALIGN 16
+
+/* Install the dtv pointer. The pointer passed is to the element with
+ index -1 which contain the length. */
+# define INSTALL_DTV(tcbp, dtvp) \
+ (((tcbhead_t *) (tcbp))->dtv = (dtvp) + 1)
+
+/* Install new dtv for current thread. */
+# define INSTALL_NEW_DTV(dtv) \
+ (THREAD_DTV() = (dtv))
+
+/* Return dtv of given thread descriptor. */
+# define GET_DTV(tcbp) \
+ (((tcbhead_t *) (tcbp))->dtv)
+
+/* Code to initially initialize the thread pointer. This might need
+ special attention since 'errno' is not yet available and if the
+ operation can cause a failure 'errno' must not be touched. */
+# define TLS_INIT_TP(tcbp, secondcall) \
+ (__builtin_set_thread_pointer ((void *)(tcbp)), NULL)
+
+/* Return the address of the dtv for the current thread. */
+# define THREAD_DTV() \
+ (((tcbhead_t *) __builtin_thread_pointer ())->dtv)
+
+/* Return the thread descriptor for the current thread. */
+# define THREAD_SELF \
+ ((struct pthread *)__builtin_thread_pointer () - 1)
+
+/* Magic for libthread_db to know how to do THREAD_SELF. */
+# define DB_THREAD_SELF \
+ REGISTER (64, 64, 32 * 8, -sizeof (struct pthread))
+
+/* Access to data in the thread descriptor is easy. */
+#define THREAD_GETMEM(descr, member) \
+ descr->member
+#define THREAD_GETMEM_NC(descr, member, idx) \
+ descr->member[idx]
+#define THREAD_SETMEM(descr, member, value) \
+ descr->member = (value)
+#define THREAD_SETMEM_NC(descr, member, idx, value) \
+ descr->member[idx] = (value)
+
+#endif /* __ASSEMBLER__ */
+
+#endif /* tls.h */
diff --git a/libc/nptl/sysdeps/i386/Makefile b/libc/nptl/sysdeps/i386/Makefile
new file mode 100644
index 000000000..2f0d88f30
--- /dev/null
+++ b/libc/nptl/sysdeps/i386/Makefile
@@ -0,0 +1,27 @@
+# Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# 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.
+
+ifeq ($(subdir),csu)
+gen-as-const-headers += tcb-offsets.sym
+endif
+
+ifeq ($(subdir),nptl)
+CFLAGS-pthread_create.c += -mpreferred-stack-boundary=4
+CFLAGS-tst-align.c += -mpreferred-stack-boundary=4
+CFLAGS-tst-align2.c += -mpreferred-stack-boundary=4
+endif
diff --git a/libc/nptl/sysdeps/i386/i486/pthread_spin_trylock.S b/libc/nptl/sysdeps/i386/i486/pthread_spin_trylock.S
new file mode 100644
index 000000000..e30072c3d
--- /dev/null
+++ b/libc/nptl/sysdeps/i386/i486/pthread_spin_trylock.S
@@ -0,0 +1,47 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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-errnos.h>
+
+
+#ifdef UP
+# define LOCK
+#else
+# define LOCK lock
+#endif
+
+ .globl pthread_spin_trylock
+ .type pthread_spin_trylock,@function
+ .align 16
+pthread_spin_trylock:
+ movl 4(%esp), %edx
+ movl $1, %eax
+ xorl %ecx, %ecx
+ LOCK
+ cmpxchgl %ecx, (%edx)
+ movl $EBUSY, %eax
+#ifdef HAVE_CMOV
+ cmovel %ecx, %eax
+#else
+ jne 0f
+ movl %ecx, %eax
+0:
+#endif
+ ret
+ .size pthread_spin_trylock,.-pthread_spin_trylock
diff --git a/libc/nptl/sysdeps/i386/i586/pthread_spin_trylock.S b/libc/nptl/sysdeps/i386/i586/pthread_spin_trylock.S
new file mode 100644
index 000000000..ffe3d456b
--- /dev/null
+++ b/libc/nptl/sysdeps/i386/i586/pthread_spin_trylock.S
@@ -0,0 +1,20 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "../i486/pthread_spin_trylock.S"
diff --git a/libc/nptl/sysdeps/i386/i686/Makefile b/libc/nptl/sysdeps/i386/i686/Makefile
new file mode 100644
index 000000000..137c0a2f0
--- /dev/null
+++ b/libc/nptl/sysdeps/i386/i686/Makefile
@@ -0,0 +1,32 @@
+# Copyright (C) 2003 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+# Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+# 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.
+
+ifeq ($(subdir),nptl)
+# It turns out that stack coloring is in general not good on P4s. Some
+# applications will benefit. We will probably have a configuration option
+# at some point. Enabling coloring can be done with
+#
+# -DCOLORING_INCREMENT=128
+#
+# What is useful is to avoid the 64k aliasing problem which reliably
+# happens if all stacks use sizes which are a multiple of 64k. Tell
+# the stack allocator to disturb this by allocation one more page if
+# necessary.
+CFLAGS-pthread_create.c += -DMULTI_PAGE_ALIASING=65536
+endif
diff --git a/libc/nptl/sysdeps/i386/i686/pthread_spin_trylock.S b/libc/nptl/sysdeps/i386/i686/pthread_spin_trylock.S
new file mode 100644
index 000000000..a5d861f92
--- /dev/null
+++ b/libc/nptl/sysdeps/i386/i686/pthread_spin_trylock.S
@@ -0,0 +1,21 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+#define HAVE_CMOV 1
+#include "../i486/pthread_spin_trylock.S"
diff --git a/libc/nptl/sysdeps/i386/i686/tls.h b/libc/nptl/sysdeps/i386/i686/tls.h
new file mode 100644
index 000000000..4025ed8d2
--- /dev/null
+++ b/libc/nptl/sysdeps/i386/i686/tls.h
@@ -0,0 +1,36 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+#ifndef _TLS_H
+
+/* Additional definitions for <tls.h> on i686 and up. */
+
+
+/* Macros to load from and store into segment registers. We can use
+ the 32-bit instructions. */
+#define TLS_GET_GS() \
+ ({ int __seg; __asm ("movl %%gs, %0" : "=q" (__seg)); __seg; })
+#define TLS_SET_GS(val) \
+ __asm ("movl %0, %%gs" :: "q" (val))
+
+
+/* Get the full set of definitions. */
+#include "../tls.h"
+
+#endif /* tls.h */
diff --git a/libc/nptl/sysdeps/i386/pthread_spin_init.c b/libc/nptl/sysdeps/i386/pthread_spin_init.c
new file mode 100644
index 000000000..0a47981aa
--- /dev/null
+++ b/libc/nptl/sysdeps/i386/pthread_spin_init.c
@@ -0,0 +1,20 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+/* Not needed. pthread_spin_init is an alias for pthread_spin_unlock. */
diff --git a/libc/nptl/sysdeps/i386/pthread_spin_lock.c b/libc/nptl/sysdeps/i386/pthread_spin_lock.c
new file mode 100644
index 000000000..b41174e5f
--- /dev/null
+++ b/libc/nptl/sysdeps/i386/pthread_spin_lock.c
@@ -0,0 +1,49 @@
+/* Copyright (C) 2002,2003,2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "pthreadP.h"
+
+#ifndef LOCK_PREFIX
+# ifdef UP
+# define LOCK_PREFIX /* nothing */
+# else
+# define LOCK_PREFIX "lock;"
+# endif
+#endif
+
+
+int
+pthread_spin_lock (lock)
+ pthread_spinlock_t *lock;
+{
+ asm ("\n"
+ "1:\t" LOCK_PREFIX "decl %0\n\t"
+ "jne 2f\n\t"
+ ".subsection 1\n\t"
+ ".align 16\n"
+ "2:\trep; nop\n\t"
+ "cmpl $0, %0\n\t"
+ "jg 1b\n\t"
+ "jmp 2b\n\t"
+ ".previous"
+ : "=m" (*lock)
+ : "m" (*lock));
+
+ return 0;
+}
diff --git a/libc/nptl/sysdeps/i386/pthread_spin_unlock.S b/libc/nptl/sysdeps/i386/pthread_spin_unlock.S
new file mode 100644
index 000000000..d94f1e7b8
--- /dev/null
+++ b/libc/nptl/sysdeps/i386/pthread_spin_unlock.S
@@ -0,0 +1,32 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+ .globl pthread_spin_unlock
+ .type pthread_spin_unlock,@function
+ .align 16
+pthread_spin_unlock:
+ movl 4(%esp), %eax
+ movl $1, (%eax)
+ xorl %eax, %eax
+ ret
+ .size pthread_spin_unlock,.-pthread_spin_unlock
+
+ /* The implementation of pthread_spin_init is identical. */
+ .globl pthread_spin_init
+pthread_spin_init = pthread_spin_unlock
diff --git a/libc/nptl/sysdeps/i386/pthreaddef.h b/libc/nptl/sysdeps/i386/pthreaddef.h
new file mode 100644
index 000000000..43b771c6d
--- /dev/null
+++ b/libc/nptl/sysdeps/i386/pthreaddef.h
@@ -0,0 +1,48 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+/* Default stack size. */
+#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024)
+
+/* Required stack pointer alignment at beginning. SSE requires 16
+ bytes. */
+#define STACK_ALIGN 16
+
+/* Minimal stack size after allocating thread descriptor and guard size. */
+#define MINIMAL_REST_STACK 2048
+
+/* Alignment requirement for TCB. */
+#define TCB_ALIGNMENT 16
+
+
+/* Location of current stack frame. */
+#define CURRENT_STACK_FRAME __builtin_frame_address (0)
+
+
+/* XXX Until we have a better place keep the definitions here. */
+
+/* While there is no such syscall. */
+#define __exit_thread_inline(val) \
+ while (1) { \
+ if (__builtin_constant_p (val) && (val) == 0) \
+ asm volatile ("xorl %%ebx, %%ebx; int $0x80" :: "a" (__NR_exit)); \
+ else \
+ asm volatile ("movl %1, %%ebx; int $0x80" \
+ :: "a" (__NR_exit), "r" (val)); \
+ }
diff --git a/libc/nptl/sysdeps/i386/tcb-offsets.sym b/libc/nptl/sysdeps/i386/tcb-offsets.sym
new file mode 100644
index 000000000..7c8d9a5ca
--- /dev/null
+++ b/libc/nptl/sysdeps/i386/tcb-offsets.sym
@@ -0,0 +1,14 @@
+#include <sysdep.h>
+#include <tls.h>
+
+RESULT offsetof (struct pthread, result)
+TID offsetof (struct pthread, tid)
+PID offsetof (struct pthread, pid)
+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)
+CLEANUP_PREV offsetof (struct _pthread_cleanup_buffer, __prev)
+MUTEX_FUTEX offsetof (pthread_mutex_t, __data.__lock)
+POINTER_GUARD offsetof (tcbhead_t, pointer_guard)
diff --git a/libc/nptl/sysdeps/i386/tls.h b/libc/nptl/sysdeps/i386/tls.h
new file mode 100644
index 000000000..a870a848c
--- /dev/null
+++ b/libc/nptl/sysdeps/i386/tls.h
@@ -0,0 +1,439 @@
+/* Definition for thread-local data handling. nptl/i386 version.
+ Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+#ifndef _TLS_H
+#define _TLS_H 1
+
+#include <dl-sysdep.h>
+#ifndef __ASSEMBLER__
+# include <stdbool.h>
+# include <stddef.h>
+# include <stdint.h>
+# include <stdlib.h>
+# include <list.h>
+
+
+/* Type for the dtv. */
+typedef union dtv
+{
+ size_t counter;
+ struct
+ {
+ void *val;
+ bool is_static;
+ } pointer;
+} dtv_t;
+
+
+typedef struct
+{
+ void *tcb; /* Pointer to the TCB. Not necessarily the
+ thread descriptor used by libpthread. */
+ dtv_t *dtv;
+ void *self; /* Pointer to the thread descriptor. */
+ int multiple_threads;
+ uintptr_t sysinfo;
+ uintptr_t stack_guard;
+ uintptr_t pointer_guard;
+} tcbhead_t;
+
+# define TLS_MULTIPLE_THREADS_IN_TCB 1
+
+#else /* __ASSEMBLER__ */
+# include <tcb-offsets.h>
+#endif
+
+
+/* We require TLS support in the tools. */
+#ifndef HAVE_TLS_SUPPORT
+# error "TLS support is required."
+#endif
+
+/* Signal that TLS support is available. */
+#define USE_TLS 1
+
+/* Alignment requirement for the stack. For IA-32 this is governed by
+ the SSE memory functions. */
+#define STACK_ALIGN 16
+
+#ifndef __ASSEMBLER__
+/* Get system call information. */
+# include <sysdep.h>
+
+/* The old way: using LDT. */
+
+/* Structure passed to `modify_ldt', 'set_thread_area', and 'clone' calls. */
+struct user_desc
+{
+ unsigned int entry_number;
+ unsigned long int base_addr;
+ unsigned int limit;
+ unsigned int seg_32bit:1;
+ unsigned int contents:2;
+ unsigned int read_exec_only:1;
+ unsigned int limit_in_pages:1;
+ unsigned int seg_not_present:1;
+ unsigned int useable:1;
+ unsigned int empty:25;
+};
+
+/* Initializing bit fields is slow. We speed it up by using a union. */
+union user_desc_init
+{
+ struct user_desc desc;
+ unsigned int vals[4];
+};
+
+
+/* Get the thread descriptor definition. */
+# include <nptl/descr.h>
+
+/* This is the size of the initial TCB. Can't be just sizeof (tcbhead_t),
+ because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
+ struct pthread even when not linked with -lpthread. */
+# define TLS_INIT_TCB_SIZE sizeof (struct pthread)
+
+/* Alignment requirements for the initial TCB. */
+# define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
+
+/* This is the size of the TCB. */
+# define TLS_TCB_SIZE sizeof (struct pthread)
+
+/* Alignment requirements for the TCB. */
+# define TLS_TCB_ALIGN __alignof__ (struct pthread)
+
+/* The TCB can have any size and the memory following the address the
+ thread pointer points to is unspecified. Allocate the TCB there. */
+# define TLS_TCB_AT_TP 1
+
+
+/* Install the dtv pointer. The pointer passed is to the element with
+ index -1 which contain the length. */
+# define INSTALL_DTV(descr, dtvp) \
+ ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
+
+/* Install new dtv for current thread. */
+# define INSTALL_NEW_DTV(dtvp) \
+ ({ struct pthread *__pd; \
+ THREAD_SETMEM (__pd, header.dtv, (dtvp)); })
+
+/* Return dtv of given thread descriptor. */
+# define GET_DTV(descr) \
+ (((tcbhead_t *) (descr))->dtv)
+
+#define THREAD_SELF_SYSINFO THREAD_GETMEM (THREAD_SELF, header.sysinfo)
+#define THREAD_SYSINFO(pd) ((pd)->header.sysinfo)
+
+/* Macros to load from and store into segment registers. */
+# ifndef TLS_GET_GS
+# define TLS_GET_GS() \
+ ({ int __seg; __asm ("movw %%gs, %w0" : "=q" (__seg)); __seg & 0xffff; })
+# endif
+# ifndef TLS_SET_GS
+# define TLS_SET_GS(val) \
+ __asm ("movw %w0, %%gs" :: "q" (val))
+# endif
+
+
+# ifndef __NR_set_thread_area
+# define __NR_set_thread_area 243
+# endif
+# ifndef TLS_FLAG_WRITABLE
+# define TLS_FLAG_WRITABLE 0x00000001
+# endif
+
+// XXX Enable for the real world.
+#if 0
+# ifndef __ASSUME_SET_THREAD_AREA
+# error "we need set_thread_area"
+# endif
+#endif
+
+# ifdef __PIC__
+# define TLS_EBX_ARG "r"
+# define TLS_LOAD_EBX "xchgl %3, %%ebx\n\t"
+# else
+# define TLS_EBX_ARG "b"
+# define TLS_LOAD_EBX
+# endif
+
+#if defined NEED_DL_SYSINFO
+# define INIT_SYSINFO \
+ _head->sysinfo = GLRO(dl_sysinfo)
+#else
+# define INIT_SYSINFO
+#endif
+
+#ifndef LOCK_PREFIX
+# ifdef UP
+# define LOCK_PREFIX /* nothing */
+# else
+# define LOCK_PREFIX "lock;"
+# endif
+#endif
+
+/* Code to initially initialize the thread pointer. This might need
+ special attention since 'errno' is not yet available and if the
+ operation can cause a failure 'errno' must not be touched. */
+# define TLS_INIT_TP(thrdescr, secondcall) \
+ ({ void *_thrdescr = (thrdescr); \
+ tcbhead_t *_head = _thrdescr; \
+ union user_desc_init _segdescr; \
+ int _result; \
+ \
+ _head->tcb = _thrdescr; \
+ /* For now the thread descriptor is at the same address. */ \
+ _head->self = _thrdescr; \
+ /* New syscall handling support. */ \
+ INIT_SYSINFO; \
+ \
+ /* The 'entry_number' field. Let the kernel pick a value. */ \
+ if (secondcall) \
+ _segdescr.vals[0] = TLS_GET_GS () >> 3; \
+ else \
+ _segdescr.vals[0] = -1; \
+ /* The 'base_addr' field. Pointer to the TCB. */ \
+ _segdescr.vals[1] = (unsigned long int) _thrdescr; \
+ /* The 'limit' field. We use 4GB which is 0xfffff pages. */ \
+ _segdescr.vals[2] = 0xfffff; \
+ /* Collapsed value of the bitfield: \
+ .seg_32bit = 1 \
+ .contents = 0 \
+ .read_exec_only = 0 \
+ .limit_in_pages = 1 \
+ .seg_not_present = 0 \
+ .useable = 1 */ \
+ _segdescr.vals[3] = 0x51; \
+ \
+ /* Install the TLS. */ \
+ asm volatile (TLS_LOAD_EBX \
+ "int $0x80\n\t" \
+ TLS_LOAD_EBX \
+ : "=a" (_result), "=m" (_segdescr.desc.entry_number) \
+ : "0" (__NR_set_thread_area), \
+ TLS_EBX_ARG (&_segdescr.desc), "m" (_segdescr.desc)); \
+ \
+ if (_result == 0) \
+ /* We know the index in the GDT, now load the segment register. \
+ The use of the GDT is described by the value 3 in the lower \
+ three bits of the segment descriptor value. \
+ \
+ Note that we have to do this even if the numeric value of \
+ the descriptor does not change. Loading the segment register \
+ causes the segment information from the GDT to be loaded \
+ which is necessary since we have changed it. */ \
+ TLS_SET_GS (_segdescr.desc.entry_number * 8 + 3); \
+ \
+ _result == 0 ? NULL \
+ : "set_thread_area failed when setting up thread-local storage\n"; })
+
+
+/* Return the address of the dtv for the current thread. */
+# define THREAD_DTV() \
+ ({ struct pthread *__pd; \
+ THREAD_GETMEM (__pd, header.dtv); })
+
+
+/* Return the thread descriptor for the current thread.
+
+ The contained asm must *not* be marked volatile since otherwise
+ assignments like
+ pthread_descr self = thread_self();
+ do not get optimized away. */
+# define THREAD_SELF \
+ ({ struct pthread *__self; \
+ asm ("movl %%gs:%c1,%0" : "=r" (__self) \
+ : "i" (offsetof (struct pthread, header.self))); \
+ __self;})
+
+/* Magic for libthread_db to know how to do THREAD_SELF. */
+# define DB_THREAD_SELF \
+ REGISTER_THREAD_AREA (32, offsetof (struct user_regs_struct, xgs), 3) \
+ REGISTER_THREAD_AREA (64, 26 * 8, 3) /* x86-64's user_regs_struct->gs */
+
+
+/* Read member of the thread descriptor directly. */
+# define THREAD_GETMEM(descr, member) \
+ ({ __typeof (descr->member) __value; \
+ if (sizeof (__value) == 1) \
+ asm volatile ("movb %%gs:%P2,%b0" \
+ : "=q" (__value) \
+ : "0" (0), "i" (offsetof (struct pthread, member))); \
+ else if (sizeof (__value) == 4) \
+ asm volatile ("movl %%gs:%P1,%0" \
+ : "=r" (__value) \
+ : "i" (offsetof (struct pthread, member))); \
+ else \
+ { \
+ if (sizeof (__value) != 8) \
+ /* There should not be any value with a size other than 1, \
+ 4 or 8. */ \
+ abort (); \
+ \
+ asm volatile ("movl %%gs:%P1,%%eax\n\t" \
+ "movl %%gs:%P2,%%edx" \
+ : "=A" (__value) \
+ : "i" (offsetof (struct pthread, member)), \
+ "i" (offsetof (struct pthread, member) + 4)); \
+ } \
+ __value; })
+
+
+/* Same as THREAD_GETMEM, but the member offset can be non-constant. */
+# define THREAD_GETMEM_NC(descr, member, idx) \
+ ({ __typeof (descr->member[0]) __value; \
+ if (sizeof (__value) == 1) \
+ asm volatile ("movb %%gs:%P2(%3),%b0" \
+ : "=q" (__value) \
+ : "0" (0), "i" (offsetof (struct pthread, member[0])), \
+ "r" (idx)); \
+ else if (sizeof (__value) == 4) \
+ asm volatile ("movl %%gs:%P1(,%2,4),%0" \
+ : "=r" (__value) \
+ : "i" (offsetof (struct pthread, member[0])), \
+ "r" (idx)); \
+ else \
+ { \
+ if (sizeof (__value) != 8) \
+ /* There should not be any value with a size other than 1, \
+ 4 or 8. */ \
+ abort (); \
+ \
+ asm volatile ("movl %%gs:%P1(,%2,8),%%eax\n\t" \
+ "movl %%gs:4+%P1(,%2,8),%%edx" \
+ : "=&A" (__value) \
+ : "i" (offsetof (struct pthread, member[0])), \
+ "r" (idx)); \
+ } \
+ __value; })
+
+
+/* Same as THREAD_SETMEM, but the member offset can be non-constant. */
+# define THREAD_SETMEM(descr, member, value) \
+ ({ if (sizeof (descr->member) == 1) \
+ asm volatile ("movb %b0,%%gs:%P1" : \
+ : "iq" (value), \
+ "i" (offsetof (struct pthread, member))); \
+ else if (sizeof (descr->member) == 4) \
+ asm volatile ("movl %0,%%gs:%P1" : \
+ : "ir" (value), \
+ "i" (offsetof (struct pthread, member))); \
+ else \
+ { \
+ if (sizeof (descr->member) != 8) \
+ /* There should not be any value with a size other than 1, \
+ 4 or 8. */ \
+ abort (); \
+ \
+ asm volatile ("movl %%eax,%%gs:%P1\n\t" \
+ "movl %%edx,%%gs:%P2" : \
+ : "A" (value), \
+ "i" (offsetof (struct pthread, member)), \
+ "i" (offsetof (struct pthread, member) + 4)); \
+ }})
+
+
+/* Set member of the thread descriptor directly. */
+# define THREAD_SETMEM_NC(descr, member, idx, value) \
+ ({ if (sizeof (descr->member[0]) == 1) \
+ asm volatile ("movb %b0,%%gs:%P1(%2)" : \
+ : "iq" (value), \
+ "i" (offsetof (struct pthread, member)), \
+ "r" (idx)); \
+ else if (sizeof (descr->member[0]) == 4) \
+ asm volatile ("movl %0,%%gs:%P1(,%2,4)" : \
+ : "ir" (value), \
+ "i" (offsetof (struct pthread, member)), \
+ "r" (idx)); \
+ else \
+ { \
+ if (sizeof (descr->member[0]) != 8) \
+ /* There should not be any value with a size other than 1, \
+ 4 or 8. */ \
+ abort (); \
+ \
+ asm volatile ("movl %%eax,%%gs:%P1(,%2,8)\n\t" \
+ "movl %%edx,%%gs:4+%P1(,%2,8)" : \
+ : "A" (value), \
+ "i" (offsetof (struct pthread, member)), \
+ "r" (idx)); \
+ }})
+
+
+/* Atomic compare and exchange on TLS, returning old value. */
+#define THREAD_ATOMIC_CMPXCHG_VAL(descr, member, newval, oldval) \
+ ({ __typeof (descr->member) __ret; \
+ __typeof (oldval) __old = (oldval); \
+ if (sizeof (descr->member) == 4) \
+ asm volatile (LOCK_PREFIX "cmpxchgl %2, %%gs:%P3" \
+ : "=a" (__ret) \
+ : "0" (__old), "r" (newval), \
+ "i" (offsetof (struct pthread, member))); \
+ else \
+ /* Not necessary for other sizes in the moment. */ \
+ abort (); \
+ __ret; })
+
+
+/* Atomic set bit. */
+#define THREAD_ATOMIC_BIT_SET(descr, member, bit) \
+ (void) ({ if (sizeof ((descr)->member) == 4) \
+ asm volatile (LOCK_PREFIX "orl %1, %%gs:%P0" \
+ :: "i" (offsetof (struct pthread, member)), \
+ "ir" (1 << (bit))); \
+ else \
+ /* Not necessary for other sizes in the moment. */ \
+ abort (); })
+
+
+/* Call the user-provided thread function. */
+#define CALL_THREAD_FCT(descr) \
+ ({ void *__res; \
+ int __ignore1, __ignore2; \
+ asm volatile ("pushl %%eax\n\t" \
+ "pushl %%eax\n\t" \
+ "pushl %%eax\n\t" \
+ "pushl %%gs:%P4\n\t" \
+ "call *%%gs:%P3\n\t" \
+ "addl $16, %%esp" \
+ : "=a" (__res), "=c" (__ignore1), "=d" (__ignore2) \
+ : "i" (offsetof (struct pthread, start_routine)), \
+ "i" (offsetof (struct pthread, arg))); \
+ __res; })
+
+
+/* Set the stack guard field in TCB head. */
+#define THREAD_SET_STACK_GUARD(value) \
+ THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
+#define THREAD_COPY_STACK_GUARD(descr) \
+ ((descr)->header.stack_guard \
+ = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
+
+
+/* Set the pointer guard field in the TCB head. */
+#define THREAD_SET_POINTER_GUARD(value) \
+ THREAD_SETMEM (THREAD_SELF, header.pointer_guard, value)
+#define THREAD_COPY_POINTER_GUARD(descr) \
+ ((descr)->header.pointer_guard \
+ = THREAD_GETMEM (THREAD_SELF, header.pointer_guard))
+
+
+#endif /* __ASSEMBLER__ */
+
+#endif /* tls.h */
diff --git a/libc/nptl/sysdeps/ia64/Makefile b/libc/nptl/sysdeps/ia64/Makefile
new file mode 100644
index 000000000..3229d3f16
--- /dev/null
+++ b/libc/nptl/sysdeps/ia64/Makefile
@@ -0,0 +1,25 @@
+# Copyright (C) 2003 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# 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.
+
+ifeq ($(subdir),csu)
+gen-as-const-headers += tcb-offsets.sym
+endif
+
+ifeq ($(subdir),nptl)
+libpthread-routines += ptw-sysdep ptw-sigblock ptw-sigprocmask
+endif
diff --git a/libc/nptl/sysdeps/ia64/pthread_spin_lock.c b/libc/nptl/sysdeps/ia64/pthread_spin_lock.c
new file mode 100644
index 000000000..7d25af7c4
--- /dev/null
+++ b/libc/nptl/sysdeps/ia64/pthread_spin_lock.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 "pthreadP.h"
+
+int
+pthread_spin_lock (lock)
+ pthread_spinlock_t *lock;
+{
+ int *p = (int *) lock;
+
+ while (__builtin_expect (__sync_val_compare_and_swap (p, 0, 1), 0))
+ {
+ /* Spin without using the atomic instruction. */
+ do
+ __asm __volatile ("hint @pause" : : : "memory");
+ while (*p);
+ }
+ return 0;
+}
diff --git a/libc/nptl/sysdeps/ia64/pthread_spin_trylock.c b/libc/nptl/sysdeps/ia64/pthread_spin_trylock.c
new file mode 100644
index 000000000..0fd8b99b7
--- /dev/null
+++ b/libc/nptl/sysdeps/ia64/pthread_spin_trylock.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 <errno.h>
+#include "pthreadP.h"
+
+int
+pthread_spin_trylock (lock)
+ pthread_spinlock_t *lock;
+{
+ return __sync_val_compare_and_swap ((int *) lock, 0, 1) == 0 ? 0 : EBUSY;
+}
diff --git a/libc/nptl/sysdeps/ia64/pthread_spin_unlock.c b/libc/nptl/sysdeps/ia64/pthread_spin_unlock.c
new file mode 100644
index 000000000..6232764b1
--- /dev/null
+++ b/libc/nptl/sysdeps/ia64/pthread_spin_unlock.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 "pthreadP.h"
+
+
+int
+pthread_spin_unlock (pthread_spinlock_t *lock)
+{
+ __sync_lock_release_si ((int *) lock);
+ return 0;
+}
diff --git a/libc/nptl/sysdeps/ia64/pthreaddef.h b/libc/nptl/sysdeps/ia64/pthreaddef.h
new file mode 100644
index 000000000..f2539e290
--- /dev/null
+++ b/libc/nptl/sysdeps/ia64/pthreaddef.h
@@ -0,0 +1,43 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+/* Default stack size. */
+#define ARCH_STACK_DEFAULT_SIZE (32 * 1024 * 1024)
+
+/* IA-64 uses a normal stack and a register stack. */
+#define NEED_SEPARATE_REGISTER_STACK
+
+/* Required stack pointer alignment at beginning. */
+#define STACK_ALIGN 16
+
+/* Minimal stack size after allocating thread descriptor and guard size. */
+#define MINIMAL_REST_STACK 16384
+
+/* Alignment requirement for TCB. */
+#define TCB_ALIGNMENT 16
+
+
+/* Location of current stack frame. */
+#define CURRENT_STACK_FRAME __stack_pointer
+register char *__stack_pointer __asm__ ("sp");
+
+/* XXX Until we have a better place keep the definitions here. */
+
+/* While there is no such syscall. */
+#define __exit_thread_inline(val) \
+ INLINE_SYSCALL (exit, 1, (val))
diff --git a/libc/nptl/sysdeps/ia64/tcb-offsets.sym b/libc/nptl/sysdeps/ia64/tcb-offsets.sym
new file mode 100644
index 000000000..e1707ab1c
--- /dev/null
+++ b/libc/nptl/sysdeps/ia64/tcb-offsets.sym
@@ -0,0 +1,7 @@
+#include <sysdep.h>
+#include <tls.h>
+
+PID offsetof (struct pthread, pid) - TLS_PRE_TCB_SIZE
+TID offsetof (struct pthread, tid) - TLS_PRE_TCB_SIZE
+MULTIPLE_THREADS_OFFSET offsetof (struct pthread, header.multiple_threads) - TLS_PRE_TCB_SIZE
+SYSINFO_OFFSET offsetof (tcbhead_t, __private)
diff --git a/libc/nptl/sysdeps/ia64/tls.h b/libc/nptl/sysdeps/ia64/tls.h
new file mode 100644
index 000000000..69101ad8c
--- /dev/null
+++ b/libc/nptl/sysdeps/ia64/tls.h
@@ -0,0 +1,171 @@
+/* Definition for thread-local data handling. nptl/IA-64 version.
+ Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+#ifndef _TLS_H
+#define _TLS_H 1
+
+#include <dl-sysdep.h>
+#ifndef __ASSEMBLER__
+# include <stdbool.h>
+# include <stddef.h>
+# include <stdint.h>
+# include <stdlib.h>
+# include <list.h>
+
+
+/* Type for the dtv. */
+typedef union dtv
+{
+ size_t counter;
+ struct
+ {
+ void *val;
+ bool is_static;
+ } pointer;
+} dtv_t;
+
+
+typedef struct
+{
+ dtv_t *dtv;
+ void *__private;
+} tcbhead_t;
+
+register struct pthread *__thread_self __asm__("r13");
+
+# define TLS_MULTIPLE_THREADS_IN_TCB 1
+
+#else /* __ASSEMBLER__ */
+# include <tcb-offsets.h>
+#endif
+
+
+/* We require TLS support in the tools. */
+#ifndef HAVE_TLS_SUPPORT
+# error "TLS support is required."
+#endif
+
+/* Signal that TLS support is available. */
+#define USE_TLS 1
+
+/* Alignment requirement for the stack. */
+#define STACK_ALIGN 16
+
+#ifndef __ASSEMBLER__
+/* Get system call information. */
+# include <sysdep.h>
+
+/* This is the size of the initial TCB. */
+# define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
+
+/* Alignment requirements for the initial TCB. */
+# define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
+
+/* This is the size of the TCB. */
+# define TLS_TCB_SIZE sizeof (tcbhead_t)
+
+/* This is the size we need before TCB.
+ If there is not any room for uintptr_t stack_guard and
+ uintptr_t pointer_guard in struct pthread's final padding,
+ we need to put struct pthread 16 byte slower. */
+# define TLS_PRE_TCB_SIZE \
+ (sizeof (struct pthread) \
+ + (PTHREAD_STRUCT_END_PADDING < 2 * sizeof (uintptr_t) \
+ ? ((2 * sizeof (uintptr_t) + __alignof__ (struct pthread) - 1) \
+ & ~(__alignof__ (struct pthread) - 1)) \
+ : 0))
+
+/* Alignment requirements for the TCB. */
+# define TLS_TCB_ALIGN __alignof__ (struct pthread)
+
+/* The DTV is allocated at the TP; the TCB is placed elsewhere. */
+# define TLS_DTV_AT_TP 1
+
+/* Get the thread descriptor definition. */
+# include <nptl/descr.h>
+
+/* Install the dtv pointer. The pointer passed is to the element with
+ index -1 which contain the length. */
+# define INSTALL_DTV(descr, dtvp) \
+ ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
+
+/* Install new dtv for current thread. */
+# define INSTALL_NEW_DTV(DTV) \
+ (((tcbhead_t *)__thread_self)->dtv = (DTV))
+
+/* Return dtv of given thread descriptor. */
+# define GET_DTV(descr) \
+ (((tcbhead_t *) (descr))->dtv)
+
+#define THREAD_SELF_SYSINFO (((tcbhead_t *) __thread_self)->__private)
+#define THREAD_SYSINFO(pd) \
+ (((tcbhead_t *) ((char *) (pd) + TLS_PRE_TCB_SIZE))->__private)
+
+#if defined NEED_DL_SYSINFO
+# define INIT_SYSINFO THREAD_SELF_SYSINFO = (void *) GLRO(dl_sysinfo)
+#else
+# define INIT_SYSINFO NULL
+#endif
+
+/* Code to initially initialize the thread pointer. This might need
+ special attention since 'errno' is not yet available and if the
+ operation can cause a failure 'errno' must not be touched. */
+# define TLS_INIT_TP(thrdescr, secondcall) \
+ (__thread_self = (thrdescr), INIT_SYSINFO, NULL)
+
+/* Return the address of the dtv for the current thread. */
+# define THREAD_DTV() \
+ (((tcbhead_t *)__thread_self)->dtv)
+
+/* Return the thread descriptor for the current thread. */
+# define THREAD_SELF \
+ ((struct pthread *) ((char *) __thread_self - TLS_PRE_TCB_SIZE))
+
+/* Magic for libthread_db to know how to do THREAD_SELF. */
+# define DB_THREAD_SELF REGISTER (64, 64, 13 * 8, -TLS_PRE_TCB_SIZE)
+
+/* Access to data in the thread descriptor is easy. */
+#define THREAD_GETMEM(descr, member) \
+ descr->member
+#define THREAD_GETMEM_NC(descr, member, idx) \
+ descr->member[idx]
+#define THREAD_SETMEM(descr, member, value) \
+ descr->member = (value)
+#define THREAD_SETMEM_NC(descr, member, idx, value) \
+ descr->member[idx] = (value)
+
+/* Set the stack guard field in TCB head. */
+#define THREAD_SET_STACK_GUARD(value) \
+ (((uintptr_t *) __thread_self)[-1] = (value))
+#define THREAD_COPY_STACK_GUARD(descr) \
+ (((uintptr_t *) ((char *) (descr) + TLS_PRE_TCB_SIZE))[-1] \
+ = ((uintptr_t *) __thread_self)[-1])
+
+/* Set the pointer guard field in TCB head. */
+#define THREAD_GET_POINTER_GUARD() \
+ (((uintptr_t *) __thread_self)[-2])
+#define THREAD_SET_POINTER_GUARD(value) \
+ (((uintptr_t *) __thread_self)[-2] = (value))
+#define THREAD_COPY_POINTER_GUARD(descr) \
+ (((uintptr_t *) ((char *) (descr) + TLS_PRE_TCB_SIZE))[-2] \
+ = THREAD_GET_POINTER_GUARD ())
+
+#endif /* __ASSEMBLER__ */
+
+#endif /* tls.h */
diff --git a/libc/nptl/sysdeps/powerpc/Makefile b/libc/nptl/sysdeps/powerpc/Makefile
new file mode 100644
index 000000000..3af245600
--- /dev/null
+++ b/libc/nptl/sysdeps/powerpc/Makefile
@@ -0,0 +1,21 @@
+# Copyright (C) 2003 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# 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.
+
+ifeq ($(subdir),csu)
+gen-as-const-headers += tcb-offsets.sym
+endif
diff --git a/libc/nptl/sysdeps/powerpc/pthread_spin_lock.c b/libc/nptl/sysdeps/powerpc/pthread_spin_lock.c
new file mode 100644
index 000000000..e2293fda1
--- /dev/null
+++ b/libc/nptl/sysdeps/powerpc/pthread_spin_lock.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus@au.ibm.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 "pthreadP.h"
+
+int
+pthread_spin_lock (lock)
+ pthread_spinlock_t *lock;
+{
+ unsigned int __tmp;
+
+ asm volatile (
+ "1: lwarx %0,0,%1\n"
+ " cmpwi 0,%0,0\n"
+ " bne- 2f\n"
+ " stwcx. %2,0,%1\n"
+ " bne- 2f\n"
+ " isync\n"
+ " .subsection 1\n"
+ "2: lwzx %0,0,%1\n"
+ " cmpwi 0,%0,0\n"
+ " bne 2b\n"
+ " b 1b\n"
+ " .previous"
+ : "=&r" (__tmp)
+ : "r" (lock), "r" (1)
+ : "cr0", "memory");
+ return 0;
+}
diff --git a/libc/nptl/sysdeps/powerpc/pthread_spin_trylock.c b/libc/nptl/sysdeps/powerpc/pthread_spin_trylock.c
new file mode 100644
index 000000000..d8e1dbcc8
--- /dev/null
+++ b/libc/nptl/sysdeps/powerpc/pthread_spin_trylock.c
@@ -0,0 +1,43 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus@au.ibm.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 <errno.h>
+#include "pthreadP.h"
+
+int
+pthread_spin_trylock (lock)
+ pthread_spinlock_t *lock;
+{
+ unsigned int old;
+ int err = EBUSY;
+
+ asm ("1: lwarx %0,0,%2\n"
+ " cmpwi 0,%0,0\n"
+ " bne 2f\n"
+ " stwcx. %3,0,%2\n"
+ " bne- 1b\n"
+ " li %1,0\n"
+ " isync\n"
+ "2: "
+ : "=&r" (old), "=&r" (err)
+ : "r" (lock), "r" (1), "1" (err)
+ : "cr0", "memory");
+
+ return err;
+}
diff --git a/libc/nptl/sysdeps/powerpc/pthreaddef.h b/libc/nptl/sysdeps/powerpc/pthreaddef.h
new file mode 100644
index 000000000..342c15c67
--- /dev/null
+++ b/libc/nptl/sysdeps/powerpc/pthreaddef.h
@@ -0,0 +1,41 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+/* Default stack size. */
+#define ARCH_STACK_DEFAULT_SIZE (4 * 1024 * 1024)
+
+/* Required stack pointer alignment at beginning. The ABI requires 16
+ bytes (for both 32-bit and 64-bit PowerPC). */
+#define STACK_ALIGN 16
+
+/* Minimal stack size after allocating thread descriptor and guard size. */
+#define MINIMAL_REST_STACK 4096
+
+/* Alignment requirement for TCB. */
+#define TCB_ALIGNMENT 16
+
+
+/* Location of current stack frame. */
+#define CURRENT_STACK_FRAME __builtin_frame_address (0)
+
+
+/* XXX Until we have a better place keep the definitions here. */
+
+/* While there is no such syscall. */
+#define __exit_thread_inline(val) \
+ INLINE_SYSCALL (exit, 1, (val))
diff --git a/libc/nptl/sysdeps/powerpc/tcb-offsets.sym b/libc/nptl/sysdeps/powerpc/tcb-offsets.sym
new file mode 100644
index 000000000..4a8671e80
--- /dev/null
+++ b/libc/nptl/sysdeps/powerpc/tcb-offsets.sym
@@ -0,0 +1,17 @@
+#include <sysdep.h>
+#include <tls.h>
+
+--
+
+-- Abuse tls.h macros to derive offsets relative to the thread register.
+# undef __thread_register
+# define __thread_register ((void *) 0)
+# define thread_offsetof(mem) ((ptrdiff_t) THREAD_SELF + offsetof (struct pthread, mem))
+
+
+#if TLS_MULTIPLE_THREADS_IN_TCB
+MULTIPLE_THREADS_OFFSET thread_offsetof (header.multiple_threads)
+#endif
+PID thread_offsetof (pid)
+TID thread_offsetof (tid)
+POINTER_GUARD (offsetof (tcbhead_t, pointer_guard) - TLS_TCB_OFFSET - sizeof (tcbhead_t))
diff --git a/libc/nptl/sysdeps/powerpc/tls.h b/libc/nptl/sysdeps/powerpc/tls.h
new file mode 100644
index 000000000..976a27136
--- /dev/null
+++ b/libc/nptl/sysdeps/powerpc/tls.h
@@ -0,0 +1,188 @@
+/* Definition for thread-local data handling. NPTL/PowerPC version.
+ Copyright (C) 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+#ifndef _TLS_H
+#define _TLS_H 1
+
+# include <dl-sysdep.h>
+
+#ifndef __ASSEMBLER__
+# include <stdbool.h>
+# include <stddef.h>
+# include <stdint.h>
+
+/* Type for the dtv. */
+typedef union dtv
+{
+ size_t counter;
+ struct
+ {
+ void *val;
+ bool is_static;
+ } pointer;
+} dtv_t;
+
+#else /* __ASSEMBLER__ */
+# include <tcb-offsets.h>
+#endif /* __ASSEMBLER__ */
+
+
+/* We require TLS support in the tools. */
+#ifndef HAVE_TLS_SUPPORT
+# error "TLS support is required."
+#endif
+
+/* Signal that TLS support is available. */
+# define USE_TLS 1
+
+#ifndef __ASSEMBLER__
+
+/* Get system call information. */
+# include <sysdep.h>
+
+/* The TP points to the start of the thread blocks. */
+# define TLS_DTV_AT_TP 1
+
+/* We use the multiple_threads field in the pthread struct */
+#define TLS_MULTIPLE_THREADS_IN_TCB 1
+
+/* Get the thread descriptor definition. */
+# include <nptl/descr.h>
+
+/* The stack_guard is accessed directly by GCC -fstack-protector code,
+ so it is a part of public ABI. The dtv and pointer_guard fields
+ are private. */
+typedef struct
+{
+ uintptr_t pointer_guard;
+ uintptr_t stack_guard;
+ dtv_t *dtv;
+} tcbhead_t;
+
+/* This is the size of the initial TCB. */
+# define TLS_INIT_TCB_SIZE 0
+
+/* Alignment requirements for the initial TCB. */
+# define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
+
+/* This is the size of the TCB. */
+# define TLS_TCB_SIZE 0
+
+/* Alignment requirements for the TCB. */
+# define TLS_TCB_ALIGN __alignof__ (struct pthread)
+
+/* This is the size we need before TCB. */
+# define TLS_PRE_TCB_SIZE \
+ (sizeof (struct pthread) \
+ + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
+
+# ifndef __powerpc64__
+/* Register r2 (tp) is reserved by the ABI as "thread pointer". */
+register void *__thread_register __asm__ ("r2");
+# define PT_THREAD_POINTER PT_R2
+# else
+/* Register r13 (tp) is reserved by the ABI as "thread pointer". */
+register void *__thread_register __asm__ ("r13");
+# define PT_THREAD_POINTER PT_R13
+# endif
+
+/* The following assumes that TP (R2 or R13) points to the end of the
+ TCB + 0x7000 (per the ABI). This implies that TCB address is
+ TP - 0x7000. As we define TLS_DTV_AT_TP we can
+ assume that the pthread struct is allocated immediately ahead of the
+ TCB. This implies that the pthread_descr address is
+ TP - (TLS_PRE_TCB_SIZE + 0x7000). */
+# define TLS_TCB_OFFSET 0x7000
+
+/* Install the dtv pointer. The pointer passed is to the element with
+ index -1 which contain the length. */
+# define INSTALL_DTV(tcbp, dtvp) \
+ ((tcbhead_t *) (tcbp))[-1].dtv = dtvp + 1
+
+/* Install new dtv for current thread. */
+# define INSTALL_NEW_DTV(dtv) (THREAD_DTV() = (dtv))
+
+/* Return dtv of given thread descriptor. */
+# define GET_DTV(tcbp) (((tcbhead_t *) (tcbp))[-1].dtv)
+
+/* Code to initially initialize the thread pointer. This might need
+ special attention since 'errno' is not yet available and if the
+ operation can cause a failure 'errno' must not be touched. */
+# define TLS_INIT_TP(tcbp, secondcall) \
+ (__thread_register = (void *) (tcbp) + TLS_TCB_OFFSET, NULL)
+
+/* Return the address of the dtv for the current thread. */
+# define THREAD_DTV() \
+ (((tcbhead_t *) (__thread_register - TLS_TCB_OFFSET))[-1].dtv)
+
+/* Return the thread descriptor for the current thread. */
+# define THREAD_SELF \
+ ((struct pthread *) (__thread_register \
+ - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
+
+/* Magic for libthread_db to know how to do THREAD_SELF. */
+# define DB_THREAD_SELF \
+ REGISTER (32, 32, PT_THREAD_POINTER * 4, \
+ - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE) \
+ REGISTER (64, 64, PT_THREAD_POINTER * 8, \
+ - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE)
+
+/* Read member of the thread descriptor directly. */
+# define THREAD_GETMEM(descr, member) ((void)(descr), (THREAD_SELF)->member)
+
+/* Same as THREAD_GETMEM, but the member offset can be non-constant. */
+# define THREAD_GETMEM_NC(descr, member, idx) \
+ ((void)(descr), (THREAD_SELF)->member[idx])
+
+/* Set member of the thread descriptor directly. */
+# define THREAD_SETMEM(descr, member, value) \
+ ((void)(descr), (THREAD_SELF)->member = (value))
+
+/* Same as THREAD_SETMEM, but the member offset can be non-constant. */
+# define THREAD_SETMEM_NC(descr, member, idx, value) \
+ ((void)(descr), (THREAD_SELF)->member[idx] = (value))
+
+/* Set the stack guard field in TCB head. */
+# define THREAD_SET_STACK_GUARD(value) \
+ (((tcbhead_t *) ((char *) __thread_register \
+ - TLS_TCB_OFFSET))[-1].stack_guard = (value))
+# define THREAD_COPY_STACK_GUARD(descr) \
+ (((tcbhead_t *) ((char *) (descr) \
+ + TLS_PRE_TCB_SIZE))[-1].stack_guard \
+ = ((tcbhead_t *) ((char *) __thread_register \
+ - TLS_TCB_OFFSET))[-1].stack_guard)
+
+/* Set the stack guard field in TCB head. */
+# define THREAD_GET_POINTER_GUARD() \
+ (((tcbhead_t *) ((char *) __thread_register \
+ - TLS_TCB_OFFSET))[-1].pointer_guard)
+# define THREAD_SET_POINTER_GUARD(value) \
+ (THREAD_GET_POINTER_GUARD () = (value))
+# define THREAD_COPY_POINTER_GUARD(descr) \
+ (((tcbhead_t *) ((char *) (descr) \
+ + TLS_PRE_TCB_SIZE))[-1].pointer_guard \
+ = THREAD_GET_POINTER_GUARD())
+
+/* l_tls_offset == 0 is perfectly valid on PPC, so we have to use some
+ different value to mean unset l_tls_offset. */
+# define NO_TLS_OFFSET -1
+
+#endif /* __ASSEMBLER__ */
+
+#endif /* tls.h */
diff --git a/libc/nptl/sysdeps/pthread/Makefile b/libc/nptl/sysdeps/pthread/Makefile
new file mode 100644
index 000000000..72550d74a
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/Makefile
@@ -0,0 +1,50 @@
+# Copyright (C) 2002,2003,2004,2006 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+# Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+# 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.
+
+ifeq ($(subdir),csu)
+routines += unwind-resume
+shared-only-routines += unwind-resume
+CFLAGS-unwind-resume.c += -fexceptions -fasynchronous-unwind-tables
+endif
+
+ifeq ($(subdir),nptl)
+libpthread-sysdep_routines += errno-loc
+endif
+
+ifeq ($(subdir),rt)
+librt-sysdep_routines += timer_routines librt-cancellation rt-unwind-resume
+librt-shared-only-routines += rt-unwind-resume
+CFLAGS-librt-cancellation.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-rt-unwind-resume.c += -fexceptions -fasynchronous-unwind-tables
+
+ifeq (yes,$(build-shared))
+$(objpfx)tst-timer: $(objpfx)librt.so $(shared-thread-library)
+else
+$(objpfx)tst-timer: $(objpfx)librt.a $(static-thread-library)
+endif
+
+ifeq ($(have-forced-unwind),yes)
+tests += tst-mqueue8x
+CFLAGS-tst-mqueue8x.c += -fexceptions
+endif
+endif
+
+ifeq ($(subdir),posix)
+CFLAGS-confstr.c += -DLIBPTHREAD_VERSION='"NPTL $(version)"'
+endif
diff --git a/libc/nptl/sysdeps/pthread/Subdirs b/libc/nptl/sysdeps/pthread/Subdirs
new file mode 100644
index 000000000..36266c1e6
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/Subdirs
@@ -0,0 +1,2 @@
+nptl
+nptl_db
diff --git a/libc/nptl/sysdeps/pthread/aio_misc.h b/libc/nptl/sysdeps/pthread/aio_misc.h
new file mode 100644
index 000000000..f28508388
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/aio_misc.h
@@ -0,0 +1,74 @@
+/* Copyright (C) 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+/* We define a special synchronization primitive for AIO. POSIX
+ conditional variables would be ideal but the pthread_cond_*wait
+ operations do not return on EINTR. This is a requirement for
+ correct aio_suspend and lio_listio implementations. */
+
+#include <assert.h>
+#include <pthreadP.h>
+#include <lowlevellock.h>
+
+#define DONT_NEED_AIO_MISC_COND 1
+
+#define AIO_MISC_NOTIFY(waitlist) \
+ do { \
+ if (--*waitlist->counterp == 0) \
+ lll_futex_wake (waitlist->counterp, 1); \
+ } while (0)
+
+#define AIO_MISC_WAIT(result, futex, timeout, cancel) \
+ do { \
+ volatile int *futexaddr = &futex; \
+ int oldval = futex; \
+ \
+ if (oldval != 0) \
+ { \
+ pthread_mutex_unlock (&__aio_requests_mutex); \
+ \
+ int oldtype; \
+ if (cancel) \
+ oldtype = LIBC_CANCEL_ASYNC (); \
+ \
+ int status; \
+ do \
+ { \
+ status = lll_futex_timed_wait (futexaddr, oldval, timeout); \
+ if (status != -EWOULDBLOCK) \
+ break; \
+ \
+ oldval = *futexaddr; \
+ } \
+ while (oldval != 0); \
+ \
+ if (cancel) \
+ LIBC_CANCEL_RESET (oldtype); \
+ \
+ if (status == -EINTR) \
+ result = EINTR; \
+ else if (status == -ETIMEDOUT) \
+ result = EAGAIN; \
+ else \
+ assert (status == 0 || status == -EWOULDBLOCK); \
+ \
+ pthread_mutex_lock (&__aio_requests_mutex); \
+ } \
+ } while (0)
+
+#include_next <aio_misc.h>
diff --git a/libc/nptl/sysdeps/pthread/allocalim.h b/libc/nptl/sysdeps/pthread/allocalim.h
new file mode 100644
index 000000000..f13c3a330
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/allocalim.h
@@ -0,0 +1,30 @@
+/* Determine whether block of given size can be allocated on the stack or not.
+ Copyright (C) 2002, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <alloca.h>
+#include <limits.h>
+
+
+extern int
+__always_inline
+__libc_use_alloca (size_t size)
+{
+ return (__builtin_expect (size <= PTHREAD_STACK_MIN / 4, 1)
+ || __libc_alloca_cutoff (size));
+}
diff --git a/libc/nptl/sysdeps/pthread/bits/libc-lock.h b/libc/nptl/sysdeps/pthread/bits/libc-lock.h
new file mode 100644
index 000000000..795caa713
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/bits/libc-lock.h
@@ -0,0 +1,568 @@
+/* libc-internal interface for mutex locks. NPTL version.
+ Copyright (C) 1996-2001, 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _BITS_LIBC_LOCK_H
+#define _BITS_LIBC_LOCK_H 1
+
+#include <pthread.h>
+#define __need_NULL
+#include <stddef.h>
+
+
+/* Fortunately Linux now has a mean to do locking which is realtime
+ safe without the aid of the thread library. We also need no fancy
+ options like error checking mutexes etc. We only need simple
+ locks, maybe recursive. This can be easily and cheaply implemented
+ using futexes. We will use them everywhere except in ld.so since
+ ld.so might be used on old kernels with a different libc.so. */
+#ifdef _LIBC
+# include <lowlevellock.h>
+# include <tls.h>
+# include <pthread-functions.h>
+#endif
+
+/* Mutex type. */
+#if defined _LIBC || defined _IO_MTSAFE_IO
+# if (defined NOT_IN_libc && !defined IS_IN_libpthread) || !defined _LIBC
+typedef pthread_mutex_t __libc_lock_t;
+typedef struct { pthread_mutex_t mutex; } __libc_lock_recursive_t;
+# else
+typedef int __libc_lock_t;
+typedef struct { int lock; int cnt; void *owner; } __libc_lock_recursive_t;
+# endif
+typedef struct { pthread_mutex_t mutex; } __rtld_lock_recursive_t;
+# ifdef __USE_UNIX98
+typedef pthread_rwlock_t __libc_rwlock_t;
+# else
+typedef struct __libc_rwlock_opaque__ __libc_rwlock_t;
+# endif
+#else
+typedef struct __libc_lock_opaque__ __libc_lock_t;
+typedef struct __libc_lock_recursive_opaque__ __libc_lock_recursive_t;
+typedef struct __libc_rwlock_opaque__ __libc_rwlock_t;
+#endif
+
+/* Type for key to thread-specific data. */
+typedef pthread_key_t __libc_key_t;
+
+/* Define a lock variable NAME with storage class CLASS. The lock must be
+ initialized with __libc_lock_init before it can be used (or define it
+ with __libc_lock_define_initialized, below). Use `extern' for CLASS to
+ declare a lock defined in another module. In public structure
+ definitions you must use a pointer to the lock structure (i.e., NAME
+ begins with a `*'), because its storage size will not be known outside
+ of libc. */
+#define __libc_lock_define(CLASS,NAME) \
+ CLASS __libc_lock_t NAME;
+#define __libc_rwlock_define(CLASS,NAME) \
+ CLASS __libc_rwlock_t NAME;
+#define __libc_lock_define_recursive(CLASS,NAME) \
+ CLASS __libc_lock_recursive_t NAME;
+#define __rtld_lock_define_recursive(CLASS,NAME) \
+ CLASS __rtld_lock_recursive_t NAME;
+
+/* Define an initialized lock variable NAME with storage class CLASS.
+
+ For the C library we take a deeper look at the initializer. For
+ this implementation all fields are initialized to zero. Therefore
+ we don't initialize the variable which allows putting it into the
+ BSS section. (Except on PA-RISC and other odd architectures, where
+ initialized locks must be set to one due to the lack of normal
+ atomic operations.) */
+
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
+# if LLL_LOCK_INITIALIZER == 0
+# define __libc_lock_define_initialized(CLASS,NAME) \
+ CLASS __libc_lock_t NAME;
+# else
+# define __libc_lock_define_initialized(CLASS,NAME) \
+ CLASS __libc_lock_t NAME = LLL_LOCK_INITIALIZER;
+# endif
+#else
+# if __LT_SPINLOCK_INIT == 0
+# define __libc_lock_define_initialized(CLASS,NAME) \
+ CLASS __libc_lock_t NAME;
+# else
+# define __libc_lock_define_initialized(CLASS,NAME) \
+ CLASS __libc_lock_t NAME = PTHREAD_MUTEX_INITIALIZER;
+# endif
+#endif
+
+#define __libc_rwlock_define_initialized(CLASS,NAME) \
+ CLASS __libc_rwlock_t NAME = PTHREAD_RWLOCK_INITIALIZER;
+
+/* Define an initialized recursive lock variable NAME with storage
+ class CLASS. */
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
+# if LLL_LOCK_INITIALIZER == 0
+# define __libc_lock_define_initialized_recursive(CLASS,NAME) \
+ CLASS __libc_lock_recursive_t NAME;
+# else
+# define __libc_lock_define_initialized_recursive(CLASS,NAME) \
+ CLASS __libc_lock_recursive_t NAME = _LIBC_LOCK_RECURSIVE_INITIALIZER;
+# endif
+# define _LIBC_LOCK_RECURSIVE_INITIALIZER \
+ { LLL_LOCK_INITIALIZER, 0, NULL }
+#else
+# define __libc_lock_define_initialized_recursive(CLASS,NAME) \
+ CLASS __libc_lock_recursive_t NAME = _LIBC_LOCK_RECURSIVE_INITIALIZER;
+# define _LIBC_LOCK_RECURSIVE_INITIALIZER \
+ {PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP}
+#endif
+
+#define __rtld_lock_define_initialized_recursive(CLASS,NAME) \
+ CLASS __rtld_lock_recursive_t NAME = _RTLD_LOCK_RECURSIVE_INITIALIZER;
+#define _RTLD_LOCK_RECURSIVE_INITIALIZER \
+ {PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP}
+
+#define __rtld_lock_initialize(NAME) \
+ (void) ((NAME) = (__rtld_lock_recursive_t) _RTLD_LOCK_RECURSIVE_INITIALIZER)
+
+/* If we check for a weakly referenced symbol and then perform a
+ normal jump to it te code generated for some platforms in case of
+ PIC is unnecessarily slow. What would happen is that the function
+ is first referenced as data and then it is called indirectly
+ through the PLT. We can make this a direct jump. */
+#ifdef __PIC__
+# define __libc_maybe_call(FUNC, ARGS, ELSE) \
+ (__extension__ ({ __typeof (FUNC) *_fn = (FUNC); \
+ _fn != NULL ? (*_fn) ARGS : ELSE; }))
+#else
+# define __libc_maybe_call(FUNC, ARGS, ELSE) \
+ (FUNC != NULL ? FUNC ARGS : ELSE)
+#endif
+
+/* Call thread functions through the function pointer table. */
+#if defined SHARED && !defined NOT_IN_libc
+# define PTF(NAME) __libc_pthread_functions.ptr_##NAME
+# define __libc_ptf_call(FUNC, ARGS, ELSE) \
+ (PTF(FUNC) != NULL ? PTF(FUNC) ARGS : ELSE)
+#else
+# define PTF(NAME) NAME
+# define __libc_ptf_call(FUNC, ARGS, ELSE) \
+ __libc_maybe_call (FUNC, ARGS, ELSE)
+#endif
+
+
+/* Initialize the named lock variable, leaving it in a consistent, unlocked
+ state. */
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
+# define __libc_lock_init(NAME) ((NAME) = LLL_LOCK_INITIALIZER, 0)
+#else
+# define __libc_lock_init(NAME) \
+ __libc_maybe_call (__pthread_mutex_init, (&(NAME), NULL), 0)
+#endif
+#define __libc_rwlock_init(NAME) \
+ __libc_maybe_call (__pthread_rwlock_init, (&(NAME), NULL), 0)
+
+/* Same as last but this time we initialize a recursive mutex. */
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
+# define __libc_lock_init_recursive(NAME) \
+ ((NAME) = (__libc_lock_recursive_t) _LIBC_LOCK_RECURSIVE_INITIALIZER, 0)
+#else
+# define __libc_lock_init_recursive(NAME) \
+ do { \
+ if (__pthread_mutex_init != NULL) \
+ { \
+ pthread_mutexattr_t __attr; \
+ __pthread_mutexattr_init (&__attr); \
+ __pthread_mutexattr_settype (&__attr, PTHREAD_MUTEX_RECURSIVE_NP); \
+ __pthread_mutex_init (&(NAME).mutex, &__attr); \
+ __pthread_mutexattr_destroy (&__attr); \
+ } \
+ } while (0)
+#endif
+
+#define __rtld_lock_init_recursive(NAME) \
+ do { \
+ if (__pthread_mutex_init != NULL) \
+ { \
+ pthread_mutexattr_t __attr; \
+ __pthread_mutexattr_init (&__attr); \
+ __pthread_mutexattr_settype (&__attr, PTHREAD_MUTEX_RECURSIVE_NP); \
+ __pthread_mutex_init (&(NAME).mutex, &__attr); \
+ __pthread_mutexattr_destroy (&__attr); \
+ } \
+ } while (0)
+
+/* Finalize the named lock variable, which must be locked. It cannot be
+ used again until __libc_lock_init is called again on it. This must be
+ called on a lock variable before the containing storage is reused. */
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
+# define __libc_lock_fini(NAME) ((void) 0)
+#else
+# define __libc_lock_fini(NAME) \
+ __libc_maybe_call (__pthread_mutex_destroy, (&(NAME)), 0)
+#endif
+#define __libc_rwlock_fini(NAME) \
+ __libc_maybe_call (__pthread_rwlock_destroy, (&(NAME)), 0)
+
+/* Finalize recursive named lock. */
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
+# define __libc_lock_fini_recursive(NAME) ((void) 0)
+#else
+# define __libc_lock_fini_recursive(NAME) \
+ __libc_maybe_call (__pthread_mutex_destroy, (&(NAME)), 0)
+#endif
+
+/* Lock the named lock variable. */
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
+# define __libc_lock_lock(NAME) \
+ ({ lll_lock (NAME); 0; })
+#else
+# define __libc_lock_lock(NAME) \
+ __libc_maybe_call (__pthread_mutex_lock, (&(NAME)), 0)
+#endif
+#define __libc_rwlock_rdlock(NAME) \
+ __libc_ptf_call (__pthread_rwlock_rdlock, (&(NAME)), 0)
+#define __libc_rwlock_wrlock(NAME) \
+ __libc_ptf_call (__pthread_rwlock_wrlock, (&(NAME)), 0)
+
+/* Lock the recursive named lock variable. */
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
+# define __libc_lock_lock_recursive(NAME) \
+ do { \
+ void *self = THREAD_SELF; \
+ if ((NAME).owner != self) \
+ { \
+ lll_lock ((NAME).lock); \
+ (NAME).owner = self; \
+ } \
+ ++(NAME).cnt; \
+ } while (0)
+#else
+# define __libc_lock_lock_recursive(NAME) \
+ __libc_maybe_call (__pthread_mutex_lock, (&(NAME).mutex), 0)
+#endif
+
+/* Try to lock the named lock variable. */
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
+# define __libc_lock_trylock(NAME) \
+ lll_trylock (NAME)
+#else
+# define __libc_lock_trylock(NAME) \
+ __libc_maybe_call (__pthread_mutex_trylock, (&(NAME)), 0)
+#endif
+#define __libc_rwlock_tryrdlock(NAME) \
+ __libc_maybe_call (__pthread_rwlock_tryrdlock, (&(NAME)), 0)
+#define __libc_rwlock_trywrlock(NAME) \
+ __libc_maybe_call (__pthread_rwlock_trywrlock, (&(NAME)), 0)
+
+/* Try to lock the recursive named lock variable. */
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
+# define __libc_lock_trylock_recursive(NAME) \
+ ({ \
+ int result = 0; \
+ void *self = THREAD_SELF; \
+ if ((NAME).owner != self) \
+ { \
+ if (lll_trylock ((NAME).lock) == 0) \
+ { \
+ (NAME).owner = self; \
+ (NAME).cnt = 1; \
+ } \
+ else \
+ result = EBUSY; \
+ } \
+ else \
+ ++(NAME).cnt; \
+ result; \
+ })
+#else
+# define __libc_lock_trylock_recursive(NAME) \
+ __libc_maybe_call (__pthread_mutex_trylock, (&(NAME)), 0)
+#endif
+
+#define __rtld_lock_trylock_recursive(NAME) \
+ __libc_maybe_call (__pthread_mutex_trylock, (&(NAME).mutex), 0)
+
+/* Unlock the named lock variable. */
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
+# define __libc_lock_unlock(NAME) \
+ lll_unlock (NAME)
+#else
+# define __libc_lock_unlock(NAME) \
+ __libc_maybe_call (__pthread_mutex_unlock, (&(NAME)), 0)
+#endif
+#define __libc_rwlock_unlock(NAME) \
+ __libc_ptf_call (__pthread_rwlock_unlock, (&(NAME)), 0)
+
+/* Unlock the recursive named lock variable. */
+#if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
+/* We do no error checking here. */
+# define __libc_lock_unlock_recursive(NAME) \
+ do { \
+ if (--(NAME).cnt == 0) \
+ { \
+ (NAME).owner = NULL; \
+ lll_unlock ((NAME).lock); \
+ } \
+ } while (0)
+#else
+# define __libc_lock_unlock_recursive(NAME) \
+ __libc_maybe_call (__pthread_mutex_unlock, (&(NAME)), 0)
+#endif
+
+#if defined _LIBC && defined SHARED
+# define __rtld_lock_default_lock_recursive(lock) \
+ ++((pthread_mutex_t *)(lock))->__data.__count;
+
+# define __rtld_lock_default_unlock_recursive(lock) \
+ --((pthread_mutex_t *)(lock))->__data.__count;
+
+# define __rtld_lock_lock_recursive(NAME) \
+ GL(dl_rtld_lock_recursive) (&(NAME).mutex)
+
+# define __rtld_lock_unlock_recursive(NAME) \
+ GL(dl_rtld_unlock_recursive) (&(NAME).mutex)
+#else
+# define __rtld_lock_lock_recursive(NAME) \
+ __libc_maybe_call (__pthread_mutex_lock, (&(NAME).mutex), 0)
+
+# define __rtld_lock_unlock_recursive(NAME) \
+ __libc_maybe_call (__pthread_mutex_unlock, (&(NAME).mutex), 0)
+#endif
+
+/* Define once control variable. */
+#if PTHREAD_ONCE_INIT == 0
+/* Special case for static variables where we can avoid the initialization
+ if it is zero. */
+# define __libc_once_define(CLASS, NAME) \
+ CLASS pthread_once_t NAME
+#else
+# define __libc_once_define(CLASS, NAME) \
+ CLASS pthread_once_t NAME = PTHREAD_ONCE_INIT
+#endif
+
+/* Call handler iff the first call. */
+#define __libc_once(ONCE_CONTROL, INIT_FUNCTION) \
+ do { \
+ if (PTF(__pthread_once) != NULL) \
+ PTF(__pthread_once) (&(ONCE_CONTROL), INIT_FUNCTION); \
+ else if ((ONCE_CONTROL) == PTHREAD_ONCE_INIT) { \
+ INIT_FUNCTION (); \
+ (ONCE_CONTROL) |= 2; \
+ } \
+ } while (0)
+
+
+/* Note that for I/O cleanup handling we are using the old-style
+ cancel handling. It does not have to be integrated with C++ snce
+ no C++ code is called in the middle. The old-style handling is
+ faster and the support is not going away. */
+extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer *buffer,
+ void (*routine) (void *), void *arg);
+extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *buffer,
+ int execute);
+extern void _pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer,
+ void (*routine) (void *), void *arg);
+extern void _pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer,
+ int execute);
+
+/* Start critical region with cleanup. */
+#define __libc_cleanup_region_start(DOIT, FCT, ARG) \
+ { struct _pthread_cleanup_buffer _buffer; \
+ int _avail; \
+ if (DOIT) { \
+ _avail = PTF(_pthread_cleanup_push_defer) != NULL; \
+ if (_avail) { \
+ PTF(_pthread_cleanup_push_defer) (&_buffer, FCT, ARG); \
+ } else { \
+ _buffer.__routine = (FCT); \
+ _buffer.__arg = (ARG); \
+ } \
+ } else { \
+ _avail = 0; \
+ }
+
+/* End critical region with cleanup. */
+#define __libc_cleanup_region_end(DOIT) \
+ if (_avail) { \
+ PTF(_pthread_cleanup_pop_restore) (&_buffer, DOIT); \
+ } else if (DOIT) \
+ _buffer.__routine (_buffer.__arg); \
+ }
+
+/* Sometimes we have to exit the block in the middle. */
+#define __libc_cleanup_end(DOIT) \
+ if (_avail) { \
+ PTF(_pthread_cleanup_pop_restore) (&_buffer, DOIT); \
+ } else if (DOIT) \
+ _buffer.__routine (_buffer.__arg)
+
+
+/* Normal cleanup handling, based on C cleanup attribute. */
+extern __inline void
+__libc_cleanup_routine (struct __pthread_cleanup_frame *f)
+{
+ if (f->__do_it)
+ f->__cancel_routine (f->__cancel_arg);
+}
+
+#define __libc_cleanup_push(fct, arg) \
+ do { \
+ struct __pthread_cleanup_frame __clframe \
+ __attribute__ ((__cleanup__ (__libc_cleanup_routine))) \
+ = { .__cancel_routine = (fct), .__cancel_arg = (arg), \
+ .__do_it = 1 };
+
+#define __libc_cleanup_pop(execute) \
+ __clframe.__do_it = (execute); \
+ } while (0)
+
+
+/* Create thread-specific key. */
+#define __libc_key_create(KEY, DESTRUCTOR) \
+ __libc_ptf_call (__pthread_key_create, (KEY, DESTRUCTOR), 1)
+
+/* Get thread-specific data. */
+#define __libc_getspecific(KEY) \
+ __libc_ptf_call (__pthread_getspecific, (KEY), NULL)
+
+/* Set thread-specific data. */
+#define __libc_setspecific(KEY, VALUE) \
+ __libc_ptf_call (__pthread_setspecific, (KEY, VALUE), 0)
+
+
+/* Register handlers to execute before and after `fork'. Note that the
+ last parameter is NULL. The handlers registered by the libc are
+ never removed so this is OK. */
+#define __libc_atfork(PREPARE, PARENT, CHILD) \
+ __register_atfork (PREPARE, PARENT, CHILD, NULL)
+extern int __register_atfork (void (*__prepare) (void),
+ void (*__parent) (void),
+ void (*__child) (void),
+ void *__dso_handle);
+
+/* Functions that are used by this file and are internal to the GNU C
+ library. */
+
+extern int __pthread_mutex_init (pthread_mutex_t *__mutex,
+ __const pthread_mutexattr_t *__mutex_attr);
+
+extern int __pthread_mutex_destroy (pthread_mutex_t *__mutex);
+
+extern int __pthread_mutex_trylock (pthread_mutex_t *__mutex);
+
+extern int __pthread_mutex_lock (pthread_mutex_t *__mutex);
+
+extern int __pthread_mutex_unlock (pthread_mutex_t *__mutex);
+
+extern int __pthread_mutexattr_init (pthread_mutexattr_t *__attr);
+
+extern int __pthread_mutexattr_destroy (pthread_mutexattr_t *__attr);
+
+extern int __pthread_mutexattr_settype (pthread_mutexattr_t *__attr,
+ int __kind);
+
+#ifdef __USE_UNIX98
+extern int __pthread_rwlock_init (pthread_rwlock_t *__rwlock,
+ __const pthread_rwlockattr_t *__attr);
+
+extern int __pthread_rwlock_destroy (pthread_rwlock_t *__rwlock);
+
+extern int __pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock);
+
+extern int __pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock);
+
+extern int __pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock);
+
+extern int __pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock);
+
+extern int __pthread_rwlock_unlock (pthread_rwlock_t *__rwlock);
+#endif
+
+extern int __pthread_key_create (pthread_key_t *__key,
+ void (*__destr_function) (void *));
+
+extern int __pthread_setspecific (pthread_key_t __key,
+ __const void *__pointer);
+
+extern void *__pthread_getspecific (pthread_key_t __key);
+
+extern int __pthread_once (pthread_once_t *__once_control,
+ void (*__init_routine) (void));
+
+extern int __pthread_atfork (void (*__prepare) (void),
+ void (*__parent) (void),
+ void (*__child) (void));
+
+
+
+/* Make the pthread functions weak so that we can elide them from
+ single-threaded processes. */
+#ifndef __NO_WEAK_PTHREAD_ALIASES
+# ifdef weak_extern
+# if _LIBC
+# include <bp-sym.h>
+# else
+# define BP_SYM (sym) sym
+# endif
+weak_extern (BP_SYM (__pthread_mutex_init))
+weak_extern (BP_SYM (__pthread_mutex_destroy))
+weak_extern (BP_SYM (__pthread_mutex_lock))
+weak_extern (BP_SYM (__pthread_mutex_trylock))
+weak_extern (BP_SYM (__pthread_mutex_unlock))
+weak_extern (BP_SYM (__pthread_mutexattr_init))
+weak_extern (BP_SYM (__pthread_mutexattr_destroy))
+weak_extern (BP_SYM (__pthread_mutexattr_settype))
+weak_extern (BP_SYM (__pthread_rwlock_init))
+weak_extern (BP_SYM (__pthread_rwlock_destroy))
+weak_extern (BP_SYM (__pthread_rwlock_rdlock))
+weak_extern (BP_SYM (__pthread_rwlock_tryrdlock))
+weak_extern (BP_SYM (__pthread_rwlock_wrlock))
+weak_extern (BP_SYM (__pthread_rwlock_trywrlock))
+weak_extern (BP_SYM (__pthread_rwlock_unlock))
+weak_extern (BP_SYM (__pthread_key_create))
+weak_extern (BP_SYM (__pthread_setspecific))
+weak_extern (BP_SYM (__pthread_getspecific))
+weak_extern (BP_SYM (__pthread_once))
+weak_extern (__pthread_initialize)
+weak_extern (__pthread_atfork)
+weak_extern (BP_SYM (_pthread_cleanup_push_defer))
+weak_extern (BP_SYM (_pthread_cleanup_pop_restore))
+weak_extern (BP_SYM (pthread_setcancelstate))
+# else
+# pragma weak __pthread_mutex_init
+# pragma weak __pthread_mutex_destroy
+# pragma weak __pthread_mutex_lock
+# pragma weak __pthread_mutex_trylock
+# pragma weak __pthread_mutex_unlock
+# pragma weak __pthread_mutexattr_init
+# pragma weak __pthread_mutexattr_destroy
+# pragma weak __pthread_mutexattr_settype
+# pragma weak __pthread_rwlock_destroy
+# pragma weak __pthread_rwlock_rdlock
+# pragma weak __pthread_rwlock_tryrdlock
+# pragma weak __pthread_rwlock_wrlock
+# pragma weak __pthread_rwlock_trywrlock
+# pragma weak __pthread_rwlock_unlock
+# pragma weak __pthread_key_create
+# pragma weak __pthread_setspecific
+# pragma weak __pthread_getspecific
+# pragma weak __pthread_once
+# pragma weak __pthread_initialize
+# pragma weak __pthread_atfork
+# pragma weak _pthread_cleanup_push_defer
+# pragma weak _pthread_cleanup_pop_restore
+# pragma weak pthread_setcancelstate
+# endif
+#endif
+
+#endif /* bits/libc-lock.h */
diff --git a/libc/nptl/sysdeps/pthread/bits/sigthread.h b/libc/nptl/sysdeps/pthread/bits/sigthread.h
new file mode 100644
index 000000000..960bde18a
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/bits/sigthread.h
@@ -0,0 +1,38 @@
+/* Signal handling function for threaded programs.
+ Copyright (C) 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _BITS_SIGTHREAD_H
+#define _BITS_SIGTHREAD_H 1
+
+#if !defined _SIGNAL_H && !defined _PTHREAD_H
+# error "Never include this file directly. Use <pthread.h> instead"
+#endif
+
+/* Functions for handling signals. */
+
+/* Modify the signal mask for the calling thread. The arguments have
+ the same meaning as for sigprocmask(2). */
+extern int pthread_sigmask (int __how,
+ __const __sigset_t *__restrict __newmask,
+ __sigset_t *__restrict __oldmask)__THROW;
+
+/* Send signal SIGNO to the given thread. */
+extern int pthread_kill (pthread_t __threadid, int __signo) __THROW;
+
+#endif /* bits/sigthread.h */
diff --git a/libc/nptl/sysdeps/pthread/bits/stdio-lock.h b/libc/nptl/sysdeps/pthread/bits/stdio-lock.h
new file mode 100644
index 000000000..cd64bc37e
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/bits/stdio-lock.h
@@ -0,0 +1,105 @@
+/* Thread package specific definitions of stream lock type. NPTL version.
+ Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+#ifndef _BITS_STDIO_LOCK_H
+#define _BITS_STDIO_LOCK_H 1
+
+#include <bits/libc-lock.h>
+#include <lowlevellock.h>
+
+
+/* The locking here is very inexpensive, even for inlining. */
+#define _IO_lock_inexpensive 1
+
+typedef struct { int lock; int cnt; void *owner; } _IO_lock_t;
+
+#define _IO_lock_initializer { LLL_LOCK_INITIALIZER, 0, NULL }
+
+#define _IO_lock_init(_name) \
+ ((_name) = (_IO_lock_t) _IO_lock_initializer , 0)
+
+#define _IO_lock_fini(_name) \
+ ((void) 0)
+
+#define _IO_lock_lock(_name) \
+ do { \
+ void *__self = THREAD_SELF; \
+ if ((_name).owner != __self) \
+ { \
+ lll_lock ((_name).lock); \
+ (_name).owner = __self; \
+ } \
+ ++(_name).cnt; \
+ } while (0)
+
+#define _IO_lock_trylock(_name) \
+ ({ \
+ int __result = 0; \
+ void *__self = THREAD_SELF; \
+ if ((_name).owner != __self) \
+ { \
+ if (lll_trylock ((_name).lock) == 0) \
+ { \
+ (_name).owner = __self; \
+ (_name).cnt = 1; \
+ } \
+ else \
+ __result = EBUSY; \
+ } \
+ else \
+ ++(_name).cnt; \
+ __result; \
+ })
+
+#define _IO_lock_unlock(_name) \
+ do { \
+ if (--(_name).cnt == 0) \
+ { \
+ (_name).owner = NULL; \
+ lll_unlock ((_name).lock); \
+ } \
+ } while (0)
+
+
+
+#define _IO_cleanup_region_start(_fct, _fp) \
+ __libc_cleanup_region_start (((_fp)->_flags & _IO_USER_LOCK) == 0, _fct, _fp)
+#define _IO_cleanup_region_start_noarg(_fct) \
+ __libc_cleanup_region_start (1, _fct, NULL)
+#define _IO_cleanup_region_end(_doit) \
+ __libc_cleanup_region_end (_doit)
+
+#if defined _LIBC && !defined NOT_IN_libc
+
+# ifdef __EXCEPTIONS
+# define _IO_acquire_lock(_fp) \
+ do { \
+ _IO_FILE *_IO_acquire_lock_file \
+ __attribute__((cleanup (_IO_acquire_lock_fct))) \
+ = (_fp); \
+ _IO_flockfile (_IO_acquire_lock_file);
+
+# else
+# define _IO_acquire_lock(_fp) _IO_acquire_lock_needs_exceptions_enabled
+# endif
+# define _IO_release_lock(_fp) ; } while (0)
+
+#endif
+
+#endif /* bits/stdio-lock.h */
diff --git a/libc/nptl/sysdeps/pthread/configure b/libc/nptl/sysdeps/pthread/configure
new file mode 100755
index 000000000..3cbe55e14
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/configure
@@ -0,0 +1,159 @@
+# This file is generated from configure.in by Autoconf. DO NOT EDIT!
+
+if test "x$libc_cv_gcc___thread" != xyes; then
+ { { echo "$as_me:$LINENO: error: compiler support for __thread is required" >&5
+echo "$as_me: error: compiler support for __thread is required" >&2;}
+ { (exit 1); exit 1; }; }
+fi
+
+if test "x${libc_cv_visibility_attribute}" != xyes ||
+ test "x${libc_cv_broken_visibility_attribute}" != xno; then
+ { { echo "$as_me:$LINENO: error: working compiler support for visibility attribute is required" >&5
+echo "$as_me: error: working compiler support for visibility attribute is required" >&2;}
+ { (exit 1); exit 1; }; }
+fi
+
+if test "x$libc_cv_asm_cfi_directives" != xyes; then
+ case "$base_machine" in
+ i386 | x86_64 | powerpc | s390)
+ { { echo "$as_me:$LINENO: error: CFI directive support in assembler is required" >&5
+echo "$as_me: error: CFI directive support in assembler is required" >&2;}
+ { (exit 1); exit 1; }; } ;;
+ *) ;;
+ esac
+fi
+
+
+echo "$as_me:$LINENO: checking for forced unwind support" >&5
+echo $ECHO_N "checking for forced unwind support... $ECHO_C" >&6
+if test "${libc_cv_forced_unwind+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+#include <unwind.h>
+int
+main ()
+{
+
+struct _Unwind_Exception exc;
+struct _Unwind_Context *context;
+_Unwind_GetCFA (context)
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ libc_cv_forced_unwind=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+libc_cv_forced_unwind=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $libc_cv_forced_unwind" >&5
+echo "${ECHO_T}$libc_cv_forced_unwind" >&6
+if test $libc_cv_forced_unwind = yes; then
+ cat >>confdefs.h <<\_ACEOF
+#define HAVE_FORCED_UNWIND 1
+_ACEOF
+
+ old_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS -Werror -fexceptions"
+ echo "$as_me:$LINENO: checking for C cleanup handling" >&5
+echo $ECHO_N "checking for C cleanup handling... $ECHO_C" >&6
+if test "${libc_cv_c_cleanup+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+
+#include <stdio.h>
+void cl (void *a) { }
+int
+main ()
+{
+
+ int a __attribute__ ((cleanup (cl)));
+ puts ("test")
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ libc_cv_c_cleanup=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+libc_cv_c_cleanup=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $libc_cv_c_cleanup" >&5
+echo "${ECHO_T}$libc_cv_c_cleanup" >&6
+ CFLAGS="$old_CFLAGS"
+ if test $libc_cv_c_cleanup = no; then
+ { { echo "$as_me:$LINENO: error: the compiler must support C cleanup handling" >&5
+echo "$as_me: error: the compiler must support C cleanup handling" >&2;}
+ { (exit 1); exit 1; }; }
+ fi
+else
+ { { echo "$as_me:$LINENO: error: forced unwind support is required" >&5
+echo "$as_me: error: forced unwind support is required" >&2;}
+ { (exit 1); exit 1; }; }
+fi
diff --git a/libc/nptl/sysdeps/pthread/configure.in b/libc/nptl/sysdeps/pthread/configure.in
new file mode 100644
index 000000000..17f18f0fb
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/configure.in
@@ -0,0 +1,49 @@
+dnl configure fragment for new libpthread implementation.
+GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
+
+if test "x$libc_cv_gcc___thread" != xyes; then
+ AC_MSG_ERROR(compiler support for __thread is required)
+fi
+
+if test "x${libc_cv_visibility_attribute}" != xyes ||
+ test "x${libc_cv_broken_visibility_attribute}" != xno; then
+ AC_MSG_ERROR(working compiler support for visibility attribute is required)
+fi
+
+if test "x$libc_cv_asm_cfi_directives" != xyes; then
+ dnl We need this only for some architectures.
+ case "$base_machine" in
+ i386 | x86_64 | powerpc | s390)
+ AC_MSG_ERROR(CFI directive support in assembler is required) ;;
+ *) ;;
+ esac
+fi
+
+dnl Iff <unwind.h> is available, make sure it is the right one and it
+dnl contains struct _Unwind_Exception.
+AC_CACHE_CHECK(dnl
+for forced unwind support, libc_cv_forced_unwind, [dnl
+AC_TRY_LINK([#include <unwind.h>], [
+struct _Unwind_Exception exc;
+struct _Unwind_Context *context;
+_Unwind_GetCFA (context)],
+libc_cv_forced_unwind=yes, libc_cv_forced_unwind=no)])
+if test $libc_cv_forced_unwind = yes; then
+ AC_DEFINE(HAVE_FORCED_UNWIND)
+dnl Check for C cleanup handling.
+ old_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS -Werror -fexceptions"
+ AC_CACHE_CHECK([for C cleanup handling], libc_cv_c_cleanup, [dnl
+ AC_TRY_LINK([
+#include <stdio.h>
+void cl (void *a) { }], [
+ int a __attribute__ ((cleanup (cl)));
+ puts ("test")],
+libc_cv_c_cleanup=yes, libc_cv_c_cleanup=no)])
+ CFLAGS="$old_CFLAGS"
+ if test $libc_cv_c_cleanup = no; then
+ AC_MSG_ERROR([the compiler must support C cleanup handling])
+ fi
+else
+ AC_MSG_ERROR(forced unwind support is required)
+fi
diff --git a/libc/nptl/sysdeps/pthread/createthread.c b/libc/nptl/sysdeps/pthread/createthread.c
new file mode 100644
index 000000000..03a0f1aa3
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/createthread.c
@@ -0,0 +1,255 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sched.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <atomic.h>
+#include <ldsodefs.h>
+#include <tls.h>
+
+#include "kernel-features.h"
+
+
+#define CLONE_SIGNAL (CLONE_SIGHAND | CLONE_THREAD)
+
+/* Unless otherwise specified, the thread "register" is going to be
+ initialized with a pointer to the TCB. */
+#ifndef TLS_VALUE
+# define TLS_VALUE pd
+#endif
+
+#ifndef ARCH_CLONE
+# define ARCH_CLONE __clone
+#endif
+
+
+#ifndef TLS_MULTIPLE_THREADS_IN_TCB
+/* Pointer to the corresponding variable in libc. */
+int *__libc_multiple_threads_ptr attribute_hidden;
+#endif
+
+
+static int
+do_clone (struct pthread *pd, const struct pthread_attr *attr,
+ int clone_flags, int (*fct) (void *), STACK_VARIABLES_PARMS,
+ int stopped)
+{
+#ifdef PREPARE_CREATE
+ PREPARE_CREATE;
+#endif
+
+ if (stopped)
+ /* We Make sure the thread does not run far by forcing it to get a
+ lock. We lock it here too so that the new thread cannot continue
+ until we tell it to. */
+ lll_lock (pd->lock);
+
+ /* One more thread. We cannot have the thread do this itself, since it
+ might exist but not have been scheduled yet by the time we've returned
+ and need to check the value to behave correctly. We must do it before
+ creating the thread, in case it does get scheduled first and then
+ might mistakenly think it was the only thread. In the failure case,
+ we momentarily store a false value; this doesn't matter because there
+ is no kosher thing a signal handler interrupting us right here can do
+ that cares whether the thread count is correct. */
+ atomic_increment (&__nptl_nthreads);
+
+ if (ARCH_CLONE (fct, STACK_VARIABLES_ARGS, clone_flags,
+ pd, &pd->tid, TLS_VALUE, &pd->tid) == -1)
+ {
+ atomic_decrement (&__nptl_nthreads); /* Oops, we lied for a second. */
+
+ /* Failed. If the thread is detached, remove the TCB here since
+ the caller cannot do this. The caller remembered the thread
+ as detached and cannot reverify that it is not since it must
+ not access the thread descriptor again. */
+ if (IS_DETACHED (pd))
+ __deallocate_stack (pd);
+
+ return errno;
+ }
+
+ /* Now we have the possibility to set scheduling parameters etc. */
+ if (__builtin_expect (stopped != 0, 0))
+ {
+ INTERNAL_SYSCALL_DECL (err);
+ int res = 0;
+
+ /* Set the affinity mask if necessary. */
+ if (attr->cpuset != NULL)
+ {
+ res = INTERNAL_SYSCALL (sched_setaffinity, err, 3, pd->tid,
+ sizeof (cpu_set_t), attr->cpuset);
+
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (res, err), 0))
+ {
+ /* The operation failed. We have to kill the thread. First
+ send it the cancellation signal. */
+ INTERNAL_SYSCALL_DECL (err2);
+ err_out:
+#if __ASSUME_TGKILL
+ (void) INTERNAL_SYSCALL (tgkill, err2, 3,
+ THREAD_GETMEM (THREAD_SELF, pid),
+ pd->tid, SIGCANCEL);
+#else
+ (void) INTERNAL_SYSCALL (tkill, err2, 2, pd->tid, SIGCANCEL);
+#endif
+
+ return (INTERNAL_SYSCALL_ERROR_P (res, err)
+ ? INTERNAL_SYSCALL_ERRNO (res, err)
+ : 0);
+ }
+ }
+
+ /* Set the scheduling parameters. */
+ if ((attr->flags & ATTR_FLAG_NOTINHERITSCHED) != 0)
+ {
+ res = INTERNAL_SYSCALL (sched_setscheduler, err, 3, pd->tid,
+ pd->schedpolicy, &pd->schedparam);
+
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (res, err), 0))
+ goto err_out;
+ }
+ }
+
+ /* We now have for sure more than one thread. The main thread might
+ not yet have the flag set. No need to set the global variable
+ again if this is what we use. */
+ THREAD_SETMEM (THREAD_SELF, header.multiple_threads, 1);
+
+ return 0;
+}
+
+
+static int
+create_thread (struct pthread *pd, const struct pthread_attr *attr,
+ STACK_VARIABLES_PARMS)
+{
+#ifdef TLS_TCB_AT_TP
+ assert (pd->header.tcb != NULL);
+#endif
+
+ /* We rely heavily on various flags the CLONE function understands:
+
+ CLONE_VM, CLONE_FS, CLONE_FILES
+ These flags select semantics with shared address space and
+ file descriptors according to what POSIX requires.
+
+ CLONE_SIGNAL
+ This flag selects the POSIX signal semantics.
+
+ CLONE_SETTLS
+ The sixth parameter to CLONE determines the TLS area for the
+ new thread.
+
+ CLONE_PARENT_SETTID
+ The kernels writes the thread ID of the newly created thread
+ into the location pointed to by the fifth parameters to CLONE.
+
+ Note that it would be semantically equivalent to use
+ CLONE_CHILD_SETTID but it is be more expensive in the kernel.
+
+ CLONE_CHILD_CLEARTID
+ The kernels clears the thread ID of a thread that has called
+ sys_exit() in the location pointed to by the seventh parameter
+ to CLONE.
+
+ CLONE_DETACHED
+ No signal is generated if the thread exists and it is
+ automatically reaped.
+
+ The termination signal is chosen to be zero which means no signal
+ is sent. */
+ int clone_flags = (CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGNAL
+ | CLONE_SETTLS | CLONE_PARENT_SETTID
+ | CLONE_CHILD_CLEARTID | CLONE_SYSVSEM
+#if __ASSUME_NO_CLONE_DETACHED == 0
+ | CLONE_DETACHED
+#endif
+ | 0);
+
+ if (__builtin_expect (THREAD_GETMEM (THREAD_SELF, report_events), 0))
+ {
+ /* The parent thread is supposed to report events. Check whether
+ the TD_CREATE event is needed, too. */
+ const int _idx = __td_eventword (TD_CREATE);
+ const uint32_t _mask = __td_eventmask (TD_CREATE);
+
+ if ((_mask & (__nptl_threads_events.event_bits[_idx]
+ | pd->eventbuf.eventmask.event_bits[_idx])) != 0)
+ {
+ /* We always must have the thread start stopped. */
+ pd->stopped_start = true;
+
+ /* Create the thread. We always create the thread stopped
+ so that it does not get far before we tell the debugger. */
+ int res = do_clone (pd, attr, clone_flags, start_thread,
+ STACK_VARIABLES_ARGS, 1);
+ if (res == 0)
+ {
+ /* Now fill in the information about the new thread in
+ the newly created thread's data structure. We cannot let
+ the new thread do this since we don't know whether it was
+ already scheduled when we send the event. */
+ pd->eventbuf.eventnum = TD_CREATE;
+ pd->eventbuf.eventdata = pd;
+
+ /* Enqueue the descriptor. */
+ do
+ pd->nextevent = __nptl_last_event;
+ while (atomic_compare_and_exchange_bool_acq (&__nptl_last_event,
+ pd, pd->nextevent)
+ != 0);
+
+ /* Now call the function which signals the event. */
+ __nptl_create_event ();
+
+ /* And finally restart the new thread. */
+ lll_unlock (pd->lock);
+ }
+
+ return res;
+ }
+ }
+
+#ifdef NEED_DL_SYSINFO
+ assert (THREAD_SELF_SYSINFO == THREAD_SYSINFO (pd));
+#endif
+
+ /* Determine whether the newly created threads has to be started
+ stopped since we have to set the scheduling parameters or set the
+ affinity. */
+ bool stopped = false;
+ if (attr != NULL && (attr->cpuset != NULL
+ || (attr->flags & ATTR_FLAG_NOTINHERITSCHED) != 0))
+ stopped = true;
+ pd->stopped_start = stopped;
+
+ /* Actually create the thread. */
+ int res = do_clone (pd, attr, clone_flags, start_thread,
+ STACK_VARIABLES_ARGS, stopped);
+
+ if (res == 0 && stopped)
+ /* And finally restart the new thread. */
+ lll_unlock (pd->lock);
+
+ return res;
+}
diff --git a/libc/nptl/sysdeps/pthread/flockfile.c b/libc/nptl/sysdeps/pthread/flockfile.c
new file mode 100644
index 000000000..918cb84f6
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/flockfile.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+#include <libio.h>
+#include <bits/stdio-lock.h>
+
+
+void
+__flockfile (stream)
+ FILE *stream;
+{
+ _IO_lock_lock (*stream->_lock);
+}
+strong_alias (__flockfile, _IO_flockfile)
+weak_alias (__flockfile, flockfile)
diff --git a/libc/nptl/sysdeps/pthread/ftrylockfile.c b/libc/nptl/sysdeps/pthread/ftrylockfile.c
new file mode 100644
index 000000000..21c1ea01e
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/ftrylockfile.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <bits/stdio-lock.h>
+
+
+int
+__ftrylockfile (stream)
+ FILE *stream;
+{
+ return _IO_lock_trylock (*stream->_lock);
+}
+strong_alias (__ftrylockfile, _IO_ftrylockfile)
+weak_alias (__ftrylockfile, ftrylockfile)
diff --git a/libc/nptl/sysdeps/pthread/funlockfile.c b/libc/nptl/sysdeps/pthread/funlockfile.c
new file mode 100644
index 000000000..f941fc985
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/funlockfile.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+#include <libio.h>
+#include <bits/stdio-lock.h>
+
+
+void
+__funlockfile (stream)
+ FILE *stream;
+{
+ _IO_lock_unlock (*stream->_lock);
+}
+strong_alias (__funlockfile, _IO_funlockfile)
+weak_alias (__funlockfile, funlockfile)
diff --git a/libc/nptl/sysdeps/pthread/gai_misc.h b/libc/nptl/sysdeps/pthread/gai_misc.h
new file mode 100644
index 000000000..1dc351a2d
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/gai_misc.h
@@ -0,0 +1,119 @@
+/* Copyright (C) 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+/* We define a special synchronization primitive for AIO. POSIX
+ conditional variables would be ideal but the pthread_cond_*wait
+ operations do not return on EINTR. This is a requirement for
+ correct aio_suspend and lio_listio implementations. */
+
+#include <assert.h>
+#include <signal.h>
+#include <pthreadP.h>
+#include <lowlevellock.h>
+
+#define DONT_NEED_GAI_MISC_COND 1
+
+#define GAI_MISC_NOTIFY(waitlist) \
+ do { \
+ if (--*waitlist->counterp == 0) \
+ lll_futex_wake (waitlist->counterp, 1); \
+ } while (0)
+
+#define GAI_MISC_WAIT(result, futex, timeout, cancel) \
+ do { \
+ volatile int *futexaddr = &futex; \
+ int oldval = futex; \
+ \
+ if (oldval != 0) \
+ { \
+ pthread_mutex_unlock (&__gai_requests_mutex); \
+ \
+ int oldtype; \
+ if (cancel) \
+ oldtype = LIBC_CANCEL_ASYNC (); \
+ \
+ int status; \
+ do \
+ { \
+ status = lll_futex_timed_wait (futexaddr, oldval, timeout); \
+ if (status != -EWOULDBLOCK) \
+ break; \
+ \
+ oldval = *futexaddr; \
+ } \
+ while (oldval != 0); \
+ \
+ if (cancel) \
+ LIBC_CANCEL_RESET (oldtype); \
+ \
+ if (status == -EINTR) \
+ result = EINTR; \
+ else if (status == -ETIMEDOUT) \
+ result = EAGAIN; \
+ else \
+ assert (status == 0 || status == -EWOULDBLOCK); \
+ \
+ pthread_mutex_lock (&__gai_requests_mutex); \
+ } \
+ } while (0)
+
+
+#define gai_start_notify_thread __gai_start_notify_thread
+#define gai_create_helper_thread __gai_create_helper_thread
+
+extern inline void
+__gai_start_notify_thread (void)
+{
+ sigset_t ss;
+ sigemptyset (&ss);
+ INTERNAL_SYSCALL_DECL (err);
+ INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, &ss, NULL, _NSIG / 8);
+}
+
+extern inline int
+__gai_create_helper_thread (pthread_t *threadp, void *(*tf) (void *),
+ void *arg)
+{
+ pthread_attr_t attr;
+
+ /* Make sure the thread is created detached. */
+ pthread_attr_init (&attr);
+ pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
+
+ /* The helper thread needs only very little resources. */
+ (void) pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
+
+ /* Block all signals in the helper thread. To do this thoroughly we
+ temporarily have to block all signals here. */
+ sigset_t ss;
+ sigset_t oss;
+ sigfillset (&ss);
+ INTERNAL_SYSCALL_DECL (err);
+ INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, &ss, &oss, _NSIG / 8);
+
+ int ret = pthread_create (threadp, &attr, tf, arg);
+
+ /* Restore the signal mask. */
+ INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, &oss, NULL,
+ _NSIG / 8);
+
+ (void) pthread_attr_destroy (&attr);
+ return ret;
+}
+
+#include_next <gai_misc.h>
diff --git a/libc/nptl/sysdeps/pthread/librt-cancellation.c b/libc/nptl/sysdeps/pthread/librt-cancellation.c
new file mode 100644
index 000000000..753a2d831
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/librt-cancellation.c
@@ -0,0 +1,108 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <setjmp.h>
+#include <signal.h>
+#include <stdlib.h>
+#include "pthreadP.h"
+#include "atomic.h"
+
+
+#ifdef IS_IN_librt
+/* The next two functions are similar to pthread_setcanceltype() but
+ more specialized for the use in the cancelable functions like write().
+ They do not need to check parameters etc. */
+int
+attribute_hidden
+__librt_enable_asynccancel (void)
+{
+ struct pthread *self = THREAD_SELF;
+ int oldval = THREAD_GETMEM (self, cancelhandling);
+
+ while (1)
+ {
+ int newval = oldval | CANCELTYPE_BITMASK;
+
+ if (__builtin_expect ((oldval & CANCELED_BITMASK) != 0, 0))
+ {
+ /* If we are already exiting or if PTHREAD_CANCEL_DISABLED,
+ stop right here. */
+ if ((oldval & (EXITING_BITMASK | CANCELSTATE_BITMASK)) != 0)
+ break;
+
+ int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling,
+ newval, oldval);
+ if (__builtin_expect (curval != oldval, 0))
+ {
+ /* Somebody else modified the word, try again. */
+ oldval = curval;
+ continue;
+ }
+
+ THREAD_SETMEM (self, result, PTHREAD_CANCELED);
+
+ __do_cancel ();
+
+ /* NOTREACHED */
+ }
+
+ int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
+ oldval);
+ if (__builtin_expect (curval == oldval, 1))
+ break;
+
+ /* Prepare the next round. */
+ oldval = curval;
+ }
+
+ return oldval;
+}
+
+
+void
+internal_function attribute_hidden
+__librt_disable_asynccancel (int oldtype)
+{
+ /* If asynchronous cancellation was enabled before we do not have
+ anything to do. */
+ if (oldtype & CANCELTYPE_BITMASK)
+ return;
+
+ struct pthread *self = THREAD_SELF;
+ int oldval = THREAD_GETMEM (self, cancelhandling);
+
+ while (1)
+ {
+ int newval = oldval & ~CANCELTYPE_BITMASK;
+
+ if (newval == oldval)
+ break;
+
+ int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
+ oldval);
+ if (__builtin_expect (curval == oldval, 1))
+ break;
+
+ /* Prepare the next round. */
+ oldval = curval;
+ }
+}
+
+
+#endif
diff --git a/libc/nptl/sysdeps/pthread/list.h b/libc/nptl/sysdeps/pthread/list.h
new file mode 100644
index 000000000..43186a2d5
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/list.h
@@ -0,0 +1,114 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+#ifndef _LIST_H
+#define _LIST_H 1
+
+/* The definitions of this file are adopted from those which can be
+ found in the Linux kernel headers to enable people familiar with
+ the latter find their way in these sources as well. */
+
+
+/* Basic type for the double-link list. */
+typedef struct list_head
+{
+ struct list_head *next;
+ struct list_head *prev;
+} list_t;
+
+
+/* Define a variable with the head and tail of the list. */
+#define LIST_HEAD(name) \
+ list_t name = { &(name), &(name) }
+
+/* Initialize a new list head. */
+#define INIT_LIST_HEAD(ptr) \
+ (ptr)->next = (ptr)->prev = (ptr)
+
+
+/* Add new element at the head of the list. */
+static inline void
+list_add (list_t *newp, list_t *head)
+{
+ head->next->prev = newp;
+ newp->next = head->next;
+ newp->prev = head;
+ head->next = newp;
+}
+
+
+/* Add new element at the tail of the list. */
+static inline void
+list_add_tail (list_t *newp, list_t *head)
+{
+ head->prev->next = newp;
+ newp->next = head;
+ newp->prev = head->prev;
+ head->prev = newp;
+}
+
+
+/* Remove element from list. */
+static inline void
+list_del (list_t *elem)
+{
+ elem->next->prev = elem->prev;
+ elem->prev->next = elem->next;
+}
+
+
+/* Join two lists. */
+static inline void
+list_splice (list_t *add, list_t *head)
+{
+ /* Do nothing if the list which gets added is empty. */
+ if (add != add->next)
+ {
+ add->next->prev = head;
+ add->prev->next = head->next;
+ head->next->prev = add->prev;
+ head->next = add->next;
+ }
+}
+
+
+/* Get typed element from list at a given position. */
+#define list_entry(ptr, type, member) \
+ ((type *) ((char *) (ptr) - (unsigned long) (&((type *) 0)->member)))
+
+
+
+/* Iterate forward over the elements of the list. */
+#define list_for_each(pos, head) \
+ for (pos = (head)->next; pos != (head); pos = pos->next)
+
+
+/* Iterate forward over the elements of the list. */
+#define list_for_each_prev(pos, head) \
+ for (pos = (head)->prev; pos != (head); pos = pos->prev)
+
+
+/* Iterate backwards over the elements list. The list elements can be
+ removed from the list while doing this. */
+#define list_for_each_prev_safe(pos, p, head) \
+ for (pos = (head)->prev, p = pos->prev; \
+ pos != (head); \
+ pos = p, p = pos->prev)
+
+#endif /* list.h */
diff --git a/libc/nptl/sysdeps/pthread/malloc-machine.h b/libc/nptl/sysdeps/pthread/malloc-machine.h
new file mode 100644
index 000000000..efab230aa
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/malloc-machine.h
@@ -0,0 +1,62 @@
+/* Basic platform-independent macro definitions for mutexes,
+ thread-specific data and parameters for malloc.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+#ifndef _MALLOC_MACHINE_H
+#define _MALLOC_MACHINE_H
+
+#undef thread_atfork_static
+
+#include <atomic.h>
+#include <bits/libc-lock.h>
+
+__libc_lock_define (typedef, mutex_t)
+
+#define mutex_init(m) __libc_lock_init (*(m))
+#define mutex_lock(m) __libc_lock_lock (*(m))
+#define mutex_trylock(m) __libc_lock_trylock (*(m))
+#define mutex_unlock(m) __libc_lock_unlock (*(m))
+
+/* This is defined by newer gcc version unique for each module. */
+extern void *__dso_handle __attribute__ ((__weak__));
+
+#include <fork.h>
+
+#ifdef SHARED
+# define thread_atfork(prepare, parent, child) \
+ __register_atfork (prepare, parent, child, __dso_handle)
+#else
+# define thread_atfork(prepare, parent, child) \
+ __register_atfork (prepare, parent, child, \
+ &__dso_handle == NULL ? NULL : __dso_handle)
+#endif
+
+/* thread specific data for glibc */
+
+#include <bits/libc-tsd.h>
+
+typedef int tsd_key_t[1]; /* no key data structure, libc magic does it */
+__libc_tsd_define (static, MALLOC) /* declaration/common definition */
+#define tsd_key_create(key, destr) ((void) (key))
+#define tsd_setspecific(key, data) __libc_tsd_set (MALLOC, (data))
+#define tsd_getspecific(key, vptr) ((vptr) = __libc_tsd_get (MALLOC))
+
+#include <sysdeps/generic/malloc-machine.h>
+
+#endif /* !defined(_MALLOC_MACHINE_H) */
diff --git a/libc/nptl/sysdeps/pthread/posix-timer.h b/libc/nptl/sysdeps/pthread/posix-timer.h
new file mode 100644
index 000000000..8b4cbc8cd
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/posix-timer.h
@@ -0,0 +1,197 @@
+/* Definitions for POSIX timer implementation on top of NPTL.
+ Copyright (C) 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Kaz Kylheku <kaz@ashi.footprints.net>.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <limits.h>
+#include <signal.h>
+
+/* Double linked list. */
+struct list_links
+{
+ struct list_links *next;
+ struct list_links *prev;
+};
+
+
+/* Forward declaration. */
+struct timer_node;
+
+
+/* Definitions for an internal thread of the POSIX timer implementation. */
+struct thread_node
+{
+ struct list_links links;
+ pthread_attr_t attr;
+ pthread_t id;
+ unsigned int exists;
+ struct list_links timer_queue;
+ pthread_cond_t cond;
+ struct timer_node *current_timer;
+ pthread_t captured;
+ clockid_t clock_id;
+};
+
+
+/* Internal representation of a timer. */
+struct timer_node
+{
+ struct list_links links;
+ struct sigevent event;
+ clockid_t clock;
+ struct itimerspec value;
+ struct timespec expirytime;
+ pthread_attr_t attr;
+ unsigned int abstime;
+ unsigned int armed;
+ enum {
+ TIMER_FREE, TIMER_INUSE, TIMER_DELETED
+ } inuse;
+ struct thread_node *thread;
+ pid_t creator_pid;
+ int refcount;
+ int overrun_count;
+};
+
+
+/* The limit is not published if we are compiled with kernel timer support.
+ But we still compiled in this implementation with its limit unless built
+ to require the kernel support. */
+#ifndef TIMER_MAX
+# define TIMER_MAX 256
+#endif
+
+/* Static array with the structures for all the timers. */
+extern struct timer_node __timer_array[TIMER_MAX];
+
+/* Global lock to protect operation on the lists. */
+extern pthread_mutex_t __timer_mutex;
+
+/* Variable to protext initialization. */
+extern pthread_once_t __timer_init_once_control;
+
+/* Nonzero if initialization of timer implementation failed. */
+extern int __timer_init_failed;
+
+/* Node for the thread used to deliver signals. */
+extern struct thread_node __timer_signal_thread_rclk;
+
+
+/* Return pointer to timer structure corresponding to ID. */
+#define timer_id2ptr(timerid) ((struct timer_node *) timerid)
+#define timer_ptr2id(timerid) ((void *) timerid)
+
+/* Check whether timer is valid; global mutex must be held. */
+static inline int
+timer_valid (struct timer_node *timer)
+{
+ return timer && timer->inuse == TIMER_INUSE;
+}
+
+/* Timer refcount functions; need global mutex. */
+extern void __timer_dealloc (struct timer_node *timer);
+
+static inline void
+timer_addref (struct timer_node *timer)
+{
+ timer->refcount++;
+}
+
+static inline void
+timer_delref (struct timer_node *timer)
+{
+ if (--timer->refcount == 0)
+ __timer_dealloc (timer);
+}
+
+/* Timespec helper routines. */
+static inline int
+__attribute ((always_inline))
+timespec_compare (const struct timespec *left, const struct timespec *right)
+{
+ if (left->tv_sec < right->tv_sec)
+ return -1;
+ if (left->tv_sec > right->tv_sec)
+ return 1;
+
+ if (left->tv_nsec < right->tv_nsec)
+ return -1;
+ if (left->tv_nsec > right->tv_nsec)
+ return 1;
+
+ return 0;
+}
+
+static inline void
+timespec_add (struct timespec *sum, const struct timespec *left,
+ const struct timespec *right)
+{
+ sum->tv_sec = left->tv_sec + right->tv_sec;
+ sum->tv_nsec = left->tv_nsec + right->tv_nsec;
+
+ if (sum->tv_nsec >= 1000000000)
+ {
+ ++sum->tv_sec;
+ sum->tv_nsec -= 1000000000;
+ }
+}
+
+static inline void
+timespec_sub (struct timespec *diff, const struct timespec *left,
+ const struct timespec *right)
+{
+ diff->tv_sec = left->tv_sec - right->tv_sec;
+ diff->tv_nsec = left->tv_nsec - right->tv_nsec;
+
+ if (diff->tv_nsec < 0)
+ {
+ --diff->tv_sec;
+ diff->tv_nsec += 1000000000;
+ }
+}
+
+
+/* We need one of the list functions in the other modules. */
+static inline void
+list_unlink_ip (struct list_links *list)
+{
+ struct list_links *lnext = list->next, *lprev = list->prev;
+
+ lnext->prev = lprev;
+ lprev->next = lnext;
+
+ /* The suffix ip means idempotent; list_unlink_ip can be called
+ * two or more times on the same node.
+ */
+
+ list->next = list;
+ list->prev = list;
+}
+
+
+/* Functions in the helper file. */
+extern void __timer_mutex_cancel_handler (void *arg);
+extern void __timer_init_once (void);
+extern struct timer_node *__timer_alloc (void);
+extern int __timer_thread_start (struct thread_node *thread);
+extern struct thread_node *__timer_thread_find_matching (const pthread_attr_t *desired_attr, clockid_t);
+extern struct thread_node *__timer_thread_alloc (const pthread_attr_t *desired_attr, clockid_t);
+extern void __timer_thread_dealloc (struct thread_node *thread);
+extern int __timer_thread_queue_timer (struct thread_node *thread,
+ struct timer_node *insert);
+extern void __timer_thread_wakeup (struct thread_node *thread);
diff --git a/libc/nptl/sysdeps/pthread/pt-initfini.c b/libc/nptl/sysdeps/pthread/pt-initfini.c
new file mode 100644
index 000000000..1e35edd3e
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/pt-initfini.c
@@ -0,0 +1,125 @@
+/* Special .init and .fini section support. Linuxthread version.
+ Copyright (C) 1995,1996,1997,2000,2001,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 of the License, or (at your option) any later version.
+
+ In addition to the permissions in the GNU Lesser General Public
+ License, the Free Software Foundation gives you unlimited
+ permission to link the compiled version of this file with other
+ programs, and to distribute those programs without any restriction
+ coming from the use of this file. (The Library General Public
+ License restrictions do apply in other respects; for example, they
+ cover modification of the file, and distribution when not linked
+ into another program.)
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* This file is compiled into assembly code which is then munged by a sed
+ script into two files: crti.s and crtn.s.
+
+ * crti.s puts a function prologue at the beginning of the
+ .init and .fini sections and defines global symbols for
+ those addresses, so they can be called as functions.
+
+ * crtn.s puts the corresponding function epilogues
+ in the .init and .fini sections. */
+
+#include <stdlib.h>
+
+/* We use embedded asm for .section unconditionally, as this makes it
+ easier to insert the necessary directives into crtn.S. */
+#define SECTION(x) asm (".section " x )
+
+/* Embed an #include to pull in the alignment and .end directives. */
+asm ("\n#include \"defs.h\"");
+
+/* The initial common code ends here. */
+asm ("\n/*@HEADER_ENDS*/");
+
+/* To determine whether we need .end and .align: */
+asm ("\n/*@TESTS_BEGIN*/");
+extern void dummy (void (*foo) (void));
+void
+dummy (void (*foo) (void))
+{
+ if (foo)
+ (*foo) ();
+}
+asm ("\n/*@TESTS_END*/");
+
+/* The beginning of _init: */
+asm ("\n/*@_init_PROLOG_BEGINS*/");
+
+static void
+call_initialize_minimal (void)
+{
+ extern void __pthread_initialize_minimal_internal (void)
+ __attribute ((visibility ("hidden")));
+
+ __pthread_initialize_minimal_internal ();
+}
+
+SECTION (".init");
+extern void _init (void);
+void
+_init (void)
+{
+ /* The very first thing we must do is to set up the registers. */
+ call_initialize_minimal ();
+
+ asm ("ALIGN");
+ asm("END_INIT");
+ /* Now the epilog. */
+ asm ("\n/*@_init_PROLOG_ENDS*/");
+ asm ("\n/*@_init_EPILOG_BEGINS*/");
+ SECTION(".init");
+}
+asm ("END_INIT");
+
+/* End of the _init epilog, beginning of the _fini prolog. */
+asm ("\n/*@_init_EPILOG_ENDS*/");
+asm ("\n/*@_fini_PROLOG_BEGINS*/");
+
+SECTION (".fini");
+extern void _fini (void);
+void
+_fini (void)
+{
+
+ /* End of the _fini prolog. */
+ asm ("ALIGN");
+ asm ("END_FINI");
+ asm ("\n/*@_fini_PROLOG_ENDS*/");
+
+ {
+ /* Let GCC know that _fini is not a leaf function by having a dummy
+ function call here. We arrange for this call to be omitted from
+ either crt file. */
+ extern void i_am_not_a_leaf (void);
+ i_am_not_a_leaf ();
+ }
+
+ /* Beginning of the _fini epilog. */
+ asm ("\n/*@_fini_EPILOG_BEGINS*/");
+ SECTION (".fini");
+}
+asm ("END_FINI");
+
+/* End of the _fini epilog. Any further generated assembly (e.g. .ident)
+ is shared between both crt files. */
+asm ("\n/*@_fini_EPILOG_ENDS*/");
+asm ("\n/*@TRAILER_BEGINS*/");
+
+/* End of file. */
diff --git a/libc/nptl/sysdeps/pthread/pt-longjmp.c b/libc/nptl/sysdeps/pthread/pt-longjmp.c
new file mode 100644
index 000000000..f161380ea
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/pt-longjmp.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <setjmp.h>
+#include <stdlib.h>
+#include "pthreadP.h"
+
+void
+longjmp (jmp_buf env, int val)
+{
+ __libc_longjmp (env, val);
+}
+weak_alias (longjmp, siglongjmp)
diff --git a/libc/nptl/sysdeps/pthread/pthread-functions.h b/libc/nptl/sysdeps/pthread/pthread-functions.h
new file mode 100644
index 000000000..d75bbbb11
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/pthread-functions.h
@@ -0,0 +1,103 @@
+/* Copyright (C) 2003, 2004, 2005 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. */
+
+#ifndef _PTHREAD_FUNCTIONS_H
+#define _PTHREAD_FUNCTIONS_H 1
+
+#include <pthread.h>
+#include <setjmp.h>
+#include <internaltypes.h>
+
+struct xid_command;
+
+/* Data type shared with libc. The libc uses it to pass on calls to
+ the thread functions. */
+struct pthread_functions
+{
+ int (*ptr_pthread_attr_destroy) (pthread_attr_t *);
+ int (*ptr___pthread_attr_init_2_0) (pthread_attr_t *);
+ int (*ptr___pthread_attr_init_2_1) (pthread_attr_t *);
+ int (*ptr_pthread_attr_getdetachstate) (const pthread_attr_t *, int *);
+ int (*ptr_pthread_attr_setdetachstate) (pthread_attr_t *, int);
+ int (*ptr_pthread_attr_getinheritsched) (const pthread_attr_t *, int *);
+ int (*ptr_pthread_attr_setinheritsched) (pthread_attr_t *, int);
+ int (*ptr_pthread_attr_getschedparam) (const pthread_attr_t *,
+ struct sched_param *);
+ int (*ptr_pthread_attr_setschedparam) (pthread_attr_t *,
+ const struct sched_param *);
+ int (*ptr_pthread_attr_getschedpolicy) (const pthread_attr_t *, int *);
+ int (*ptr_pthread_attr_setschedpolicy) (pthread_attr_t *, int);
+ int (*ptr_pthread_attr_getscope) (const pthread_attr_t *, int *);
+ int (*ptr_pthread_attr_setscope) (pthread_attr_t *, int);
+ int (*ptr_pthread_condattr_destroy) (pthread_condattr_t *);
+ int (*ptr_pthread_condattr_init) (pthread_condattr_t *);
+ int (*ptr___pthread_cond_broadcast) (pthread_cond_t *);
+ int (*ptr___pthread_cond_destroy) (pthread_cond_t *);
+ int (*ptr___pthread_cond_init) (pthread_cond_t *,
+ const pthread_condattr_t *);
+ int (*ptr___pthread_cond_signal) (pthread_cond_t *);
+ int (*ptr___pthread_cond_wait) (pthread_cond_t *, pthread_mutex_t *);
+ int (*ptr___pthread_cond_timedwait) (pthread_cond_t *, pthread_mutex_t *,
+ const struct timespec *);
+ int (*ptr___pthread_cond_broadcast_2_0) (pthread_cond_2_0_t *);
+ int (*ptr___pthread_cond_destroy_2_0) (pthread_cond_2_0_t *);
+ int (*ptr___pthread_cond_init_2_0) (pthread_cond_2_0_t *,
+ const pthread_condattr_t *);
+ int (*ptr___pthread_cond_signal_2_0) (pthread_cond_2_0_t *);
+ int (*ptr___pthread_cond_wait_2_0) (pthread_cond_2_0_t *, pthread_mutex_t *);
+ int (*ptr___pthread_cond_timedwait_2_0) (pthread_cond_2_0_t *,
+ pthread_mutex_t *,
+ const struct timespec *);
+ int (*ptr_pthread_equal) (pthread_t, pthread_t);
+ void (*ptr___pthread_exit) (void *);
+ int (*ptr_pthread_getschedparam) (pthread_t, int *, struct sched_param *);
+ int (*ptr_pthread_setschedparam) (pthread_t, int,
+ const struct sched_param *);
+ int (*ptr_pthread_mutex_destroy) (pthread_mutex_t *);
+ int (*ptr_pthread_mutex_init) (pthread_mutex_t *,
+ const pthread_mutexattr_t *);
+ int (*ptr_pthread_mutex_lock) (pthread_mutex_t *);
+ int (*ptr_pthread_mutex_unlock) (pthread_mutex_t *);
+ pthread_t (*ptr_pthread_self) (void);
+ int (*ptr_pthread_setcancelstate) (int, int *);
+ int (*ptr_pthread_setcanceltype) (int, int *);
+ void (*ptr___pthread_cleanup_upto) (__jmp_buf, char *);
+ int (*ptr___pthread_once) (pthread_once_t *, void (*) (void));
+ int (*ptr___pthread_rwlock_rdlock) (pthread_rwlock_t *);
+ int (*ptr___pthread_rwlock_wrlock) (pthread_rwlock_t *);
+ int (*ptr___pthread_rwlock_unlock) (pthread_rwlock_t *);
+ int (*ptr___pthread_key_create) (pthread_key_t *, void (*) (void *));
+ void *(*ptr___pthread_getspecific) (pthread_key_t);
+ int (*ptr___pthread_setspecific) (pthread_key_t, const void *);
+ void (*ptr__pthread_cleanup_push_defer) (struct _pthread_cleanup_buffer *,
+ void (*) (void *), void *);
+ void (*ptr__pthread_cleanup_pop_restore) (struct _pthread_cleanup_buffer *,
+ int);
+#define HAVE_PTR_NTHREADS
+ unsigned int *ptr_nthreads;
+ void (*ptr___pthread_unwind) (__pthread_unwind_buf_t *)
+ __attribute ((noreturn)) __cleanup_fct_attribute;
+ void (*ptr__nptl_deallocate_tsd) (void);
+ int (*ptr__nptl_setxid) (struct xid_command *);
+};
+
+/* Variable in libc.so. */
+extern struct pthread_functions __libc_pthread_functions attribute_hidden;
+
+#endif /* pthread-functions.h */
diff --git a/libc/nptl/sysdeps/pthread/pthread.h b/libc/nptl/sysdeps/pthread/pthread.h
new file mode 100644
index 000000000..f60ecdee1
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/pthread.h
@@ -0,0 +1,1115 @@
+/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+#ifndef _PTHREAD_H
+#define _PTHREAD_H 1
+
+#include <features.h>
+#include <sched.h>
+#include <time.h>
+
+#define __need_sigset_t
+#include <signal.h>
+#include <bits/pthreadtypes.h>
+#include <bits/setjmp.h>
+#include <bits/wordsize.h>
+
+
+/* Detach state. */
+enum
+{
+ PTHREAD_CREATE_JOINABLE,
+#define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE
+ PTHREAD_CREATE_DETACHED
+#define PTHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED
+};
+
+
+/* Mutex types. */
+enum
+{
+ PTHREAD_MUTEX_TIMED_NP,
+ PTHREAD_MUTEX_RECURSIVE_NP,
+ PTHREAD_MUTEX_ERRORCHECK_NP,
+ PTHREAD_MUTEX_ADAPTIVE_NP
+#ifdef __USE_UNIX98
+ ,
+ PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_TIMED_NP,
+ PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP,
+ PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP,
+ PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
+#endif
+#ifdef __USE_GNU
+ /* For compatibility. */
+ , PTHREAD_MUTEX_FAST_NP = PTHREAD_MUTEX_TIMED_NP
+#endif
+};
+
+
+#ifdef __USE_GNU
+/* Robust mutex or not flags. */
+enum
+{
+ PTHREAD_MUTEX_STALLED_NP,
+ PTHREAD_MUTEX_ROBUST_NP
+};
+#endif
+
+
+#ifdef __USE_UNIX98
+/* Mutex protocols. */
+enum
+{
+ PTHREAD_PRIO_NONE,
+ PTHREAD_PRIO_INHERIT,
+ PTHREAD_PRIO_PROTECT
+};
+#endif
+
+
+/* Mutex initializers. */
+#if __WORDSIZE == 64
+# define PTHREAD_MUTEX_INITIALIZER \
+ { { 0, 0, 0, 0, 0, 0, { 0, 0 } } }
+# ifdef __USE_GNU
+# define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
+ { { 0, 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, 0, { 0, 0 } } }
+# define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
+ { { 0, 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 0, { 0, 0 } } }
+# define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
+ { { 0, 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, 0, { 0, 0 } } }
+# endif
+#else
+# define PTHREAD_MUTEX_INITIALIZER \
+ { { 0, 0, 0, 0, 0, { 0 } } }
+# ifdef __USE_GNU
+# define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
+ { { 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, 0, { 0 } } }
+# define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
+ { { 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 0, { 0 } } }
+# define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
+ { { 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, 0, { 0 } } }
+# endif
+#endif
+
+
+/* Read-write lock types. */
+#if defined __USE_UNIX98 || defined __USE_XOPEN2K
+enum
+{
+ PTHREAD_RWLOCK_PREFER_READER_NP,
+ PTHREAD_RWLOCK_PREFER_WRITER_NP,
+ PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,
+ PTHREAD_RWLOCK_DEFAULT_NP = PTHREAD_RWLOCK_PREFER_READER_NP
+};
+
+/* Read-write lock initializers. */
+# if __WORDSIZE == 64
+# define PTHREAD_RWLOCK_INITIALIZER \
+ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
+# else
+# define PTHREAD_RWLOCK_INITIALIZER \
+ { { 0, 0, 0, 0, 0, 0, 0, 0 } }
+# endif
+# ifdef __USE_GNU
+# if __WORDSIZE == 64
+# define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
+ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+ PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP } }
+# else
+# define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
+ { { 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, 0 } }
+# endif
+# endif
+#endif /* Unix98 or XOpen2K */
+
+
+/* Scheduler inheritance. */
+enum
+{
+ PTHREAD_INHERIT_SCHED,
+#define PTHREAD_INHERIT_SCHED PTHREAD_INHERIT_SCHED
+ PTHREAD_EXPLICIT_SCHED
+#define PTHREAD_EXPLICIT_SCHED PTHREAD_EXPLICIT_SCHED
+};
+
+
+/* Scope handling. */
+enum
+{
+ PTHREAD_SCOPE_SYSTEM,
+#define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_SYSTEM
+ PTHREAD_SCOPE_PROCESS
+#define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_PROCESS
+};
+
+
+/* Process shared or private flag. */
+enum
+{
+ PTHREAD_PROCESS_PRIVATE,
+#define PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE
+ PTHREAD_PROCESS_SHARED
+#define PTHREAD_PROCESS_SHARED PTHREAD_PROCESS_SHARED
+};
+
+
+
+/* Conditional variable handling. */
+#define PTHREAD_COND_INITIALIZER { { 0, 0, 0, 0, 0, (void *) 0, 0, 0 } }
+
+
+/* Cleanup buffers */
+struct _pthread_cleanup_buffer
+{
+ void (*__routine) (void *); /* Function to call. */
+ void *__arg; /* Its argument. */
+ int __canceltype; /* Saved cancellation type. */
+ struct _pthread_cleanup_buffer *__prev; /* Chaining of cleanup functions. */
+};
+
+/* Cancellation */
+enum
+{
+ PTHREAD_CANCEL_ENABLE,
+#define PTHREAD_CANCEL_ENABLE PTHREAD_CANCEL_ENABLE
+ PTHREAD_CANCEL_DISABLE
+#define PTHREAD_CANCEL_DISABLE PTHREAD_CANCEL_DISABLE
+};
+enum
+{
+ PTHREAD_CANCEL_DEFERRED,
+#define PTHREAD_CANCEL_DEFERRED PTHREAD_CANCEL_DEFERRED
+ PTHREAD_CANCEL_ASYNCHRONOUS
+#define PTHREAD_CANCEL_ASYNCHRONOUS PTHREAD_CANCEL_ASYNCHRONOUS
+};
+#define PTHREAD_CANCELED ((void *) -1)
+
+
+/* Single execution handling. */
+#define PTHREAD_ONCE_INIT 0
+
+
+#ifdef __USE_XOPEN2K
+/* Value returned by 'pthread_barrier_wait' for one of the threads after
+ the required number of threads have called this function.
+ -1 is distinct from 0 and all errno constants */
+# define PTHREAD_BARRIER_SERIAL_THREAD -1
+#endif
+
+
+__BEGIN_DECLS
+
+/* Create a new thread, starting with execution of START-ROUTINE
+ getting passed ARG. Creation attributed come from ATTR. The new
+ handle is stored in *NEWTHREAD. */
+extern int pthread_create (pthread_t *__restrict __newthread,
+ __const pthread_attr_t *__restrict __attr,
+ void *(*__start_routine) (void *),
+ void *__restrict __arg) __THROW __nonnull ((1, 3));
+
+/* Terminate calling thread.
+
+ The registered cleanup handlers are called via exception handling
+ so we cannot mark this function with __THROW.*/
+extern void pthread_exit (void *__retval) __attribute__ ((__noreturn__));
+
+/* Make calling thread wait for termination of the thread TH. The
+ exit status of the thread is stored in *THREAD_RETURN, if THREAD_RETURN
+ is not NULL.
+
+ This function is a cancellation point and therefore not marked with
+ __THROW. */
+extern int pthread_join (pthread_t __th, void **__thread_return);
+
+#ifdef __USE_GNU
+/* Check whether thread TH has terminated. If yes return the status of
+ the thread in *THREAD_RETURN, if THREAD_RETURN is not NULL. */
+extern int pthread_tryjoin_np (pthread_t __th, void **__thread_return) __THROW;
+
+/* Make calling thread wait for termination of the thread TH, but only
+ until TIMEOUT. The exit status of the thread is stored in
+ *THREAD_RETURN, if THREAD_RETURN is not NULL.
+
+ This function is a cancellation point and therefore not marked with
+ __THROW. */
+extern int pthread_timedjoin_np (pthread_t __th, void **__thread_return,
+ __const struct timespec *__abstime);
+#endif
+
+/* Indicate that the thread TH is never to be joined with PTHREAD_JOIN.
+ The resources of TH will therefore be freed immediately when it
+ terminates, instead of waiting for another thread to perform PTHREAD_JOIN
+ on it. */
+extern int pthread_detach (pthread_t __th) __THROW;
+
+
+/* Obtain the identifier of the current thread. */
+extern pthread_t pthread_self (void) __THROW __attribute__ ((__const__));
+
+/* Compare two thread identifiers. */
+extern int pthread_equal (pthread_t __thread1, pthread_t __thread2) __THROW;
+
+
+/* Thread attribute handling. */
+
+/* Initialize thread attribute *ATTR with default attributes
+ (detachstate is PTHREAD_JOINABLE, scheduling policy is SCHED_OTHER,
+ no user-provided stack). */
+extern int pthread_attr_init (pthread_attr_t *__attr) __THROW __nonnull ((1));
+
+/* Destroy thread attribute *ATTR. */
+extern int pthread_attr_destroy (pthread_attr_t *__attr)
+ __THROW __nonnull ((1));
+
+/* Get detach state attribute. */
+extern int pthread_attr_getdetachstate (__const pthread_attr_t *__attr,
+ int *__detachstate)
+ __THROW __nonnull ((1, 2));
+
+/* Set detach state attribute. */
+extern int pthread_attr_setdetachstate (pthread_attr_t *__attr,
+ int __detachstate)
+ __THROW __nonnull ((1));
+
+
+/* Get the size of the guard area created for stack overflow protection. */
+extern int pthread_attr_getguardsize (__const pthread_attr_t *__attr,
+ size_t *__guardsize)
+ __THROW __nonnull ((1, 2));
+
+/* Set the size of the guard area created for stack overflow protection. */
+extern int pthread_attr_setguardsize (pthread_attr_t *__attr,
+ size_t __guardsize)
+ __THROW __nonnull ((1));
+
+
+/* Return in *PARAM the scheduling parameters of *ATTR. */
+extern int pthread_attr_getschedparam (__const pthread_attr_t *__restrict
+ __attr,
+ struct sched_param *__restrict __param)
+ __THROW __nonnull ((1, 2));
+
+/* Set scheduling parameters (priority, etc) in *ATTR according to PARAM. */
+extern int pthread_attr_setschedparam (pthread_attr_t *__restrict __attr,
+ __const struct sched_param *__restrict
+ __param) __THROW __nonnull ((1, 2));
+
+/* Return in *POLICY the scheduling policy of *ATTR. */
+extern int pthread_attr_getschedpolicy (__const pthread_attr_t *__restrict
+ __attr, int *__restrict __policy)
+ __THROW __nonnull ((1, 2));
+
+/* Set scheduling policy in *ATTR according to POLICY. */
+extern int pthread_attr_setschedpolicy (pthread_attr_t *__attr, int __policy)
+ __THROW __nonnull ((1));
+
+/* Return in *INHERIT the scheduling inheritance mode of *ATTR. */
+extern int pthread_attr_getinheritsched (__const pthread_attr_t *__restrict
+ __attr, int *__restrict __inherit)
+ __THROW __nonnull ((1, 2));
+
+/* Set scheduling inheritance mode in *ATTR according to INHERIT. */
+extern int pthread_attr_setinheritsched (pthread_attr_t *__attr,
+ int __inherit)
+ __THROW __nonnull ((1));
+
+
+/* Return in *SCOPE the scheduling contention scope of *ATTR. */
+extern int pthread_attr_getscope (__const pthread_attr_t *__restrict __attr,
+ int *__restrict __scope)
+ __THROW __nonnull ((1, 2));
+
+/* Set scheduling contention scope in *ATTR according to SCOPE. */
+extern int pthread_attr_setscope (pthread_attr_t *__attr, int __scope)
+ __THROW __nonnull ((1));
+
+/* Return the previously set address for the stack. */
+extern int pthread_attr_getstackaddr (__const pthread_attr_t *__restrict
+ __attr, void **__restrict __stackaddr)
+ __THROW __nonnull ((1, 2)) __attribute_deprecated__;
+
+/* Set the starting address of the stack of the thread to be created.
+ Depending on whether the stack grows up or down the value must either
+ be higher or lower than all the address in the memory block. The
+ minimal size of the block must be PTHREAD_STACK_MIN. */
+extern int pthread_attr_setstackaddr (pthread_attr_t *__attr,
+ void *__stackaddr)
+ __THROW __nonnull ((1)) __attribute_deprecated__;
+
+/* Return the currently used minimal stack size. */
+extern int pthread_attr_getstacksize (__const pthread_attr_t *__restrict
+ __attr, size_t *__restrict __stacksize)
+ __THROW __nonnull ((1, 2));
+
+/* Add information about the minimum stack size needed for the thread
+ to be started. This size must never be less than PTHREAD_STACK_MIN
+ and must also not exceed the system limits. */
+extern int pthread_attr_setstacksize (pthread_attr_t *__attr,
+ size_t __stacksize)
+ __THROW __nonnull ((1));
+
+#ifdef __USE_XOPEN2K
+/* Return the previously set address for the stack. */
+extern int pthread_attr_getstack (__const pthread_attr_t *__restrict __attr,
+ void **__restrict __stackaddr,
+ size_t *__restrict __stacksize)
+ __THROW __nonnull ((1, 2, 3));
+
+/* The following two interfaces are intended to replace the last two. They
+ require setting the address as well as the size since only setting the
+ address will make the implementation on some architectures impossible. */
+extern int pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr,
+ size_t __stacksize) __THROW __nonnull ((1));
+#endif
+
+#ifdef __USE_GNU
+/* Thread created with attribute ATTR will be limited to run only on
+ the processors represented in CPUSET. */
+extern int pthread_attr_setaffinity_np (pthread_attr_t *__attr,
+ size_t __cpusetsize,
+ __const cpu_set_t *__cpuset)
+ __THROW __nonnull ((1, 3));
+
+/* Get bit set in CPUSET representing the processors threads created with
+ ATTR can run on. */
+extern int pthread_attr_getaffinity_np (__const pthread_attr_t *__attr,
+ size_t __cpusetsize,
+ cpu_set_t *__cpuset)
+ __THROW __nonnull ((1, 3));
+
+
+/* Initialize thread attribute *ATTR with attributes corresponding to the
+ already running thread TH. It shall be called on unitialized ATTR
+ and destroyed with pthread_attr_destroy when no longer needed. */
+extern int pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr)
+ __THROW __nonnull ((2));
+#endif
+
+
+/* Functions for scheduling control. */
+
+/* Set the scheduling parameters for TARGET_THREAD according to POLICY
+ and *PARAM. */
+extern int pthread_setschedparam (pthread_t __target_thread, int __policy,
+ __const struct sched_param *__param)
+ __THROW __nonnull ((3));
+
+/* Return in *POLICY and *PARAM the scheduling parameters for TARGET_THREAD. */
+extern int pthread_getschedparam (pthread_t __target_thread,
+ int *__restrict __policy,
+ struct sched_param *__restrict __param)
+ __THROW __nonnull ((2, 3));
+
+/* Set the scheduling priority for TARGET_THREAD. */
+extern int pthread_setschedprio (pthread_t __target_thread, int __prio)
+ __THROW;
+
+
+#ifdef __USE_UNIX98
+/* Determine level of concurrency. */
+extern int pthread_getconcurrency (void) __THROW;
+
+/* Set new concurrency level to LEVEL. */
+extern int pthread_setconcurrency (int __level) __THROW;
+#endif
+
+#ifdef __USE_GNU
+/* Yield the processor to another thread or process.
+ This function is similar to the POSIX `sched_yield' function but
+ might be differently implemented in the case of a m-on-n thread
+ implementation. */
+extern int pthread_yield (void) __THROW;
+
+
+/* Limit specified thread TH to run only on the processors represented
+ in CPUSET. */
+extern int pthread_setaffinity_np (pthread_t __th, size_t __cpusetsize,
+ __const cpu_set_t *__cpuset)
+ __THROW __nonnull ((3));
+
+/* Get bit set in CPUSET representing the processors TH can run on. */
+extern int pthread_getaffinity_np (pthread_t __th, size_t __cpusetsize,
+ cpu_set_t *__cpuset)
+ __THROW __nonnull ((3));
+#endif
+
+
+/* Functions for handling initialization. */
+
+/* Guarantee that the initialization function INIT_ROUTINE will be called
+ only once, even if pthread_once is executed several times with the
+ same ONCE_CONTROL argument. ONCE_CONTROL must point to a static or
+ extern variable initialized to PTHREAD_ONCE_INIT.
+
+ The initialization functions might throw exception which is why
+ this function is not marked with __THROW. */
+extern int pthread_once (pthread_once_t *__once_control,
+ void (*__init_routine) (void)) __nonnull ((1, 2));
+
+
+/* Functions for handling cancellation.
+
+ Note that these functions are explicitly not marked to not throw an
+ exception in C++ code. If cancellation is implemented by unwinding
+ this is necessary to have the compiler generate the unwind information. */
+
+/* Set cancelability state of current thread to STATE, returning old
+ state in *OLDSTATE if OLDSTATE is not NULL. */
+extern int pthread_setcancelstate (int __state, int *__oldstate);
+
+/* Set cancellation state of current thread to TYPE, returning the old
+ type in *OLDTYPE if OLDTYPE is not NULL. */
+extern int pthread_setcanceltype (int __type, int *__oldtype);
+
+/* Cancel THREAD immediately or at the next possibility. */
+extern int pthread_cancel (pthread_t __th);
+
+/* Test for pending cancellation for the current thread and terminate
+ the thread as per pthread_exit(PTHREAD_CANCELED) if it has been
+ cancelled. */
+extern void pthread_testcancel (void);
+
+
+/* Cancellation handling with integration into exception handling. */
+
+typedef struct
+{
+ struct
+ {
+ __jmp_buf __cancel_jmp_buf;
+ int __mask_was_saved;
+ } __cancel_jmp_buf[1];
+ void *__pad[4];
+} __pthread_unwind_buf_t __attribute__ ((__aligned__));
+
+/* No special attributes by default. */
+#ifndef __cleanup_fct_attribute
+# define __cleanup_fct_attribute
+#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); }
+ void __setdoit (int __newval) { __do_it = __newval; }
+ void __defer () { pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED,
+ &__cancel_type); }
+ void __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 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 { \
+ 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); \
+ void *__cancel_arg = (arg); \
+ int not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) \
+ __cancel_buf.__cancel_jmp_buf, 0); \
+ if (__builtin_expect (not_first_call, 0)) \
+ { \
+ __cancel_routine (__cancel_arg); \
+ __pthread_unwind_next (&__cancel_buf); \
+ /* NOTREACHED */ \
+ } \
+ \
+ __pthread_register_cancel (&__cancel_buf); \
+ do {
+extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf)
+ __cleanup_fct_attribute;
+
+/* 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) \
+ } while (0); \
+ __pthread_unregister_cancel (&__cancel_buf); \
+ if (execute) \
+ __cancel_routine (__cancel_arg); \
+ } while (0)
+extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf)
+ __cleanup_fct_attribute;
+
+# 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_unwind_buf_t __cancel_buf; \
+ void (*__cancel_routine) (void *) = (routine); \
+ void *__cancel_arg = (arg); \
+ int not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) \
+ __cancel_buf.__cancel_jmp_buf, 0); \
+ if (__builtin_expect (not_first_call, 0)) \
+ { \
+ __cancel_routine (__cancel_arg); \
+ __pthread_unwind_next (&__cancel_buf); \
+ /* NOTREACHED */ \
+ } \
+ \
+ __pthread_register_cancel_defer (&__cancel_buf); \
+ do {
+extern void __pthread_register_cancel_defer (__pthread_unwind_buf_t *__buf)
+ __cleanup_fct_attribute;
+
+/* 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) \
+ } 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
+
+/* Internal interface to initiate cleanup. */
+extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf)
+ __cleanup_fct_attribute __attribute__ ((__noreturn__))
+# ifndef SHARED
+ __attribute__ ((__weak__))
+# endif
+ ;
+#endif
+
+/* Function used in the macros. */
+struct __jmp_buf_tag;
+extern int __sigsetjmp (struct __jmp_buf_tag *__env, int __savemask) __THROW;
+
+
+/* Mutex handling. */
+
+/* Initialize a mutex. */
+extern int pthread_mutex_init (pthread_mutex_t *__mutex,
+ __const pthread_mutexattr_t *__mutexattr)
+ __THROW __nonnull ((1));
+
+/* Destroy a mutex. */
+extern int pthread_mutex_destroy (pthread_mutex_t *__mutex)
+ __THROW __nonnull ((1));
+
+/* Try locking a mutex. */
+extern int pthread_mutex_trylock (pthread_mutex_t *__mutex)
+ __THROW __nonnull ((1));
+
+/* Lock a mutex. */
+extern int pthread_mutex_lock (pthread_mutex_t *__mutex)
+ __THROW __nonnull ((1));
+
+#ifdef __USE_XOPEN2K
+/* Wait until lock becomes available, or specified time passes. */
+extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex,
+ __const struct timespec *__restrict
+ __abstime) __THROW __nonnull ((1, 2));
+#endif
+
+/* Unlock a mutex. */
+extern int pthread_mutex_unlock (pthread_mutex_t *__mutex)
+ __THROW __nonnull ((1));
+
+
+#ifdef __USE_UNIX98
+/* Get the priority ceiling of MUTEX. */
+extern int pthread_mutex_getprioceiling (__const pthread_mutex_t *
+ __restrict __mutex,
+ int *__restrict __prioceiling)
+ __THROW __nonnull ((1, 2));
+
+/* Set the priority ceiling of MUTEX to PRIOCEILING, return old
+ priority ceiling value in *OLD_CEILING. */
+extern int pthread_mutex_setprioceiling (pthread_mutex_t *__restrict __mutex,
+ int __prioceiling,
+ int *__restrict __old_ceiling)
+ __THROW __nonnull ((1, 3));
+#endif
+
+
+#ifdef __USE_GNU
+/* Declare the state protected by MUTEX as consistent. */
+extern int pthread_mutex_consistent_np (pthread_mutex_t *__mutex)
+ __THROW __nonnull ((1));
+#endif
+
+
+/* Functions for handling mutex attributes. */
+
+/* Initialize mutex attribute object ATTR with default attributes
+ (kind is PTHREAD_MUTEX_TIMED_NP). */
+extern int pthread_mutexattr_init (pthread_mutexattr_t *__attr)
+ __THROW __nonnull ((1));
+
+/* Destroy mutex attribute object ATTR. */
+extern int pthread_mutexattr_destroy (pthread_mutexattr_t *__attr)
+ __THROW __nonnull ((1));
+
+/* Get the process-shared flag of the mutex attribute ATTR. */
+extern int pthread_mutexattr_getpshared (__const pthread_mutexattr_t *
+ __restrict __attr,
+ int *__restrict __pshared)
+ __THROW __nonnull ((1, 2));
+
+/* Set the process-shared flag of the mutex attribute ATTR. */
+extern int pthread_mutexattr_setpshared (pthread_mutexattr_t *__attr,
+ int __pshared)
+ __THROW __nonnull ((1));
+
+#ifdef __USE_UNIX98
+/* Return in *KIND the mutex kind attribute in *ATTR. */
+extern int pthread_mutexattr_gettype (__const pthread_mutexattr_t *__restrict
+ __attr, int *__restrict __kind)
+ __THROW __nonnull ((1, 2));
+
+/* Set the mutex kind attribute in *ATTR to KIND (either PTHREAD_MUTEX_NORMAL,
+ PTHREAD_MUTEX_RECURSIVE, PTHREAD_MUTEX_ERRORCHECK, or
+ PTHREAD_MUTEX_DEFAULT). */
+extern int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind)
+ __THROW __nonnull ((1));
+
+/* Return in *PROTOCOL the mutex protocol attribute in *ATTR. */
+extern int pthread_mutexattr_getprotocol (__const pthread_mutexattr_t *
+ __restrict __attr,
+ int *__restrict __protocol)
+ __THROW __nonnull ((1, 2));
+
+/* Set the mutex protocol attribute in *ATTR to PROTOCOL (either
+ PTHREAD_PRIO_NONE, PTHREAD_PRIO_INHERIT, or PTHREAD_PRIO_PROTECT). */
+extern int pthread_mutexattr_setprotocol (pthread_mutexattr_t *__attr,
+ int __protocol)
+ __THROW __nonnull ((1));
+
+/* Return in *PRIOCEILING the mutex prioceiling attribute in *ATTR. */
+extern int pthread_mutexattr_getprioceiling (__const pthread_mutexattr_t *
+ __restrict __attr,
+ int *__restrict __prioceiling)
+ __THROW __nonnull ((1, 2));
+
+/* Set the mutex prioceiling attribute in *ATTR to PRIOCEILING. */
+extern int pthread_mutexattr_setprioceiling (pthread_mutexattr_t *__attr,
+ int __prioceiling)
+ __THROW __nonnull ((1));
+#endif
+
+#ifdef __USE_GNU
+/* Get the robustness flag of the mutex attribute ATTR. */
+extern int pthread_mutexattr_getrobust_np (__const pthread_mutexattr_t *__attr,
+ int *__robustness)
+ __THROW __nonnull ((1, 2));
+
+/* Set the robustness flag of the mutex attribute ATTR. */
+extern int pthread_mutexattr_setrobust_np (pthread_mutexattr_t *__attr,
+ int __robustness)
+ __THROW __nonnull ((1));
+#endif
+
+
+#if defined __USE_UNIX98 || defined __USE_XOPEN2K
+/* Functions for handling read-write locks. */
+
+/* Initialize read-write lock RWLOCK using attributes ATTR, or use
+ the default values if later is NULL. */
+extern int pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock,
+ __const pthread_rwlockattr_t *__restrict
+ __attr) __THROW __nonnull ((1));
+
+/* Destroy read-write lock RWLOCK. */
+extern int pthread_rwlock_destroy (pthread_rwlock_t *__rwlock)
+ __THROW __nonnull ((1));
+
+/* Acquire read lock for RWLOCK. */
+extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock)
+ __THROW __nonnull ((1));
+
+/* Try to acquire read lock for RWLOCK. */
+extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock)
+ __THROW __nonnull ((1));
+
+# ifdef __USE_XOPEN2K
+/* Try to acquire read lock for RWLOCK or return after specfied time. */
+extern int pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict __rwlock,
+ __const struct timespec *__restrict
+ __abstime) __THROW __nonnull ((1, 2));
+# endif
+
+/* Acquire write lock for RWLOCK. */
+extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock)
+ __THROW __nonnull ((1));
+
+/* Try to acquire write lock for RWLOCK. */
+extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock)
+ __THROW __nonnull ((1));
+
+# ifdef __USE_XOPEN2K
+/* Try to acquire write lock for RWLOCK or return after specfied time. */
+extern int pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict __rwlock,
+ __const struct timespec *__restrict
+ __abstime) __THROW __nonnull ((1, 2));
+# endif
+
+/* Unlock RWLOCK. */
+extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock)
+ __THROW __nonnull ((1));
+
+
+/* Functions for handling read-write lock attributes. */
+
+/* Initialize attribute object ATTR with default values. */
+extern int pthread_rwlockattr_init (pthread_rwlockattr_t *__attr)
+ __THROW __nonnull ((1));
+
+/* Destroy attribute object ATTR. */
+extern int pthread_rwlockattr_destroy (pthread_rwlockattr_t *__attr)
+ __THROW __nonnull ((1));
+
+/* Return current setting of process-shared attribute of ATTR in PSHARED. */
+extern int pthread_rwlockattr_getpshared (__const pthread_rwlockattr_t *
+ __restrict __attr,
+ int *__restrict __pshared)
+ __THROW __nonnull ((1, 2));
+
+/* Set process-shared attribute of ATTR to PSHARED. */
+extern int pthread_rwlockattr_setpshared (pthread_rwlockattr_t *__attr,
+ int __pshared)
+ __THROW __nonnull ((1));
+
+/* Return current setting of reader/writer preference. */
+extern int pthread_rwlockattr_getkind_np (__const pthread_rwlockattr_t *
+ __restrict __attr,
+ int *__restrict __pref)
+ __THROW __nonnull ((1, 2));
+
+/* Set reader/write preference. */
+extern int pthread_rwlockattr_setkind_np (pthread_rwlockattr_t *__attr,
+ int __pref) __THROW __nonnull ((1));
+#endif
+
+
+/* Functions for handling conditional variables. */
+
+/* Initialize condition variable COND using attributes ATTR, or use
+ the default values if later is NULL. */
+extern int pthread_cond_init (pthread_cond_t *__restrict __cond,
+ __const pthread_condattr_t *__restrict
+ __cond_attr) __THROW __nonnull ((1));
+
+/* Destroy condition variable COND. */
+extern int pthread_cond_destroy (pthread_cond_t *__cond)
+ __THROW __nonnull ((1));
+
+/* Wake up one thread waiting for condition variable COND. */
+extern int pthread_cond_signal (pthread_cond_t *__cond)
+ __THROW __nonnull ((1));
+
+/* Wake up all threads waiting for condition variables COND. */
+extern int pthread_cond_broadcast (pthread_cond_t *__cond)
+ __THROW __nonnull ((1));
+
+/* Wait for condition variable COND to be signaled or broadcast.
+ MUTEX is assumed to be locked before.
+
+ This function is a cancellation point and therefore not marked with
+ __THROW. */
+extern int pthread_cond_wait (pthread_cond_t *__restrict __cond,
+ pthread_mutex_t *__restrict __mutex)
+ __nonnull ((1, 2));
+
+/* Wait for condition variable COND to be signaled or broadcast until
+ ABSTIME. MUTEX is assumed to be locked before. ABSTIME is an
+ absolute time specification; zero is the beginning of the epoch
+ (00:00:00 GMT, January 1, 1970).
+
+ This function is a cancellation point and therefore not marked with
+ __THROW. */
+extern int pthread_cond_timedwait (pthread_cond_t *__restrict __cond,
+ pthread_mutex_t *__restrict __mutex,
+ __const struct timespec *__restrict
+ __abstime) __nonnull ((1, 2, 3));
+
+/* Functions for handling condition variable attributes. */
+
+/* Initialize condition variable attribute ATTR. */
+extern int pthread_condattr_init (pthread_condattr_t *__attr)
+ __THROW __nonnull ((1));
+
+/* Destroy condition variable attribute ATTR. */
+extern int pthread_condattr_destroy (pthread_condattr_t *__attr)
+ __THROW __nonnull ((1));
+
+/* Get the process-shared flag of the condition variable attribute ATTR. */
+extern int pthread_condattr_getpshared (__const pthread_condattr_t *
+ __restrict __attr,
+ int *__restrict __pshared)
+ __THROW __nonnull ((1, 2));
+
+/* Set the process-shared flag of the condition variable attribute ATTR. */
+extern int pthread_condattr_setpshared (pthread_condattr_t *__attr,
+ int __pshared) __THROW __nonnull ((1));
+
+#ifdef __USE_XOPEN2K
+/* Get the clock selected for the conditon variable attribute ATTR. */
+extern int pthread_condattr_getclock (__const pthread_condattr_t *
+ __restrict __attr,
+ __clockid_t *__restrict __clock_id)
+ __THROW __nonnull ((1, 2));
+
+/* Set the clock selected for the conditon variable attribute ATTR. */
+extern int pthread_condattr_setclock (pthread_condattr_t *__attr,
+ __clockid_t __clock_id)
+ __THROW __nonnull ((1));
+#endif
+
+
+#ifdef __USE_XOPEN2K
+/* Functions to handle spinlocks. */
+
+/* Initialize the spinlock LOCK. If PSHARED is nonzero the spinlock can
+ be shared between different processes. */
+extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared)
+ __THROW __nonnull ((1));
+
+/* Destroy the spinlock LOCK. */
+extern int pthread_spin_destroy (pthread_spinlock_t *__lock)
+ __THROW __nonnull ((1));
+
+/* Wait until spinlock LOCK is retrieved. */
+extern int pthread_spin_lock (pthread_spinlock_t *__lock)
+ __THROW __nonnull ((1));
+
+/* Try to lock spinlock LOCK. */
+extern int pthread_spin_trylock (pthread_spinlock_t *__lock)
+ __THROW __nonnull ((1));
+
+/* Release spinlock LOCK. */
+extern int pthread_spin_unlock (pthread_spinlock_t *__lock)
+ __THROW __nonnull ((1));
+
+
+/* Functions to handle barriers. */
+
+/* Initialize BARRIER with the attributes in ATTR. The barrier is
+ opened when COUNT waiters arrived. */
+extern int pthread_barrier_init (pthread_barrier_t *__restrict __barrier,
+ __const pthread_barrierattr_t *__restrict
+ __attr, unsigned int __count)
+ __THROW __nonnull ((1));
+
+/* Destroy a previously dynamically initialized barrier BARRIER. */
+extern int pthread_barrier_destroy (pthread_barrier_t *__barrier)
+ __THROW __nonnull ((1));
+
+/* Wait on barrier BARRIER. */
+extern int pthread_barrier_wait (pthread_barrier_t *__barrier)
+ __THROW __nonnull ((1));
+
+
+/* Initialize barrier attribute ATTR. */
+extern int pthread_barrierattr_init (pthread_barrierattr_t *__attr)
+ __THROW __nonnull ((1));
+
+/* Destroy previously dynamically initialized barrier attribute ATTR. */
+extern int pthread_barrierattr_destroy (pthread_barrierattr_t *__attr)
+ __THROW __nonnull ((1));
+
+/* Get the process-shared flag of the barrier attribute ATTR. */
+extern int pthread_barrierattr_getpshared (__const pthread_barrierattr_t *
+ __restrict __attr,
+ int *__restrict __pshared)
+ __THROW __nonnull ((1, 2));
+
+/* Set the process-shared flag of the barrier attribute ATTR. */
+extern int pthread_barrierattr_setpshared (pthread_barrierattr_t *__attr,
+ int __pshared)
+ __THROW __nonnull ((1));
+#endif
+
+
+/* Functions for handling thread-specific data. */
+
+/* Create a key value identifying a location in the thread-specific
+ data area. Each thread maintains a distinct thread-specific data
+ area. DESTR_FUNCTION, if non-NULL, is called with the value
+ associated to that key when the key is destroyed.
+ DESTR_FUNCTION is not called if the value associated is NULL when
+ the key is destroyed. */
+extern int pthread_key_create (pthread_key_t *__key,
+ void (*__destr_function) (void *))
+ __THROW __nonnull ((1));
+
+/* Destroy KEY. */
+extern int pthread_key_delete (pthread_key_t __key) __THROW;
+
+/* Return current value of the thread-specific data slot identified by KEY. */
+extern void *pthread_getspecific (pthread_key_t __key) __THROW;
+
+/* Store POINTER in the thread-specific data slot identified by KEY. */
+extern int pthread_setspecific (pthread_key_t __key,
+ __const void *__pointer) __THROW ;
+
+
+#ifdef __USE_XOPEN2K
+/* Get ID of CPU-time clock for thread THREAD_ID. */
+extern int pthread_getcpuclockid (pthread_t __thread_id,
+ __clockid_t *__clock_id)
+ __THROW __nonnull ((2));
+#endif
+
+
+/* Install handlers to be called when a new process is created with FORK.
+ The PREPARE handler is called in the parent process just before performing
+ FORK. The PARENT handler is called in the parent process just after FORK.
+ The CHILD handler is called in the child process. Each of the three
+ handlers can be NULL, meaning that no handler needs to be called at that
+ point.
+ PTHREAD_ATFORK can be called several times, in which case the PREPARE
+ handlers are called in LIFO order (last added with PTHREAD_ATFORK,
+ first called before FORK), and the PARENT and CHILD handlers are called
+ in FIFO (first added, first called). */
+
+extern int pthread_atfork (void (*__prepare) (void),
+ void (*__parent) (void),
+ void (*__child) (void)) __THROW;
+
+
+#ifdef __USE_EXTERN_INLINES
+/* Optimizations. */
+extern __inline int
+__NTH (pthread_equal (pthread_t __thread1, pthread_t __thread2))
+{
+ return __thread1 == __thread2;
+}
+#endif
+
+__END_DECLS
+
+#endif /* pthread.h */
diff --git a/libc/nptl/sysdeps/pthread/pthread_barrier_wait.c b/libc/nptl/sysdeps/pthread/pthread_barrier_wait.c
new file mode 100644
index 000000000..c6b563f24
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/pthread_barrier_wait.c
@@ -0,0 +1,77 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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 <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <pthreadP.h>
+
+
+/* Wait on barrier. */
+int
+pthread_barrier_wait (barrier)
+ pthread_barrier_t *barrier;
+{
+ struct pthread_barrier *ibarrier = (struct pthread_barrier *) barrier;
+ int result = 0;
+
+ /* Make sure we are alone. */
+ lll_lock (ibarrier->lock);
+
+ /* One more arrival. */
+ --ibarrier->left;
+
+ /* Are these all? */
+ if (ibarrier->left == 0)
+ {
+ /* Yes. Increment the event counter to avoid invalid wake-ups and
+ tell the current waiters that it is their turn. */
+ ++ibarrier->curr_event;
+
+ /* Wake up everybody. */
+ lll_futex_wake (&ibarrier->curr_event, INT_MAX);
+
+ /* This is the thread which finished the serialization. */
+ result = PTHREAD_BARRIER_SERIAL_THREAD;
+ }
+ else
+ {
+ /* The number of the event we are waiting for. The barrier's event
+ number must be bumped before we continue. */
+ unsigned int event = ibarrier->curr_event;
+
+ /* Before suspending, make the barrier available to others. */
+ lll_unlock (ibarrier->lock);
+
+ /* Wait for the event counter of the barrier to change. */
+ do
+ lll_futex_wait (&ibarrier->curr_event, event);
+ while (event == ibarrier->curr_event);
+ }
+
+ /* Make sure the init_count is stored locally or in a register. */
+ unsigned int init_count = ibarrier->init_count;
+
+ /* If this was the last woken thread, unlock. */
+ if (atomic_increment_val (&ibarrier->left) == init_count)
+ /* We are done. */
+ lll_unlock (ibarrier->lock);
+
+ return result;
+}
diff --git a/libc/nptl/sysdeps/pthread/pthread_cond_broadcast.c b/libc/nptl/sysdeps/pthread/pthread_cond_broadcast.c
new file mode 100644
index 000000000..2b8b5460f
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/pthread_cond_broadcast.c
@@ -0,0 +1,86 @@
+/* Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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 <endian.h>
+#include <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <pthread.h>
+#include <pthreadP.h>
+
+#include <shlib-compat.h>
+#include <kernel-features.h>
+
+
+int
+__pthread_cond_broadcast (cond)
+ pthread_cond_t *cond;
+{
+ /* Make sure we are alone. */
+ lll_mutex_lock (cond->__data.__lock);
+
+ /* Are there any waiters to be woken? */
+ if (cond->__data.__total_seq > cond->__data.__wakeup_seq)
+ {
+ /* Yes. Mark them all as woken. */
+ cond->__data.__wakeup_seq = cond->__data.__total_seq;
+ cond->__data.__woken_seq = cond->__data.__total_seq;
+ cond->__data.__futex = (unsigned int) cond->__data.__total_seq * 2;
+ int futex_val = cond->__data.__futex;
+ /* Signal that a broadcast happened. */
+ ++cond->__data.__broadcast_seq;
+
+ /* We are done. */
+ lll_mutex_unlock (cond->__data.__lock);
+
+ /* Do not use requeue for pshared condvars. */
+ if (cond->__data.__mutex == (void *) ~0l)
+ goto wake_all;
+
+ /* Wake everybody. */
+ pthread_mutex_t *mut = (pthread_mutex_t *) cond->__data.__mutex;
+
+ /* XXX: Kernel so far doesn't support requeue to PI futex. */
+ if (__builtin_expect (mut->__data.__kind & PTHREAD_MUTEX_PRIO_INHERIT_NP,
+ 0))
+ goto wake_all;
+
+ /* lll_futex_requeue returns 0 for success and non-zero
+ for errors. */
+ if (__builtin_expect (lll_futex_requeue (&cond->__data.__futex, 1,
+ INT_MAX, &mut->__data.__lock,
+ futex_val), 0))
+ {
+ /* The requeue functionality is not available. */
+ wake_all:
+ lll_futex_wake (&cond->__data.__futex, INT_MAX);
+ }
+
+ /* That's all. */
+ return 0;
+ }
+
+ /* We are done. */
+ lll_mutex_unlock (cond->__data.__lock);
+
+ return 0;
+}
+
+versioned_symbol (libpthread, __pthread_cond_broadcast, pthread_cond_broadcast,
+ GLIBC_2_3_2);
diff --git a/libc/nptl/sysdeps/pthread/pthread_cond_signal.c b/libc/nptl/sysdeps/pthread/pthread_cond_signal.c
new file mode 100644
index 000000000..5a9bbcad9
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/pthread_cond_signal.c
@@ -0,0 +1,61 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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 <endian.h>
+#include <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <pthread.h>
+#include <pthreadP.h>
+
+#include <shlib-compat.h>
+#include <kernel-features.h>
+
+
+int
+__pthread_cond_signal (cond)
+ pthread_cond_t *cond;
+{
+ /* Make sure we are alone. */
+ lll_mutex_lock (cond->__data.__lock);
+
+ /* Are there any waiters to be woken? */
+ if (cond->__data.__total_seq > cond->__data.__wakeup_seq)
+ {
+ /* Yes. Mark one of them as woken. */
+ ++cond->__data.__wakeup_seq;
+ ++cond->__data.__futex;
+
+ /* Wake one. */
+ if (! __builtin_expect (lll_futex_wake_unlock (&cond->__data.__futex, 1,
+ 1, &cond->__data.__lock),
+ 0))
+ return 0;
+
+ lll_futex_wake (&cond->__data.__futex, 1);
+ }
+
+ /* We are done. */
+ lll_mutex_unlock (cond->__data.__lock);
+
+ return 0;
+}
+
+versioned_symbol (libpthread, __pthread_cond_signal, pthread_cond_signal,
+ GLIBC_2_3_2);
diff --git a/libc/nptl/sysdeps/pthread/pthread_cond_timedwait.c b/libc/nptl/sysdeps/pthread/pthread_cond_timedwait.c
new file mode 100644
index 000000000..fdbf43eae
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/pthread_cond_timedwait.c
@@ -0,0 +1,214 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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 <endian.h>
+#include <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <pthread.h>
+#include <pthreadP.h>
+
+#include <shlib-compat.h>
+
+
+/* Cleanup handler, defined in pthread_cond_wait.c. */
+extern void __condvar_cleanup (void *arg)
+ __attribute__ ((visibility ("hidden")));
+
+struct _condvar_cleanup_buffer
+{
+ int oldtype;
+ pthread_cond_t *cond;
+ pthread_mutex_t *mutex;
+ unsigned int bc_seq;
+};
+
+int
+__pthread_cond_timedwait (cond, mutex, abstime)
+ pthread_cond_t *cond;
+ pthread_mutex_t *mutex;
+ const struct timespec *abstime;
+{
+ struct _pthread_cleanup_buffer buffer;
+ struct _condvar_cleanup_buffer cbuffer;
+ int result = 0;
+
+ /* Catch invalid parameters. */
+ if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)
+ return EINVAL;
+
+ /* Make sure we are along. */
+ lll_mutex_lock (cond->__data.__lock);
+
+ /* Now we can release the mutex. */
+ int err = __pthread_mutex_unlock_usercnt (mutex, 0);
+ if (err)
+ {
+ lll_mutex_unlock (cond->__data.__lock);
+ return err;
+ }
+
+ /* We have one new user of the condvar. */
+ ++cond->__data.__total_seq;
+ ++cond->__data.__futex;
+ cond->__data.__nwaiters += 1 << COND_CLOCK_BITS;
+
+ /* Remember the mutex we are using here. If there is already a
+ different address store this is a bad user bug. Do not store
+ anything for pshared condvars. */
+ if (cond->__data.__mutex != (void *) ~0l)
+ cond->__data.__mutex = mutex;
+
+ /* Prepare structure passed to cancellation handler. */
+ cbuffer.cond = cond;
+ cbuffer.mutex = mutex;
+
+ /* Before we block we enable cancellation. Therefore we have to
+ install a cancellation handler. */
+ __pthread_cleanup_push (&buffer, __condvar_cleanup, &cbuffer);
+
+ /* The current values of the wakeup counter. The "woken" counter
+ must exceed this value. */
+ unsigned long long int val;
+ unsigned long long int seq;
+ val = seq = cond->__data.__wakeup_seq;
+ /* Remember the broadcast counter. */
+ cbuffer.bc_seq = cond->__data.__broadcast_seq;
+
+ while (1)
+ {
+ struct timespec rt;
+ {
+#ifdef __NR_clock_gettime
+ INTERNAL_SYSCALL_DECL (err);
+ int ret;
+ ret = INTERNAL_SYSCALL (clock_gettime, err, 2,
+ (cond->__data.__nwaiters
+ & ((1 << COND_CLOCK_BITS) - 1)),
+ &rt);
+# ifndef __ASSUME_POSIX_TIMERS
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (ret, err), 0))
+ {
+ struct timeval tv;
+ (void) gettimeofday (&tv, NULL);
+
+ /* Convert the absolute timeout value to a relative timeout. */
+ rt.tv_sec = abstime->tv_sec - tv.tv_sec;
+ rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
+ }
+ else
+# endif
+ {
+ /* Convert the absolute timeout value to a relative timeout. */
+ rt.tv_sec = abstime->tv_sec - rt.tv_sec;
+ rt.tv_nsec = abstime->tv_nsec - rt.tv_nsec;
+ }
+#else
+ /* Get the current time. So far we support only one clock. */
+ struct timeval tv;
+ (void) gettimeofday (&tv, NULL);
+
+ /* Convert the absolute timeout value to a relative timeout. */
+ rt.tv_sec = abstime->tv_sec - tv.tv_sec;
+ rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
+#endif
+ }
+ if (rt.tv_nsec < 0)
+ {
+ rt.tv_nsec += 1000000000;
+ --rt.tv_sec;
+ }
+ /* Did we already time out? */
+ if (__builtin_expect (rt.tv_sec < 0, 0))
+ {
+ if (cbuffer.bc_seq != cond->__data.__broadcast_seq)
+ goto bc_out;
+
+ goto timeout;
+ }
+
+ unsigned int futex_val = cond->__data.__futex;
+
+ /* Prepare to wait. Release the condvar futex. */
+ lll_mutex_unlock (cond->__data.__lock);
+
+ /* Enable asynchronous cancellation. Required by the standard. */
+ cbuffer.oldtype = __pthread_enable_asynccancel ();
+
+ /* Wait until woken by signal or broadcast. */
+ err = lll_futex_timed_wait (&cond->__data.__futex,
+ futex_val, &rt);
+
+ /* Disable asynchronous cancellation. */
+ __pthread_disable_asynccancel (cbuffer.oldtype);
+
+ /* We are going to look at shared data again, so get the lock. */
+ lll_mutex_lock(cond->__data.__lock);
+
+ /* If a broadcast happened, we are done. */
+ if (cbuffer.bc_seq != cond->__data.__broadcast_seq)
+ goto bc_out;
+
+ /* Check whether we are eligible for wakeup. */
+ val = cond->__data.__wakeup_seq;
+ if (val != seq && cond->__data.__woken_seq != val)
+ break;
+
+ /* Not woken yet. Maybe the time expired? */
+ if (__builtin_expect (err == -ETIMEDOUT, 0))
+ {
+ timeout:
+ /* Yep. Adjust the counters. */
+ ++cond->__data.__wakeup_seq;
+ ++cond->__data.__futex;
+
+ /* The error value. */
+ result = ETIMEDOUT;
+ break;
+ }
+ }
+
+ /* Another thread woken up. */
+ ++cond->__data.__woken_seq;
+
+ bc_out:
+
+ cond->__data.__nwaiters -= 1 << COND_CLOCK_BITS;
+
+ /* If pthread_cond_destroy was called on this variable already,
+ notify the pthread_cond_destroy caller all waiters have left
+ and it can be successfully destroyed. */
+ if (cond->__data.__total_seq == -1ULL
+ && cond->__data.__nwaiters < (1 << COND_CLOCK_BITS))
+ lll_futex_wake (&cond->__data.__nwaiters, 1);
+
+ /* We are done with the condvar. */
+ lll_mutex_unlock (cond->__data.__lock);
+
+ /* The cancellation handling is back to normal, remove the handler. */
+ __pthread_cleanup_pop (&buffer, 0);
+
+ /* Get the mutex before returning. */
+ err = __pthread_mutex_cond_lock (mutex);
+
+ return err ?: result;
+}
+
+versioned_symbol (libpthread, __pthread_cond_timedwait, pthread_cond_timedwait,
+ GLIBC_2_3_2);
diff --git a/libc/nptl/sysdeps/pthread/pthread_cond_wait.c b/libc/nptl/sysdeps/pthread/pthread_cond_wait.c
new file mode 100644
index 000000000..86669458a
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/pthread_cond_wait.c
@@ -0,0 +1,185 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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 <endian.h>
+#include <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <pthread.h>
+#include <pthreadP.h>
+
+#include <shlib-compat.h>
+
+
+struct _condvar_cleanup_buffer
+{
+ int oldtype;
+ pthread_cond_t *cond;
+ pthread_mutex_t *mutex;
+ unsigned int bc_seq;
+};
+
+
+void
+__attribute__ ((visibility ("hidden")))
+__condvar_cleanup (void *arg)
+{
+ struct _condvar_cleanup_buffer *cbuffer =
+ (struct _condvar_cleanup_buffer *) arg;
+ unsigned int destroying;
+
+ /* We are going to modify shared data. */
+ lll_mutex_lock (cbuffer->cond->__data.__lock);
+
+ if (cbuffer->bc_seq == cbuffer->cond->__data.__broadcast_seq)
+ {
+ /* This thread is not waiting anymore. Adjust the sequence counters
+ appropriately. */
+ ++cbuffer->cond->__data.__wakeup_seq;
+ ++cbuffer->cond->__data.__woken_seq;
+ ++cbuffer->cond->__data.__futex;
+ }
+
+ cbuffer->cond->__data.__nwaiters -= 1 << COND_CLOCK_BITS;
+
+ /* If pthread_cond_destroy was called on this variable already,
+ notify the pthread_cond_destroy caller all waiters have left
+ and it can be successfully destroyed. */
+ destroying = 0;
+ if (cbuffer->cond->__data.__total_seq == -1ULL
+ && cbuffer->cond->__data.__nwaiters < (1 << COND_CLOCK_BITS))
+ {
+ lll_futex_wake (&cbuffer->cond->__data.__nwaiters, 1);
+ destroying = 1;
+ }
+
+ /* We are done. */
+ lll_mutex_unlock (cbuffer->cond->__data.__lock);
+
+ /* Wake everybody to make sure no condvar signal gets lost. */
+ if (! destroying)
+ lll_futex_wake (&cbuffer->cond->__data.__futex, INT_MAX);
+
+ /* Get the mutex before returning unless asynchronous cancellation
+ is in effect. */
+ __pthread_mutex_cond_lock (cbuffer->mutex);
+}
+
+
+int
+__pthread_cond_wait (cond, mutex)
+ pthread_cond_t *cond;
+ pthread_mutex_t *mutex;
+{
+ struct _pthread_cleanup_buffer buffer;
+ struct _condvar_cleanup_buffer cbuffer;
+ int err;
+
+ /* Make sure we are along. */
+ lll_mutex_lock (cond->__data.__lock);
+
+ /* Now we can release the mutex. */
+ err = __pthread_mutex_unlock_usercnt (mutex, 0);
+ if (__builtin_expect (err, 0))
+ {
+ lll_mutex_unlock (cond->__data.__lock);
+ return err;
+ }
+
+ /* We have one new user of the condvar. */
+ ++cond->__data.__total_seq;
+ ++cond->__data.__futex;
+ cond->__data.__nwaiters += 1 << COND_CLOCK_BITS;
+
+ /* Remember the mutex we are using here. If there is already a
+ different address store this is a bad user bug. Do not store
+ anything for pshared condvars. */
+ if (cond->__data.__mutex != (void *) ~0l)
+ cond->__data.__mutex = mutex;
+
+ /* Prepare structure passed to cancellation handler. */
+ cbuffer.cond = cond;
+ cbuffer.mutex = mutex;
+
+ /* Before we block we enable cancellation. Therefore we have to
+ install a cancellation handler. */
+ __pthread_cleanup_push (&buffer, __condvar_cleanup, &cbuffer);
+
+ /* The current values of the wakeup counter. The "woken" counter
+ must exceed this value. */
+ unsigned long long int val;
+ unsigned long long int seq;
+ val = seq = cond->__data.__wakeup_seq;
+ /* Remember the broadcast counter. */
+ cbuffer.bc_seq = cond->__data.__broadcast_seq;
+
+ do
+ {
+ unsigned int futex_val = cond->__data.__futex;
+
+ /* Prepare to wait. Release the condvar futex. */
+ lll_mutex_unlock (cond->__data.__lock);
+
+ /* Enable asynchronous cancellation. Required by the standard. */
+ cbuffer.oldtype = __pthread_enable_asynccancel ();
+
+ /* Wait until woken by signal or broadcast. */
+ lll_futex_wait (&cond->__data.__futex, futex_val);
+
+ /* Disable asynchronous cancellation. */
+ __pthread_disable_asynccancel (cbuffer.oldtype);
+
+ /* We are going to look at shared data again, so get the lock. */
+ lll_mutex_lock (cond->__data.__lock);
+
+ /* If a broadcast happened, we are done. */
+ if (cbuffer.bc_seq != cond->__data.__broadcast_seq)
+ goto bc_out;
+
+ /* Check whether we are eligible for wakeup. */
+ val = cond->__data.__wakeup_seq;
+ }
+ while (val == seq || cond->__data.__woken_seq == val);
+
+ /* Another thread woken up. */
+ ++cond->__data.__woken_seq;
+
+ bc_out:
+
+ cond->__data.__nwaiters -= 1 << COND_CLOCK_BITS;
+
+ /* If pthread_cond_destroy was called on this varaible already,
+ notify the pthread_cond_destroy caller all waiters have left
+ and it can be successfully destroyed. */
+ if (cond->__data.__total_seq == -1ULL
+ && cond->__data.__nwaiters < (1 << COND_CLOCK_BITS))
+ lll_futex_wake (&cond->__data.__nwaiters, 1);
+
+ /* We are done with the condvar. */
+ lll_mutex_unlock (cond->__data.__lock);
+
+ /* The cancellation handling is back to normal, remove the handler. */
+ __pthread_cleanup_pop (&buffer, 0);
+
+ /* Get the mutex before returning. */
+ return __pthread_mutex_cond_lock (mutex);
+}
+
+versioned_symbol (libpthread, __pthread_cond_wait, pthread_cond_wait,
+ GLIBC_2_3_2);
diff --git a/libc/nptl/sysdeps/pthread/pthread_getcpuclockid.c b/libc/nptl/sysdeps/pthread/pthread_getcpuclockid.c
new file mode 100644
index 000000000..8506f94eb
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/pthread_getcpuclockid.c
@@ -0,0 +1,57 @@
+/* Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <pthreadP.h>
+#include <sys/time.h>
+#include <tls.h>
+
+
+int
+pthread_getcpuclockid (threadid, clockid)
+ pthread_t threadid;
+ clockid_t *clockid;
+{
+ struct pthread *pd = (struct pthread *) threadid;
+
+ /* Make sure the descriptor is valid. */
+ if (INVALID_TD_P (pd))
+ /* Not a valid thread handle. */
+ return ESRCH;
+
+#ifdef CLOCK_THREAD_CPUTIME_ID
+ /* We need to store the thread ID in the CLOCKID variable together
+ with a number identifying the clock. We reserve the low 3 bits
+ for the clock ID and the rest for the thread ID. This is
+ problematic if the thread ID is too large. But 29 bits should be
+ fine.
+
+ If some day more clock IDs are needed the ID part can be
+ enlarged. The IDs are entirely internal. */
+ if (pd->tid >= 1 << (8 * sizeof (*clockid) - CLOCK_IDFIELD_SIZE))
+ return ERANGE;
+
+ /* Store the number. */
+ *clockid = CLOCK_THREAD_CPUTIME_ID | (pd->tid << CLOCK_IDFIELD_SIZE);
+
+ return 0;
+#else
+ /* We don't have a timer for that. */
+ return ENOENT;
+#endif
+}
diff --git a/libc/nptl/sysdeps/pthread/pthread_once.c b/libc/nptl/sysdeps/pthread/pthread_once.c
new file mode 100644
index 000000000..9b2cef864
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/pthread_once.c
@@ -0,0 +1,54 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "pthreadP.h"
+#include <lowlevellock.h>
+
+
+
+static lll_lock_t once_lock = LLL_LOCK_INITIALIZER;
+
+
+int
+__pthread_once (once_control, init_routine)
+ pthread_once_t *once_control;
+ void (*init_routine) (void);
+{
+ /* XXX Depending on whether the LOCK_IN_ONCE_T is defined use a
+ global lock variable or one which is part of the pthread_once_t
+ object. */
+ if (*once_control == PTHREAD_ONCE_INIT)
+ {
+ lll_lock (once_lock);
+
+ /* XXX This implementation is not complete. It doesn't take
+ cancelation and fork into account. */
+ if (*once_control == PTHREAD_ONCE_INIT)
+ {
+ init_routine ();
+
+ *once_control = !PTHREAD_ONCE_INIT;
+ }
+
+ lll_unlock (once_lock);
+ }
+
+ return 0;
+}
+strong_alias (__pthread_once, pthread_once)
diff --git a/libc/nptl/sysdeps/pthread/pthread_rwlock_rdlock.c b/libc/nptl/sysdeps/pthread/pthread_rwlock_rdlock.c
new file mode 100644
index 000000000..e225d7030
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/pthread_rwlock_rdlock.c
@@ -0,0 +1,95 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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 <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <pthread.h>
+#include <pthreadP.h>
+
+
+/* Acquire read lock for RWLOCK. */
+int
+__pthread_rwlock_rdlock (rwlock)
+ pthread_rwlock_t *rwlock;
+{
+ int result = 0;
+
+ /* Make sure we are along. */
+ lll_mutex_lock (rwlock->__data.__lock);
+
+ while (1)
+ {
+ /* Get the rwlock if there is no writer... */
+ if (rwlock->__data.__writer == 0
+ /* ...and if either no writer is waiting or we prefer readers. */
+ && (!rwlock->__data.__nr_writers_queued
+ || rwlock->__data.__flags == 0))
+ {
+ /* Increment the reader counter. Avoid overflow. */
+ if (__builtin_expect (++rwlock->__data.__nr_readers == 0, 0))
+ {
+ /* Overflow on number of readers. */
+ --rwlock->__data.__nr_readers;
+ result = EAGAIN;
+ }
+
+ break;
+ }
+
+ /* Make sure we are not holding the rwlock as a writer. This is
+ a deadlock situation we recognize and report. */
+ if (__builtin_expect (rwlock->__data.__writer
+ == THREAD_GETMEM (THREAD_SELF, tid), 0))
+ {
+ result = EDEADLK;
+ break;
+ }
+
+ /* Remember that we are a reader. */
+ if (__builtin_expect (++rwlock->__data.__nr_readers_queued == 0, 0))
+ {
+ /* Overflow on number of queued readers. */
+ --rwlock->__data.__nr_readers_queued;
+ result = EAGAIN;
+ break;
+ }
+
+ int waitval = rwlock->__data.__readers_wakeup;
+
+ /* Free the lock. */
+ lll_mutex_unlock (rwlock->__data.__lock);
+
+ /* Wait for the writer to finish. */
+ lll_futex_wait (&rwlock->__data.__readers_wakeup, waitval);
+
+ /* Get the lock. */
+ lll_mutex_lock (rwlock->__data.__lock);
+
+ --rwlock->__data.__nr_readers_queued;
+ }
+
+ /* We are done, free the lock. */
+ lll_mutex_unlock (rwlock->__data.__lock);
+
+ return result;
+}
+
+weak_alias (__pthread_rwlock_rdlock, pthread_rwlock_rdlock)
+strong_alias (__pthread_rwlock_rdlock, __pthread_rwlock_rdlock_internal)
diff --git a/libc/nptl/sysdeps/pthread/pthread_rwlock_timedrdlock.c b/libc/nptl/sysdeps/pthread/pthread_rwlock_timedrdlock.c
new file mode 100644
index 000000000..80ea83a3d
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/pthread_rwlock_timedrdlock.c
@@ -0,0 +1,137 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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 <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <pthread.h>
+#include <pthreadP.h>
+
+
+/* Try to acquire read lock for RWLOCK or return after specfied time. */
+int
+pthread_rwlock_timedrdlock (rwlock, abstime)
+ pthread_rwlock_t *rwlock;
+ const struct timespec *abstime;
+{
+ int result = 0;
+
+ /* Make sure we are along. */
+ lll_mutex_lock(rwlock->__data.__lock);
+
+ while (1)
+ {
+ int err;
+
+ /* Get the rwlock if there is no writer... */
+ if (rwlock->__data.__writer == 0
+ /* ...and if either no writer is waiting or we prefer readers. */
+ && (!rwlock->__data.__nr_writers_queued
+ || rwlock->__data.__flags == 0))
+ {
+ /* Increment the reader counter. Avoid overflow. */
+ if (++rwlock->__data.__nr_readers == 0)
+ {
+ /* Overflow on number of readers. */
+ --rwlock->__data.__nr_readers;
+ result = EAGAIN;
+ }
+
+ break;
+ }
+
+ /* Make sure we are not holding the rwlock as a writer. This is
+ a deadlock situation we recognize and report. */
+ if (__builtin_expect (rwlock->__data.__writer
+ == THREAD_GETMEM (THREAD_SELF, tid), 0))
+ {
+ result = EDEADLK;
+ break;
+ }
+
+ /* Make sure the passed in timeout value is valid. Ideally this
+ test would be executed once. But since it must not be
+ performed if we would not block at all simply moving the test
+ to the front is no option. Replicating all the code is
+ costly while this test is not. */
+ if (__builtin_expect (abstime->tv_nsec >= 1000000000
+ || abstime->tv_nsec < 0, 0))
+ {
+ result = EINVAL;
+ break;
+ }
+
+ /* Get the current time. So far we support only one clock. */
+ struct timeval tv;
+ (void) gettimeofday (&tv, NULL);
+
+ /* Convert the absolute timeout value to a relative timeout. */
+ struct timespec rt;
+ rt.tv_sec = abstime->tv_sec - tv.tv_sec;
+ rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
+ if (rt.tv_nsec < 0)
+ {
+ rt.tv_nsec += 1000000000;
+ --rt.tv_sec;
+ }
+ /* Did we already time out? */
+ if (rt.tv_sec < 0)
+ {
+ /* Yep, return with an appropriate error. */
+ result = ETIMEDOUT;
+ break;
+ }
+
+ /* Remember that we are a reader. */
+ if (++rwlock->__data.__nr_readers_queued == 0)
+ {
+ /* Overflow on number of queued readers. */
+ --rwlock->__data.__nr_readers_queued;
+ result = EAGAIN;
+ break;
+ }
+
+ int waitval = rwlock->__data.__readers_wakeup;
+
+ /* Free the lock. */
+ lll_mutex_unlock (rwlock->__data.__lock);
+
+ /* Wait for the writer to finish. */
+ err = lll_futex_timed_wait (&rwlock->__data.__readers_wakeup,
+ waitval, &rt);
+
+ /* Get the lock. */
+ lll_mutex_lock (rwlock->__data.__lock);
+
+ --rwlock->__data.__nr_readers_queued;
+
+ /* Did the futex call time out? */
+ if (err == -ETIMEDOUT)
+ {
+ /* Yep, report it. */
+ result = ETIMEDOUT;
+ break;
+ }
+ }
+
+ /* We are done, free the lock. */
+ lll_mutex_unlock (rwlock->__data.__lock);
+
+ return result;
+}
diff --git a/libc/nptl/sysdeps/pthread/pthread_rwlock_timedwrlock.c b/libc/nptl/sysdeps/pthread/pthread_rwlock_timedwrlock.c
new file mode 100644
index 000000000..97c0598f9
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/pthread_rwlock_timedwrlock.c
@@ -0,0 +1,127 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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 <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <pthread.h>
+#include <pthreadP.h>
+
+
+/* Try to acquire write lock for RWLOCK or return after specfied time. */
+int
+pthread_rwlock_timedwrlock (rwlock, abstime)
+ pthread_rwlock_t *rwlock;
+ const struct timespec *abstime;
+{
+ int result = 0;
+
+ /* Make sure we are along. */
+ lll_mutex_lock (rwlock->__data.__lock);
+
+ while (1)
+ {
+ int err;
+
+ /* Get the rwlock if there is no writer and no reader. */
+ if (rwlock->__data.__writer == 0 && rwlock->__data.__nr_readers == 0)
+ {
+ /* Mark self as writer. */
+ rwlock->__data.__writer = THREAD_GETMEM (THREAD_SELF, tid);
+ break;
+ }
+
+ /* Make sure we are not holding the rwlock as a writer. This is
+ a deadlock situation we recognize and report. */
+ if (__builtin_expect (rwlock->__data.__writer
+ == THREAD_GETMEM (THREAD_SELF, tid), 0))
+ {
+ result = EDEADLK;
+ break;
+ }
+
+ /* Make sure the passed in timeout value is valid. Ideally this
+ test would be executed once. But since it must not be
+ performed if we would not block at all simply moving the test
+ to the front is no option. Replicating all the code is
+ costly while this test is not. */
+ if (__builtin_expect (abstime->tv_nsec >= 1000000000
+ || abstime->tv_nsec < 0, 0))
+ {
+ result = EINVAL;
+ break;
+ }
+
+ /* Get the current time. So far we support only one clock. */
+ struct timeval tv;
+ (void) gettimeofday (&tv, NULL);
+
+ /* Convert the absolute timeout value to a relative timeout. */
+ struct timespec rt;
+ rt.tv_sec = abstime->tv_sec - tv.tv_sec;
+ rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
+ if (rt.tv_nsec < 0)
+ {
+ rt.tv_nsec += 1000000000;
+ --rt.tv_sec;
+ }
+ /* Did we already time out? */
+ if (rt.tv_sec < 0)
+ {
+ result = ETIMEDOUT;
+ break;
+ }
+
+ /* Remember that we are a writer. */
+ if (++rwlock->__data.__nr_writers_queued == 0)
+ {
+ /* Overflow on number of queued writers. */
+ --rwlock->__data.__nr_writers_queued;
+ result = EAGAIN;
+ break;
+ }
+
+ int waitval = rwlock->__data.__writer_wakeup;
+
+ /* Free the lock. */
+ lll_mutex_unlock (rwlock->__data.__lock);
+
+ /* Wait for the writer or reader(s) to finish. */
+ err = lll_futex_timed_wait (&rwlock->__data.__writer_wakeup,
+ waitval, &rt);
+
+ /* Get the lock. */
+ lll_mutex_lock (rwlock->__data.__lock);
+
+ /* To start over again, remove the thread from the writer list. */
+ --rwlock->__data.__nr_writers_queued;
+
+ /* Did the futex call time out? */
+ if (err == -ETIMEDOUT)
+ {
+ result = ETIMEDOUT;
+ break;
+ }
+ }
+
+ /* We are done, free the lock. */
+ lll_mutex_unlock (rwlock->__data.__lock);
+
+ return result;
+}
diff --git a/libc/nptl/sysdeps/pthread/pthread_rwlock_unlock.c b/libc/nptl/sysdeps/pthread/pthread_rwlock_unlock.c
new file mode 100644
index 000000000..9cae8b6c2
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/pthread_rwlock_unlock.c
@@ -0,0 +1,57 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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 <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <pthread.h>
+#include <pthreadP.h>
+
+/* Unlock RWLOCK. */
+int
+__pthread_rwlock_unlock (pthread_rwlock_t *rwlock)
+{
+ lll_mutex_lock (rwlock->__data.__lock);
+ if (rwlock->__data.__writer)
+ rwlock->__data.__writer = 0;
+ else
+ --rwlock->__data.__nr_readers;
+ if (rwlock->__data.__nr_readers == 0)
+ {
+ if (rwlock->__data.__nr_writers_queued)
+ {
+ ++rwlock->__data.__writer_wakeup;
+ lll_mutex_unlock (rwlock->__data.__lock);
+ lll_futex_wake (&rwlock->__data.__writer_wakeup, 1);
+ return 0;
+ }
+ else if (rwlock->__data.__nr_readers_queued)
+ {
+ ++rwlock->__data.__readers_wakeup;
+ lll_mutex_unlock (rwlock->__data.__lock);
+ lll_futex_wake (&rwlock->__data.__readers_wakeup, INT_MAX);
+ return 0;
+ }
+ }
+ lll_mutex_unlock (rwlock->__data.__lock);
+ return 0;
+}
+
+weak_alias (__pthread_rwlock_unlock, pthread_rwlock_unlock)
+strong_alias (__pthread_rwlock_unlock, __pthread_rwlock_unlock_internal)
diff --git a/libc/nptl/sysdeps/pthread/pthread_rwlock_wrlock.c b/libc/nptl/sysdeps/pthread/pthread_rwlock_wrlock.c
new file mode 100644
index 000000000..822aeed79
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/pthread_rwlock_wrlock.c
@@ -0,0 +1,87 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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 <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <pthread.h>
+#include <pthreadP.h>
+
+
+/* Acquire write lock for RWLOCK. */
+int
+__pthread_rwlock_wrlock (rwlock)
+ pthread_rwlock_t *rwlock;
+{
+ int result = 0;
+
+ /* Make sure we are along. */
+ lll_mutex_lock (rwlock->__data.__lock);
+
+ while (1)
+ {
+ /* Get the rwlock if there is no writer and no reader. */
+ if (rwlock->__data.__writer == 0 && rwlock->__data.__nr_readers == 0)
+ {
+ /* Mark self as writer. */
+ rwlock->__data.__writer = THREAD_GETMEM (THREAD_SELF, tid);
+ break;
+ }
+
+ /* Make sure we are not holding the rwlock as a writer. This is
+ a deadlock situation we recognize and report. */
+ if (__builtin_expect (rwlock->__data.__writer
+ == THREAD_GETMEM (THREAD_SELF, tid), 0))
+ {
+ result = EDEADLK;
+ break;
+ }
+
+ /* Remember that we are a writer. */
+ if (++rwlock->__data.__nr_writers_queued == 0)
+ {
+ /* Overflow on number of queued writers. */
+ --rwlock->__data.__nr_writers_queued;
+ result = EAGAIN;
+ break;
+ }
+
+ int waitval = rwlock->__data.__writer_wakeup;
+
+ /* Free the lock. */
+ lll_mutex_unlock (rwlock->__data.__lock);
+
+ /* Wait for the writer or reader(s) to finish. */
+ lll_futex_wait (&rwlock->__data.__writer_wakeup, waitval);
+
+ /* Get the lock. */
+ lll_mutex_lock (rwlock->__data.__lock);
+
+ /* To start over again, remove the thread from the writer list. */
+ --rwlock->__data.__nr_writers_queued;
+ }
+
+ /* We are done, free the lock. */
+ lll_mutex_unlock (rwlock->__data.__lock);
+
+ return result;
+}
+
+weak_alias (__pthread_rwlock_wrlock, pthread_rwlock_wrlock)
+strong_alias (__pthread_rwlock_wrlock, __pthread_rwlock_wrlock_internal)
diff --git a/libc/nptl/sysdeps/pthread/pthread_sigmask.c b/libc/nptl/sysdeps/pthread/pthread_sigmask.c
new file mode 100644
index 000000000..0d12fe6bf
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/pthread_sigmask.c
@@ -0,0 +1,58 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <signal.h>
+#include <pthreadP.h>
+#include <sysdep.h>
+
+
+int
+pthread_sigmask (how, newmask, oldmask)
+ int how;
+ const sigset_t *newmask;
+ sigset_t *oldmask;
+{
+ sigset_t local_newmask;
+
+ /* The only thing we have to make sure here is that SIGCANCEL and
+ SIGSETXID is not blocked. */
+ if (newmask != NULL
+ && (__builtin_expect (__sigismember (newmask, SIGCANCEL), 0)
+ || __builtin_expect (__sigismember (newmask, SIGSETXID), 0)))
+ {
+ local_newmask = *newmask;
+ __sigdelset (&local_newmask, SIGCANCEL);
+ __sigdelset (&local_newmask, SIGSETXID);
+ newmask = &local_newmask;
+ }
+
+#ifdef INTERNAL_SYSCALL
+ /* We know that realtime signals are available if NPTL is used. */
+ INTERNAL_SYSCALL_DECL (err);
+ int result = INTERNAL_SYSCALL (rt_sigprocmask, err, 4, how, newmask,
+ oldmask, _NSIG / 8);
+
+ return (INTERNAL_SYSCALL_ERROR_P (result, err)
+ ? INTERNAL_SYSCALL_ERRNO (result, err)
+ : 0);
+#else
+ return sigprocmask (how, newmask, oldmask) == -1 ? errno : 0;
+#endif
+}
diff --git a/libc/nptl/sysdeps/pthread/pthread_spin_destroy.c b/libc/nptl/sysdeps/pthread/pthread_spin_destroy.c
new file mode 100644
index 000000000..4d0109cf0
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/pthread_spin_destroy.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "pthreadP.h"
+
+
+int
+pthread_spin_destroy (lock)
+ pthread_spinlock_t *lock;
+{
+ /* Nothing to do. */
+ return 0;
+}
diff --git a/libc/nptl/sysdeps/pthread/pthread_spin_init.c b/libc/nptl/sysdeps/pthread/pthread_spin_init.c
new file mode 100644
index 000000000..c2275085e
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/pthread_spin_init.c
@@ -0,0 +1,28 @@
+/* pthread_spin_init -- initialize a spin lock. Generic version.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus@au.ibm.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 "pthreadP.h"
+
+int
+pthread_spin_init (pthread_spinlock_t *lock, int pshared)
+{
+ *lock = 0;
+ return 0;
+}
diff --git a/libc/nptl/sysdeps/pthread/pthread_spin_unlock.c b/libc/nptl/sysdeps/pthread/pthread_spin_unlock.c
new file mode 100644
index 000000000..f97cadfbd
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/pthread_spin_unlock.c
@@ -0,0 +1,30 @@
+/* pthread_spin_unlock -- unlock a spin lock. Generic version.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus@au.ibm.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 "pthreadP.h"
+#include <atomic.h>
+
+int
+pthread_spin_unlock (pthread_spinlock_t *lock)
+{
+ atomic_full_barrier ();
+ *lock = 0;
+ return 0;
+}
diff --git a/libc/nptl/sysdeps/pthread/rt-unwind-resume.c b/libc/nptl/sysdeps/pthread/rt-unwind-resume.c
new file mode 100644
index 000000000..743e675d4
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/rt-unwind-resume.c
@@ -0,0 +1 @@
+#include <unwind-resume.c>
diff --git a/libc/nptl/sysdeps/pthread/setxid.h b/libc/nptl/sysdeps/pthread/setxid.h
new file mode 100644
index 000000000..8ec382f40
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/setxid.h
@@ -0,0 +1,64 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <pthreadP.h>
+#include <sysdep.h>
+
+#define __SETXID_1(cmd, arg1) \
+ cmd.id[0] = arg1
+#define __SETXID_2(cmd, arg1, arg2) \
+ __SETXID_1 (cmd, arg1); cmd.id[1] = arg2
+#define __SETXID_3(cmd, arg1, arg2, arg3) \
+ __SETXID_2 (cmd, arg1, arg2); cmd.id[2] = arg3
+
+#ifdef SINGLE_THREAD
+# define INLINE_SETXID_SYSCALL(name, nr, args...) \
+ INLINE_SYSCALL (name, nr, args)
+#elif defined SHARED
+# define INLINE_SETXID_SYSCALL(name, nr, args...) \
+ ({ \
+ int __result; \
+ if (__builtin_expect (__libc_pthread_functions.ptr__nptl_setxid \
+ != NULL, 0)) \
+ { \
+ struct xid_command __cmd; \
+ __cmd.syscall_no = __NR_##name; \
+ __SETXID_##nr (__cmd, args); \
+ __result = __libc_pthread_functions.ptr__nptl_setxid (&__cmd); \
+ } \
+ else \
+ __result = INLINE_SYSCALL (name, nr, args); \
+ __result; \
+ })
+#else
+# define INLINE_SETXID_SYSCALL(name, nr, args...) \
+ ({ \
+ extern __typeof (__nptl_setxid) __nptl_setxid __attribute__((weak));\
+ int __result; \
+ if (__builtin_expect (__nptl_setxid != NULL, 0)) \
+ { \
+ struct xid_command __cmd; \
+ __cmd.syscall_no = __NR_##name; \
+ __SETXID_##nr (__cmd, args); \
+ __result =__nptl_setxid (&__cmd); \
+ } \
+ else \
+ __result = INLINE_SYSCALL (name, nr, args); \
+ __result; \
+ })
+#endif
diff --git a/libc/nptl/sysdeps/pthread/sigfillset.c b/libc/nptl/sysdeps/pthread/sigfillset.c
new file mode 100644
index 000000000..180607c77
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/sigfillset.c
@@ -0,0 +1,21 @@
+/* Copyright (C) 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <nptl/pthreadP.h>
+
+#include <signal/sigfillset.c>
diff --git a/libc/nptl/sysdeps/pthread/sigprocmask.c b/libc/nptl/sysdeps/pthread/sigprocmask.c
new file mode 100644
index 000000000..855b43396
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/sigprocmask.c
@@ -0,0 +1,20 @@
+/* Copyright (C) 1997,1998,1999,2000,2001,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <nptl/pthreadP.h>
+#include <sysdeps/unix/sysv/linux/sigprocmask.c>
diff --git a/libc/nptl/sysdeps/pthread/tcb-offsets.h b/libc/nptl/sysdeps/pthread/tcb-offsets.h
new file mode 100644
index 000000000..3fe13702e
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/tcb-offsets.h
@@ -0,0 +1 @@
+/* This is overridden by generated tcb-offsets.h on arches which need it. */
diff --git a/libc/nptl/sysdeps/pthread/timer_create.c b/libc/nptl/sysdeps/pthread/timer_create.c
new file mode 100644
index 000000000..2809ac744
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/timer_create.c
@@ -0,0 +1,170 @@
+/* Copyright (C) 2000, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Kaz Kylheku <kaz@ashi.footprints.net>.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <signal.h>
+#include <pthread.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "posix-timer.h"
+
+
+/* Create new per-process timer using CLOCK. */
+int
+timer_create (clock_id, evp, timerid)
+ clockid_t clock_id;
+ struct sigevent *evp;
+ timer_t *timerid;
+{
+ int retval = -1;
+ struct timer_node *newtimer = NULL;
+ struct thread_node *thread = NULL;
+
+ if (0
+#if defined _POSIX_CPUTIME && _POSIX_CPUTIME >= 0
+ || clock_id == CLOCK_PROCESS_CPUTIME_ID
+#endif
+#if defined _POSIX_THREAD_CPUTIME && _POSIX_THREAD_CPUTIME >= 0
+ || clock_id == CLOCK_THREAD_CPUTIME_ID
+#endif
+ )
+ {
+ /* We don't allow timers for CPU clocks. At least not in the
+ moment. */
+ __set_errno (ENOTSUP);
+ return -1;
+ }
+
+ if (clock_id != CLOCK_REALTIME)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ pthread_once (&__timer_init_once_control, __timer_init_once);
+
+ if (__timer_init_failed)
+ {
+ __set_errno (ENOMEM);
+ return -1;
+ }
+
+ pthread_mutex_lock (&__timer_mutex);
+
+ newtimer = __timer_alloc ();
+ if (__builtin_expect (newtimer == NULL, 0))
+ {
+ __set_errno (EAGAIN);
+ goto unlock_bail;
+ }
+
+ if (evp != NULL)
+ newtimer->event = *evp;
+ else
+ {
+ newtimer->event.sigev_notify = SIGEV_SIGNAL;
+ newtimer->event.sigev_signo = SIGALRM;
+ newtimer->event.sigev_value.sival_ptr = timer_ptr2id (newtimer);
+ newtimer->event.sigev_notify_function = 0;
+ }
+
+ newtimer->event.sigev_notify_attributes = &newtimer->attr;
+ newtimer->creator_pid = getpid ();
+
+ switch (__builtin_expect (newtimer->event.sigev_notify, SIGEV_SIGNAL))
+ {
+ case SIGEV_NONE:
+ case SIGEV_SIGNAL:
+ /* We have a global thread for delivering timed signals.
+ If it is not running, try to start it up. */
+ thread = &__timer_signal_thread_rclk;
+ if (! thread->exists)
+ {
+ if (__builtin_expect (__timer_thread_start (thread),
+ 1) < 0)
+ {
+ __set_errno (EAGAIN);
+ goto unlock_bail;
+ }
+ }
+ break;
+
+ case SIGEV_THREAD:
+ /* Copy over thread attributes or set up default ones. */
+ if (evp->sigev_notify_attributes)
+ newtimer->attr = *(pthread_attr_t *) evp->sigev_notify_attributes;
+ else
+ pthread_attr_init (&newtimer->attr);
+
+ /* Ensure thread attributes call for deatched thread. */
+ pthread_attr_setdetachstate (&newtimer->attr, PTHREAD_CREATE_DETACHED);
+
+ /* Try to find existing thread having the right attributes. */
+ thread = __timer_thread_find_matching (&newtimer->attr, clock_id);
+
+ /* If no existing thread has these attributes, try to allocate one. */
+ if (thread == NULL)
+ thread = __timer_thread_alloc (&newtimer->attr, clock_id);
+
+ /* Out of luck; no threads are available. */
+ if (__builtin_expect (thread == NULL, 0))
+ {
+ __set_errno (EAGAIN);
+ goto unlock_bail;
+ }
+
+ /* If the thread is not running already, try to start it. */
+ if (! thread->exists
+ && __builtin_expect (! __timer_thread_start (thread), 0))
+ {
+ __set_errno (EAGAIN);
+ goto unlock_bail;
+ }
+ break;
+
+ default:
+ __set_errno (EINVAL);
+ goto unlock_bail;
+ }
+
+ newtimer->clock = clock_id;
+ newtimer->abstime = 0;
+ newtimer->armed = 0;
+ newtimer->thread = thread;
+
+ *timerid = timer_ptr2id (newtimer);
+ retval = 0;
+
+ if (__builtin_expect (retval, 0) == -1)
+ {
+ unlock_bail:
+ if (thread != NULL)
+ __timer_thread_dealloc (thread);
+ if (newtimer != NULL)
+ {
+ timer_delref (newtimer);
+ __timer_dealloc (newtimer);
+ }
+ }
+
+ pthread_mutex_unlock (&__timer_mutex);
+
+ return retval;
+}
diff --git a/libc/nptl/sysdeps/pthread/timer_delete.c b/libc/nptl/sysdeps/pthread/timer_delete.c
new file mode 100644
index 000000000..48ba1f272
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/timer_delete.c
@@ -0,0 +1,70 @@
+/* Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Kaz Kylheku <kaz@ashi.footprints.net>.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <pthread.h>
+#include <time.h>
+
+#include "posix-timer.h"
+
+
+/* Delete timer TIMERID. */
+int
+timer_delete (timerid)
+ timer_t timerid;
+{
+ struct timer_node *timer;
+ int retval = -1;
+
+ pthread_mutex_lock (&__timer_mutex);
+
+ timer = timer_id2ptr (timerid);
+ if (! timer_valid (timer))
+ /* Invalid timer ID or the timer is not in use. */
+ __set_errno (EINVAL);
+ else
+ {
+ if (timer->armed && timer->thread != NULL)
+ {
+ struct thread_node *thread = timer->thread;
+ assert (thread != NULL);
+
+ /* If thread is cancelled while waiting for handler to terminate,
+ the mutex is unlocked and timer_delete is aborted. */
+ pthread_cleanup_push (__timer_mutex_cancel_handler, &__timer_mutex);
+
+ /* If timer is currently being serviced, wait for it to finish. */
+ while (thread->current_timer == timer)
+ pthread_cond_wait (&thread->cond, &__timer_mutex);
+
+ pthread_cleanup_pop (0);
+ }
+
+ /* Remove timer from whatever queue it may be on and deallocate it. */
+ timer->inuse = TIMER_DELETED;
+ list_unlink_ip (&timer->links);
+ timer_delref (timer);
+ retval = 0;
+ }
+
+ pthread_mutex_unlock (&__timer_mutex);
+
+ return retval;
+}
diff --git a/libc/nptl/sysdeps/pthread/timer_getoverr.c b/libc/nptl/sysdeps/pthread/timer_getoverr.c
new file mode 100644
index 000000000..f3e22215b
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/timer_getoverr.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Kaz Kylheku <kaz@ashi.footprints.net>.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <pthread.h>
+#include <time.h>
+
+#include "posix-timer.h"
+
+
+/* Get expiration overrun for timer TIMERID. */
+int
+timer_getoverrun (timerid)
+ timer_t timerid;
+{
+ struct timer_node *timer;
+ int retval = -1;
+
+ pthread_mutex_lock (&__timer_mutex);
+
+ if (! timer_valid (timer = timer_id2ptr (timerid)))
+ __set_errno (EINVAL);
+ else
+ retval = timer->overrun_count;
+
+ pthread_mutex_unlock (&__timer_mutex);
+
+ return retval;
+}
diff --git a/libc/nptl/sysdeps/pthread/timer_gettime.c b/libc/nptl/sysdeps/pthread/timer_gettime.c
new file mode 100644
index 000000000..723a61632
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/timer_gettime.c
@@ -0,0 +1,77 @@
+/* Copyright (C) 2000, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Kaz Kylheku <kaz@ashi.footprints.net>.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <pthread.h>
+#include <time.h>
+
+#include "posix-timer.h"
+
+
+/* Get current value of timer TIMERID and store it in VLAUE. */
+int
+timer_gettime (timerid, value)
+ timer_t timerid;
+ struct itimerspec *value;
+{
+ struct timer_node *timer;
+ struct timespec now, expiry;
+ int retval = -1, armed = 0, valid;
+ clock_t clock = 0;
+
+ pthread_mutex_lock (&__timer_mutex);
+
+ timer = timer_id2ptr (timerid);
+ valid = timer_valid (timer);
+
+ if (valid) {
+ armed = timer->armed;
+ expiry = timer->expirytime;
+ clock = timer->clock;
+ value->it_interval = timer->value.it_interval;
+ }
+
+ pthread_mutex_unlock (&__timer_mutex);
+
+ if (valid)
+ {
+ if (armed)
+ {
+ clock_gettime (clock, &now);
+ if (timespec_compare (&now, &expiry) < 0)
+ timespec_sub (&value->it_value, &expiry, &now);
+ else
+ {
+ value->it_value.tv_sec = 0;
+ value->it_value.tv_nsec = 0;
+ }
+ }
+ else
+ {
+ value->it_value.tv_sec = 0;
+ value->it_value.tv_nsec = 0;
+ }
+
+ retval = 0;
+ }
+ else
+ __set_errno (EINVAL);
+
+ return retval;
+}
diff --git a/libc/nptl/sysdeps/pthread/timer_routines.c b/libc/nptl/sysdeps/pthread/timer_routines.c
new file mode 100644
index 000000000..8d5b1d13a
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/timer_routines.c
@@ -0,0 +1,578 @@
+/* Helper code for POSIX timer implementation on NPTL.
+ Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Kaz Kylheku <kaz@ashi.footprints.net>.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <pthread.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sysdep.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+
+#include "posix-timer.h"
+#include <pthreadP.h>
+
+
+/* Number of threads used. */
+#define THREAD_MAXNODES 16
+
+/* Array containing the descriptors for the used threads. */
+static struct thread_node thread_array[THREAD_MAXNODES];
+
+/* Static array with the structures for all the timers. */
+struct timer_node __timer_array[TIMER_MAX];
+
+/* Global lock to protect operation on the lists. */
+pthread_mutex_t __timer_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+/* Variable to protext initialization. */
+pthread_once_t __timer_init_once_control = PTHREAD_ONCE_INIT;
+
+/* Nonzero if initialization of timer implementation failed. */
+int __timer_init_failed;
+
+/* Node for the thread used to deliver signals. */
+struct thread_node __timer_signal_thread_rclk;
+
+/* Lists to keep free and used timers and threads. */
+struct list_links timer_free_list;
+struct list_links thread_free_list;
+struct list_links thread_active_list;
+
+
+#ifdef __NR_rt_sigqueueinfo
+extern int __syscall_rt_sigqueueinfo (int, int, siginfo_t *);
+#endif
+
+
+/* List handling functions. */
+static inline void
+list_init (struct list_links *list)
+{
+ list->next = list->prev = list;
+}
+
+static inline void
+list_append (struct list_links *list, struct list_links *newp)
+{
+ newp->prev = list->prev;
+ newp->next = list;
+ list->prev->next = newp;
+ list->prev = newp;
+}
+
+static inline void
+list_insbefore (struct list_links *list, struct list_links *newp)
+{
+ list_append (list, newp);
+}
+
+/*
+ * Like list_unlink_ip, except that calling it on a node that
+ * is already unlinked is disastrous rather than a noop.
+ */
+
+static inline void
+list_unlink (struct list_links *list)
+{
+ struct list_links *lnext = list->next, *lprev = list->prev;
+
+ lnext->prev = lprev;
+ lprev->next = lnext;
+}
+
+static inline struct list_links *
+list_first (struct list_links *list)
+{
+ return list->next;
+}
+
+static inline struct list_links *
+list_null (struct list_links *list)
+{
+ return list;
+}
+
+static inline struct list_links *
+list_next (struct list_links *list)
+{
+ return list->next;
+}
+
+static inline int
+list_isempty (struct list_links *list)
+{
+ return list->next == list;
+}
+
+
+/* Functions build on top of the list functions. */
+static inline struct thread_node *
+thread_links2ptr (struct list_links *list)
+{
+ return (struct thread_node *) ((char *) list
+ - offsetof (struct thread_node, links));
+}
+
+static inline struct timer_node *
+timer_links2ptr (struct list_links *list)
+{
+ return (struct timer_node *) ((char *) list
+ - offsetof (struct timer_node, links));
+}
+
+
+/* Initialize a newly allocated thread structure. */
+static void
+thread_init (struct thread_node *thread, const pthread_attr_t *attr, clockid_t clock_id)
+{
+ if (attr != NULL)
+ thread->attr = *attr;
+ else
+ {
+ pthread_attr_init (&thread->attr);
+ pthread_attr_setdetachstate (&thread->attr, PTHREAD_CREATE_DETACHED);
+ }
+
+ thread->exists = 0;
+ list_init (&thread->timer_queue);
+ pthread_cond_init (&thread->cond, 0);
+ thread->current_timer = 0;
+ thread->captured = pthread_self ();
+ thread->clock_id = clock_id;
+}
+
+
+/* Initialize the global lists, and acquire global resources. Error
+ reporting is done by storing a non-zero value to the global variable
+ timer_init_failed. */
+static void
+init_module (void)
+{
+ int i;
+
+ list_init (&timer_free_list);
+ list_init (&thread_free_list);
+ list_init (&thread_active_list);
+
+ for (i = 0; i < TIMER_MAX; ++i)
+ {
+ list_append (&timer_free_list, &__timer_array[i].links);
+ __timer_array[i].inuse = TIMER_FREE;
+ }
+
+ for (i = 0; i < THREAD_MAXNODES; ++i)
+ list_append (&thread_free_list, &thread_array[i].links);
+
+ thread_init (&__timer_signal_thread_rclk, 0, CLOCK_REALTIME);
+}
+
+
+/* This is a handler executed in a child process after a fork()
+ occurs. It reinitializes the module, resetting all of the data
+ structures to their initial state. The mutex is initialized in
+ case it was locked in the parent process. */
+static void
+reinit_after_fork (void)
+{
+ init_module ();
+ pthread_mutex_init (&__timer_mutex, 0);
+}
+
+
+/* Called once form pthread_once in timer_init. This initializes the
+ module and ensures that reinit_after_fork will be executed in any
+ child process. */
+void
+__timer_init_once (void)
+{
+ init_module ();
+ pthread_atfork (0, 0, reinit_after_fork);
+}
+
+
+/* Deinitialize a thread that is about to be deallocated. */
+static void
+thread_deinit (struct thread_node *thread)
+{
+ assert (list_isempty (&thread->timer_queue));
+ pthread_cond_destroy (&thread->cond);
+}
+
+
+/* Allocate a thread structure from the global free list. Global
+ mutex lock must be held by caller. The thread is moved to
+ the active list. */
+struct thread_node *
+__timer_thread_alloc (const pthread_attr_t *desired_attr, clockid_t clock_id)
+{
+ struct list_links *node = list_first (&thread_free_list);
+
+ if (node != list_null (&thread_free_list))
+ {
+ struct thread_node *thread = thread_links2ptr (node);
+ list_unlink (node);
+ thread_init (thread, desired_attr, clock_id);
+ list_append (&thread_active_list, node);
+ return thread;
+ }
+
+ return 0;
+}
+
+
+/* Return a thread structure to the global free list. Global lock
+ must be held by caller. */
+void
+__timer_thread_dealloc (struct thread_node *thread)
+{
+ thread_deinit (thread);
+ list_unlink (&thread->links);
+ list_append (&thread_free_list, &thread->links);
+}
+
+
+/* Each of our threads which terminates executes this cleanup
+ handler. We never terminate threads ourselves; if a thread gets here
+ it means that the evil application has killed it. If the thread has
+ timers, these require servicing and so we must hire a replacement
+ thread right away. We must also unblock another thread that may
+ have been waiting for this thread to finish servicing a timer (see
+ timer_delete()). */
+
+static void
+thread_cleanup (void *val)
+{
+ if (val != NULL)
+ {
+ struct thread_node *thread = val;
+
+ /* How did the signal thread get killed? */
+ assert (thread != &__timer_signal_thread_rclk);
+
+ pthread_mutex_lock (&__timer_mutex);
+
+ thread->exists = 0;
+
+ /* We are no longer processing a timer event. */
+ thread->current_timer = 0;
+
+ if (list_isempty (&thread->timer_queue))
+ __timer_thread_dealloc (thread);
+ else
+ (void) __timer_thread_start (thread);
+
+ pthread_mutex_unlock (&__timer_mutex);
+
+ /* Unblock potentially blocked timer_delete(). */
+ pthread_cond_broadcast (&thread->cond);
+ }
+}
+
+
+/* Handle a timer which is supposed to go off now. */
+static void
+thread_expire_timer (struct thread_node *self, struct timer_node *timer)
+{
+ self->current_timer = timer; /* Lets timer_delete know timer is running. */
+
+ pthread_mutex_unlock (&__timer_mutex);
+
+ switch (__builtin_expect (timer->event.sigev_notify, SIGEV_SIGNAL))
+ {
+ case SIGEV_NONE:
+ break;
+
+ case SIGEV_SIGNAL:
+#ifdef __NR_rt_sigqueueinfo
+ {
+ siginfo_t info;
+
+ /* First, clear the siginfo_t structure, so that we don't pass our
+ stack content to other tasks. */
+ memset (&info, 0, sizeof (siginfo_t));
+ /* We must pass the information about the data in a siginfo_t
+ value. */
+ info.si_signo = timer->event.sigev_signo;
+ info.si_code = SI_TIMER;
+ info.si_pid = timer->creator_pid;
+ info.si_uid = getuid ();
+ info.si_value = timer->event.sigev_value;
+
+ INLINE_SYSCALL (rt_sigqueueinfo, 3, info.si_pid, info.si_signo, &info);
+ }
+#else
+ if (pthread_kill (self->captured, timer->event.sigev_signo) != 0)
+ {
+ if (pthread_kill (self->id, timer->event.sigev_signo) != 0)
+ abort ();
+ }
+#endif
+ break;
+
+ case SIGEV_THREAD:
+ timer->event.sigev_notify_function (timer->event.sigev_value);
+ break;
+
+ default:
+ assert (! "unknown event");
+ break;
+ }
+
+ pthread_mutex_lock (&__timer_mutex);
+
+ self->current_timer = 0;
+
+ pthread_cond_broadcast (&self->cond);
+}
+
+
+/* Thread function; executed by each timer thread. The job of this
+ function is to wait on the thread's timer queue and expire the
+ timers in chronological order as close to their scheduled time as
+ possible. */
+static void
+__attribute__ ((noreturn))
+thread_func (void *arg)
+{
+ struct thread_node *self = arg;
+
+ /* Register cleanup handler, in case rogue application terminates
+ this thread. (This cannot happen to __timer_signal_thread, which
+ doesn't invoke application callbacks). */
+
+ pthread_cleanup_push (thread_cleanup, self);
+
+ pthread_mutex_lock (&__timer_mutex);
+
+ while (1)
+ {
+ struct list_links *first;
+ struct timer_node *timer = NULL;
+
+ /* While the timer queue is not empty, inspect the first node. */
+ first = list_first (&self->timer_queue);
+ if (first != list_null (&self->timer_queue))
+ {
+ struct timespec now;
+
+ timer = timer_links2ptr (first);
+
+ /* This assumes that the elements of the list of one thread
+ are all for the same clock. */
+ clock_gettime (timer->clock, &now);
+
+ while (1)
+ {
+ /* If the timer is due or overdue, remove it from the queue.
+ If it's a periodic timer, re-compute its new time and
+ requeue it. Either way, perform the timer expiry. */
+ if (timespec_compare (&now, &timer->expirytime) < 0)
+ break;
+
+ list_unlink_ip (first);
+
+ if (__builtin_expect (timer->value.it_interval.tv_sec, 0) != 0
+ || timer->value.it_interval.tv_nsec != 0)
+ {
+ timer->overrun_count = 0;
+ timespec_add (&timer->expirytime, &timer->expirytime,
+ &timer->value.it_interval);
+ while (timespec_compare (&timer->expirytime, &now) < 0)
+ {
+ timespec_add (&timer->expirytime, &timer->expirytime,
+ &timer->value.it_interval);
+ if (timer->overrun_count < DELAYTIMER_MAX)
+ ++timer->overrun_count;
+ }
+ __timer_thread_queue_timer (self, timer);
+ }
+
+ thread_expire_timer (self, timer);
+
+ first = list_first (&self->timer_queue);
+ if (first == list_null (&self->timer_queue))
+ break;
+
+ timer = timer_links2ptr (first);
+ }
+ }
+
+ /* If the queue is not empty, wait until the expiry time of the
+ first node. Otherwise wait indefinitely. Insertions at the
+ head of the queue must wake up the thread by broadcasting
+ this condition variable. */
+ if (timer != NULL)
+ pthread_cond_timedwait (&self->cond, &__timer_mutex,
+ &timer->expirytime);
+ else
+ pthread_cond_wait (&self->cond, &__timer_mutex);
+ }
+ /* This macro will never be executed since the while loop loops
+ forever - but we have to add it for proper nesting. */
+ pthread_cleanup_pop (1);
+}
+
+
+/* Enqueue a timer in wakeup order in the thread's timer queue.
+ Returns 1 if the timer was inserted at the head of the queue,
+ causing the queue's next wakeup time to change. */
+
+int
+__timer_thread_queue_timer (struct thread_node *thread,
+ struct timer_node *insert)
+{
+ struct list_links *iter;
+ int athead = 1;
+
+ for (iter = list_first (&thread->timer_queue);
+ iter != list_null (&thread->timer_queue);
+ iter = list_next (iter))
+ {
+ struct timer_node *timer = timer_links2ptr (iter);
+
+ if (timespec_compare (&insert->expirytime, &timer->expirytime) < 0)
+ break;
+ athead = 0;
+ }
+
+ list_insbefore (iter, &insert->links);
+ return athead;
+}
+
+
+/* Start a thread and associate it with the given thread node. Global
+ lock must be held by caller. */
+int
+__timer_thread_start (struct thread_node *thread)
+{
+ int retval = 1;
+
+ assert (!thread->exists);
+ thread->exists = 1;
+
+ if (pthread_create (&thread->id, &thread->attr,
+ (void *(*) (void *)) thread_func, thread) != 0)
+ {
+ thread->exists = 0;
+ retval = -1;
+ }
+
+ return retval;
+}
+
+
+void
+__timer_thread_wakeup (struct thread_node *thread)
+{
+ pthread_cond_broadcast (&thread->cond);
+}
+
+
+/* Compare two pthread_attr_t thread attributes for exact equality.
+ Returns 1 if they are equal, otherwise zero if they are not equal
+ or contain illegal values. This version is NPTL-specific for
+ performance reason. One could use the access functions to get the
+ values of all the fields of the attribute structure. */
+static int
+thread_attr_compare (const pthread_attr_t *left, const pthread_attr_t *right)
+{
+ struct pthread_attr *ileft = (struct pthread_attr *) left;
+ struct pthread_attr *iright = (struct pthread_attr *) right;
+
+ return (ileft->flags == iright->flags
+ && ileft->schedpolicy == iright->schedpolicy
+ && (ileft->schedparam.sched_priority
+ == iright->schedparam.sched_priority)
+ && ileft->guardsize == iright->guardsize
+ && ileft->stackaddr == iright->stackaddr
+ && ileft->stacksize == iright->stacksize
+ && ((ileft->cpuset == NULL && iright->cpuset == NULL)
+ || (ileft->cpuset != NULL && iright->cpuset != NULL
+ && ileft->cpusetsize == iright->cpusetsize
+ && memcmp (ileft->cpuset, iright->cpuset,
+ ileft->cpusetsize) == 0)));
+}
+
+
+/* Search the list of active threads and find one which has matching
+ attributes. Global mutex lock must be held by caller. */
+struct thread_node *
+__timer_thread_find_matching (const pthread_attr_t *desired_attr,
+ clockid_t desired_clock_id)
+{
+ struct list_links *iter = list_first (&thread_active_list);
+
+ while (iter != list_null (&thread_active_list))
+ {
+ struct thread_node *candidate = thread_links2ptr (iter);
+
+ if (thread_attr_compare (desired_attr, &candidate->attr)
+ && desired_clock_id == candidate->clock_id)
+ return candidate;
+
+ iter = list_next (iter);
+ }
+
+ return NULL;
+}
+
+
+/* Grab a free timer structure from the global free list. The global
+ lock must be held by the caller. */
+struct timer_node *
+__timer_alloc (void)
+{
+ struct list_links *node = list_first (&timer_free_list);
+
+ if (node != list_null (&timer_free_list))
+ {
+ struct timer_node *timer = timer_links2ptr (node);
+ list_unlink_ip (node);
+ timer->inuse = TIMER_INUSE;
+ timer->refcount = 1;
+ return timer;
+ }
+
+ return NULL;
+}
+
+
+/* Return a timer structure to the global free list. The global lock
+ must be held by the caller. */
+void
+__timer_dealloc (struct timer_node *timer)
+{
+ assert (timer->refcount == 0);
+ timer->thread = NULL; /* Break association between timer and thread. */
+ timer->inuse = TIMER_FREE;
+ list_append (&timer_free_list, &timer->links);
+}
+
+
+/* Thread cancellation handler which unlocks a mutex. */
+void
+__timer_mutex_cancel_handler (void *arg)
+{
+ pthread_mutex_unlock (arg);
+}
diff --git a/libc/nptl/sysdeps/pthread/timer_settime.c b/libc/nptl/sysdeps/pthread/timer_settime.c
new file mode 100644
index 000000000..592b5271b
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/timer_settime.c
@@ -0,0 +1,137 @@
+/* Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Kaz Kylheku <kaz@ashi.footprints.net>.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <pthread.h>
+#include <time.h>
+
+#include "posix-timer.h"
+
+
+/* Set timer TIMERID to VALUE, returning old value in OVLAUE. */
+int
+timer_settime (timerid, flags, value, ovalue)
+ timer_t timerid;
+ int flags;
+ const struct itimerspec *value;
+ struct itimerspec *ovalue;
+{
+ struct timer_node *timer;
+ struct thread_node *thread = NULL;
+ struct timespec now;
+ int have_now = 0, need_wakeup = 0;
+ int retval = -1;
+
+ timer = timer_id2ptr (timerid);
+ if (timer == NULL)
+ {
+ __set_errno (EINVAL);
+ goto bail;
+ }
+
+ if (value->it_interval.tv_nsec < 0
+ || value->it_interval.tv_nsec >= 1000000000
+ || value->it_value.tv_nsec < 0
+ || value->it_value.tv_nsec >= 1000000000)
+ {
+ __set_errno (EINVAL);
+ goto bail;
+ }
+
+ /* Will need to know current time since this is a relative timer;
+ might as well make the system call outside of the lock now! */
+
+ if ((flags & TIMER_ABSTIME) == 0)
+ {
+ clock_gettime (timer->clock, &now);
+ have_now = 1;
+ }
+
+ pthread_mutex_lock (&__timer_mutex);
+ timer_addref (timer);
+
+ /* One final check of timer validity; this one is possible only
+ until we have the mutex, because it accesses the inuse flag. */
+
+ if (! timer_valid(timer))
+ {
+ __set_errno (EINVAL);
+ goto unlock_bail;
+ }
+
+ if (ovalue != NULL)
+ {
+ ovalue->it_interval = timer->value.it_interval;
+
+ if (timer->armed)
+ {
+ if (! have_now)
+ {
+ pthread_mutex_unlock (&__timer_mutex);
+ clock_gettime (timer->clock, &now);
+ have_now = 1;
+ pthread_mutex_lock (&__timer_mutex);
+ timer_addref (timer);
+ }
+
+ timespec_sub (&ovalue->it_value, &timer->expirytime, &now);
+ }
+ else
+ {
+ ovalue->it_value.tv_sec = 0;
+ ovalue->it_value.tv_nsec = 0;
+ }
+ }
+
+ timer->value = *value;
+
+ list_unlink_ip (&timer->links);
+ timer->armed = 0;
+
+ thread = timer->thread;
+
+ /* A value of { 0, 0 } causes the timer to be stopped. */
+ if (value->it_value.tv_sec != 0
+ || __builtin_expect (value->it_value.tv_nsec != 0, 1))
+ {
+ if ((flags & TIMER_ABSTIME) != 0)
+ /* The user specified the expiration time. */
+ timer->expirytime = value->it_value;
+ else
+ timespec_add (&timer->expirytime, &now, &value->it_value);
+
+ /* Only need to wake up the thread if timer is inserted
+ at the head of the queue. */
+ if (thread != NULL)
+ need_wakeup = __timer_thread_queue_timer (thread, timer);
+ timer->armed = 1;
+ }
+
+ retval = 0;
+
+unlock_bail:
+ timer_delref (timer);
+ pthread_mutex_unlock (&__timer_mutex);
+
+bail:
+ if (thread != NULL && need_wakeup)
+ __timer_thread_wakeup (thread);
+
+ return retval;
+}
diff --git a/libc/nptl/sysdeps/pthread/tst-mqueue8x.c b/libc/nptl/sysdeps/pthread/tst-mqueue8x.c
new file mode 100644
index 000000000..ca280394f
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/tst-mqueue8x.c
@@ -0,0 +1 @@
+#include <rt/tst-mqueue8.c>
diff --git a/libc/nptl/sysdeps/pthread/tst-timer.c b/libc/nptl/sysdeps/pthread/tst-timer.c
new file mode 100644
index 000000000..f19fe364b
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/tst-timer.c
@@ -0,0 +1,159 @@
+/* Tests for POSIX timer implementation.
+ Copyright (C) 2000, 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Kaz Kylheku <kaz@ashi.footprints.net>.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <signal.h>
+#include <stdio.h>
+#include <time.h>
+#include <unistd.h>
+
+
+static void
+notify_func1 (union sigval sigval)
+{
+ puts ("notify_func1");
+}
+
+
+static void
+notify_func2 (union sigval sigval)
+{
+ puts ("notify_func2");
+}
+
+
+static void
+signal_func (int sig)
+{
+ static const char text[] = "signal_func\n";
+ signal (sig, signal_func);
+ write (STDOUT_FILENO, text, sizeof text - 1);
+}
+
+static void
+intr_sleep (int sec)
+{
+ struct timespec ts;
+
+ ts.tv_sec = sec;
+ ts.tv_nsec = 0;
+
+ while (nanosleep (&ts, &ts) == -1 && errno == EINTR)
+ ;
+}
+
+#define ZSIGALRM 14
+
+
+int
+main (void)
+{
+ struct timespec ts;
+ timer_t timer_sig, timer_thr1, timer_thr2;
+ int retval;
+ struct sigevent sigev1 =
+ {
+ .sigev_notify = SIGEV_SIGNAL,
+ .sigev_signo = ZSIGALRM
+ };
+ struct sigevent sigev2;
+ struct itimerspec itimer1 = { { 0, 200000000 }, { 0, 200000000 } };
+ struct itimerspec itimer2 = { { 0, 100000000 }, { 0, 500000000 } };
+ struct itimerspec itimer3 = { { 0, 150000000 }, { 0, 300000000 } };
+ struct itimerspec old;
+
+ retval = clock_gettime (CLOCK_REALTIME, &ts);
+
+ sigev2.sigev_notify = SIGEV_THREAD;
+ sigev2.sigev_notify_function = notify_func1;
+ sigev2.sigev_notify_attributes = NULL;
+ /* It is unnecessary to do the following but to set a good example
+ we do it anyhow. */
+ sigev2.sigev_value.sival_ptr = NULL;
+
+ setvbuf (stdout, 0, _IOLBF, 0);
+
+ printf ("clock_gettime returned %d, timespec = { %ld, %ld }\n",
+ retval, ts.tv_sec, ts.tv_nsec);
+
+ retval = clock_getres (CLOCK_REALTIME, &ts);
+
+ printf ("clock_getres returned %d, timespec = { %ld, %ld }\n",
+ retval, ts.tv_sec, ts.tv_nsec);
+
+ if (timer_create (CLOCK_REALTIME, &sigev1, &timer_sig) != 0)
+ {
+ printf ("timer_create for timer_sig failed: %m\n");
+ exit (1);
+ }
+ if (timer_create (CLOCK_REALTIME, &sigev2, &timer_thr1) != 0)
+ {
+ printf ("timer_create for timer_thr1 failed: %m\n");
+ exit (1);
+ }
+ sigev2.sigev_notify_function = notify_func2;
+ if (timer_create (CLOCK_REALTIME, &sigev2, &timer_thr2) != 0)
+ {
+ printf ("timer_create for timer_thr2 failed: %m\n");
+ exit (1);
+ }
+
+ if (timer_settime (timer_thr1, 0, &itimer2, &old) != 0)
+ {
+ printf ("timer_settime for timer_thr1 failed: %m\n");
+ exit (1);
+ }
+ if (timer_settime (timer_thr2, 0, &itimer3, &old) != 0)
+ {
+ printf ("timer_settime for timer_thr2 failed: %m\n");
+ exit (1);
+ }
+
+ signal (ZSIGALRM, signal_func);
+
+ if (timer_settime (timer_sig, 0, &itimer1, &old) != 0)
+ {
+ printf ("timer_settime for timer_sig failed: %m\n");
+ exit (1);
+ }
+
+ intr_sleep (3);
+
+ if (timer_delete (timer_sig) != 0)
+ {
+ printf ("timer_delete for timer_sig failed: %m\n");
+ exit (1);
+ }
+ if (timer_delete (timer_thr1) != 0)
+ {
+ printf ("timer_delete for timer_thr1 failed: %m\n");
+ exit (1);
+ }
+
+ intr_sleep (3);
+
+ if (timer_delete (timer_thr2) != 0)
+ {
+ printf ("timer_delete for timer_thr2 failed: %m\n");
+ exit (1);
+ }
+
+ return 0;
+}
diff --git a/libc/nptl/sysdeps/pthread/unwind-forcedunwind.c b/libc/nptl/sysdeps/pthread/unwind-forcedunwind.c
new file mode 100644
index 000000000..6792d719d
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/unwind-forcedunwind.c
@@ -0,0 +1,110 @@
+/* Copyright (C) 2003, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <dlfcn.h>
+#include <stdio.h>
+#include <unwind.h>
+#include <pthreadP.h>
+
+static void (*libgcc_s_resume) (struct _Unwind_Exception *exc);
+static _Unwind_Reason_Code (*libgcc_s_personality)
+ (int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *,
+ struct _Unwind_Context *);
+static _Unwind_Reason_Code (*libgcc_s_forcedunwind)
+ (struct _Unwind_Exception *, _Unwind_Stop_Fn, void *);
+static _Unwind_Word (*libgcc_s_getcfa) (struct _Unwind_Context *);
+
+void
+__attribute_noinline__
+pthread_cancel_init (void)
+{
+ void *resume, *personality, *forcedunwind, *getcfa;
+ void *handle;
+
+ if (__builtin_expect (libgcc_s_getcfa != NULL, 1))
+ {
+ /* Force gcc to reload all values. */
+ asm volatile ("" ::: "memory");
+ return;
+ }
+
+ handle = __libc_dlopen ("libgcc_s.so.1");
+
+ if (handle == NULL
+ || (resume = __libc_dlsym (handle, "_Unwind_Resume")) == NULL
+ || (personality = __libc_dlsym (handle, "__gcc_personality_v0")) == NULL
+ || (forcedunwind = __libc_dlsym (handle, "_Unwind_ForcedUnwind"))
+ == NULL
+ || (getcfa = __libc_dlsym (handle, "_Unwind_GetCFA")) == NULL
+#ifdef ARCH_CANCEL_INIT
+ || ARCH_CANCEL_INIT (handle)
+#endif
+ )
+ __libc_fatal ("libgcc_s.so.1 must be installed for pthread_cancel to work\n");
+
+ libgcc_s_resume = resume;
+ libgcc_s_personality = personality;
+ libgcc_s_forcedunwind = forcedunwind;
+ /* Make sure libgcc_s_getcfa is written last. Otherwise,
+ pthread_cancel_init might return early even when the pointer the
+ caller is interested in is not initialized yet. */
+ atomic_write_barrier ();
+ libgcc_s_getcfa = getcfa;
+}
+
+void
+_Unwind_Resume (struct _Unwind_Exception *exc)
+{
+ if (__builtin_expect (libgcc_s_resume == NULL, 0))
+ pthread_cancel_init ();
+
+ libgcc_s_resume (exc);
+}
+
+_Unwind_Reason_Code
+__gcc_personality_v0 (int version, _Unwind_Action actions,
+ _Unwind_Exception_Class exception_class,
+ struct _Unwind_Exception *ue_header,
+ struct _Unwind_Context *context)
+{
+ if (__builtin_expect (libgcc_s_personality == NULL, 0))
+ pthread_cancel_init ();
+
+ return libgcc_s_personality (version, actions, exception_class,
+ ue_header, context);
+}
+
+_Unwind_Reason_Code
+_Unwind_ForcedUnwind (struct _Unwind_Exception *exc, _Unwind_Stop_Fn stop,
+ void *stop_argument)
+{
+ if (__builtin_expect (libgcc_s_forcedunwind == NULL, 0))
+ pthread_cancel_init ();
+
+ return libgcc_s_forcedunwind (exc, stop, stop_argument);
+}
+
+_Unwind_Word
+_Unwind_GetCFA (struct _Unwind_Context *context)
+{
+ if (__builtin_expect (libgcc_s_getcfa == NULL, 0))
+ pthread_cancel_init ();
+
+ return libgcc_s_getcfa (context);
+}
diff --git a/libc/nptl/sysdeps/pthread/unwind-resume.c b/libc/nptl/sysdeps/pthread/unwind-resume.c
new file mode 100644
index 000000000..088f4c6f6
--- /dev/null
+++ b/libc/nptl/sysdeps/pthread/unwind-resume.c
@@ -0,0 +1,64 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <dlfcn.h>
+#include <stdio.h>
+#include <unwind.h>
+
+static void (*libgcc_s_resume) (struct _Unwind_Exception *exc);
+static _Unwind_Reason_Code (*libgcc_s_personality)
+ (int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *,
+ struct _Unwind_Context *);
+
+static void
+init (void)
+{
+ void *resume, *personality;
+ void *handle;
+
+ handle = __libc_dlopen ("libgcc_s.so.1");
+
+ if (handle == NULL
+ || (resume = __libc_dlsym (handle, "_Unwind_Resume")) == NULL
+ || (personality = __libc_dlsym (handle, "__gcc_personality_v0")) == NULL)
+ __libc_fatal ("libgcc_s.so.1 must be installed for pthread_cancel to work\n");
+
+ libgcc_s_resume = resume;
+ libgcc_s_personality = personality;
+}
+
+void
+_Unwind_Resume (struct _Unwind_Exception *exc)
+{
+ if (__builtin_expect (libgcc_s_resume == NULL, 0))
+ init ();
+ libgcc_s_resume (exc);
+}
+
+_Unwind_Reason_Code
+__gcc_personality_v0 (int version, _Unwind_Action actions,
+ _Unwind_Exception_Class exception_class,
+ struct _Unwind_Exception *ue_header,
+ struct _Unwind_Context *context)
+{
+ if (__builtin_expect (libgcc_s_personality == NULL, 0))
+ init ();
+ return libgcc_s_personality (version, actions, exception_class,
+ ue_header, context);
+}
diff --git a/libc/nptl/sysdeps/s390/Makefile b/libc/nptl/sysdeps/s390/Makefile
new file mode 100644
index 000000000..fff17dbd1
--- /dev/null
+++ b/libc/nptl/sysdeps/s390/Makefile
@@ -0,0 +1,25 @@
+# Copyright (C) 2003 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# 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.
+
+ifeq ($(subdir),csu)
+gen-as-const-headers += tcb-offsets.sym
+endif
+
+ifeq ($(subdir),nptl)
+libpthread-routines += ptw-sysdep
+endif
diff --git a/libc/nptl/sysdeps/s390/pthread_spin_init.c b/libc/nptl/sysdeps/s390/pthread_spin_init.c
new file mode 100644
index 000000000..814bb484e
--- /dev/null
+++ b/libc/nptl/sysdeps/s390/pthread_spin_init.c
@@ -0,0 +1,20 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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. */
+
+/* Not needed. pthread_spin_init is an alias for pthread_spin_unlock. */
diff --git a/libc/nptl/sysdeps/s390/pthread_spin_lock.c b/libc/nptl/sysdeps/s390/pthread_spin_lock.c
new file mode 100644
index 000000000..f0fddf4ae
--- /dev/null
+++ b/libc/nptl/sysdeps/s390/pthread_spin_lock.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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 "pthreadP.h"
+
+int
+pthread_spin_lock (lock)
+ pthread_spinlock_t *lock;
+{
+ int oldval;
+
+ __asm __volatile ("0: lhi %0,0\n"
+ " cs %0,%2,%1\n"
+ " jl 0b"
+ : "=&d" (oldval), "=Q" (*lock)
+ : "d" (1), "m" (*lock) : "cc" );
+ return 0;
+}
diff --git a/libc/nptl/sysdeps/s390/pthread_spin_trylock.c b/libc/nptl/sysdeps/s390/pthread_spin_trylock.c
new file mode 100644
index 000000000..0153b65da
--- /dev/null
+++ b/libc/nptl/sysdeps/s390/pthread_spin_trylock.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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 <errno.h>
+#include "pthreadP.h"
+
+int
+pthread_spin_trylock (lock)
+ pthread_spinlock_t *lock;
+{
+ int old;
+
+ __asm __volatile ("cs %0,%3,%1"
+ : "=d" (old), "=Q" (*lock)
+ : "0" (0), "d" (1), "m" (*lock) : "cc" );
+
+ return old != 0 ? EBUSY : 0;
+}
diff --git a/libc/nptl/sysdeps/s390/pthread_spin_unlock.c b/libc/nptl/sysdeps/s390/pthread_spin_unlock.c
new file mode 100644
index 000000000..a59c94529
--- /dev/null
+++ b/libc/nptl/sysdeps/s390/pthread_spin_unlock.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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. */
+
+/* Ugly hack to avoid the declaration of pthread_spin_init. */
+#define pthread_spin_init pthread_spin_init_XXX
+#include "pthreadP.h"
+#undef pthread_spin_init
+
+int
+pthread_spin_unlock (pthread_spinlock_t *lock)
+{
+ __asm __volatile (" xc %O0(4,%R0),%0\n"
+ " bcr 15,0"
+ : "=Q" (*lock) : "m" (*lock) : "cc" );
+ return 0;
+}
+strong_alias (pthread_spin_unlock, pthread_spin_init)
diff --git a/libc/nptl/sysdeps/s390/pthreaddef.h b/libc/nptl/sysdeps/s390/pthreaddef.h
new file mode 100644
index 000000000..6569e2aba
--- /dev/null
+++ b/libc/nptl/sysdeps/s390/pthreaddef.h
@@ -0,0 +1,41 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+/* Default stack size. */
+#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024)
+
+/* Required stack pointer alignment at beginning. SSE requires 16
+ bytes. */
+#define STACK_ALIGN 16
+
+/* Minimal stack size after allocating thread descriptor and guard size. */
+#define MINIMAL_REST_STACK 2048
+
+/* Alignment requirement for TCB. */
+#define TCB_ALIGNMENT 16
+
+
+/* Location of current stack frame. */
+#define CURRENT_STACK_FRAME __builtin_frame_address (0)
+
+
+/* XXX Until we have a better place keep the definitions here. */
+
+/* While there is no such syscall. */
+#define __exit_thread_inline(val) \
+ INLINE_SYSCALL (exit, 1, (val))
diff --git a/libc/nptl/sysdeps/s390/tcb-offsets.sym b/libc/nptl/sysdeps/s390/tcb-offsets.sym
new file mode 100644
index 000000000..9cfae211e
--- /dev/null
+++ b/libc/nptl/sysdeps/s390/tcb-offsets.sym
@@ -0,0 +1,7 @@
+#include <sysdep.h>
+#include <tls.h>
+
+MULTIPLE_THREADS_OFFSET offsetof (tcbhead_t, multiple_threads)
+STACK_GUARD offsetof (tcbhead_t, stack_guard)
+PID offsetof (struct pthread, pid)
+TID offsetof (struct pthread, tid)
diff --git a/libc/nptl/sysdeps/s390/tls.h b/libc/nptl/sysdeps/s390/tls.h
new file mode 100644
index 000000000..89ff095d5
--- /dev/null
+++ b/libc/nptl/sysdeps/s390/tls.h
@@ -0,0 +1,176 @@
+/* Definition for thread-local data handling. NPTL/s390 version.
+ Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+#ifndef _TLS_H
+#define _TLS_H 1
+
+#include <dl-sysdep.h>
+#ifndef __ASSEMBLER__
+# include <stdbool.h>
+# include <stddef.h>
+# include <stdint.h>
+# include <stdlib.h>
+# include <list.h>
+
+
+/* Type for the dtv. */
+typedef union dtv
+{
+ size_t counter;
+ struct
+ {
+ void *val;
+ bool is_static;
+ } pointer;
+} dtv_t;
+
+
+typedef struct
+{
+ void *tcb; /* Pointer to the TCB. Not necessary the
+ thread descriptor used by libpthread. */
+ dtv_t *dtv;
+ void *self; /* Pointer to the thread descriptor. */
+ int multiple_threads;
+ uintptr_t sysinfo;
+ uintptr_t stack_guard;
+} tcbhead_t;
+
+# ifndef __s390x__
+# define TLS_MULTIPLE_THREADS_IN_TCB 1
+# endif
+
+#else /* __ASSEMBLER__ */
+# include <tcb-offsets.h>
+#endif
+
+
+/* We require TLS support in the tools. */
+#ifndef HAVE_TLS_SUPPORT
+# error "TLS support is required."
+#endif
+
+/* Signal that TLS support is available. */
+#define USE_TLS 1
+
+/* Alignment requirement for the stack. For IA-32 this is governed by
+ the SSE memory functions. */
+#define STACK_ALIGN 16
+
+#ifndef __ASSEMBLER__
+/* Get system call information. */
+# include <sysdep.h>
+
+/* Get the thread descriptor definition. */
+# include <nptl/descr.h>
+
+/* This is the size of the initial TCB. Can't be just sizeof (tcbhead_t),
+ because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
+ struct pthread even when not linked with -lpthread. */
+# define TLS_INIT_TCB_SIZE sizeof (struct pthread)
+
+/* Alignment requirements for the initial TCB. */
+# define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
+
+/* This is the size of the TCB. */
+# define TLS_TCB_SIZE sizeof (struct pthread)
+
+/* Alignment requirements for the TCB. */
+# define TLS_TCB_ALIGN __alignof__ (struct pthread)
+
+/* The TCB can have any size and the memory following the address the
+ thread pointer points to is unspecified. Allocate the TCB there. */
+# define TLS_TCB_AT_TP 1
+
+
+/* Install the dtv pointer. The pointer passed is to the element with
+ index -1 which contain the length. */
+# define INSTALL_DTV(descr, dtvp) \
+ ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
+
+/* Install new dtv for current thread. */
+# define INSTALL_NEW_DTV(dtv) \
+ (((tcbhead_t *) __builtin_thread_pointer ())->dtv = (dtv))
+
+/* Return dtv of given thread descriptor. */
+# define GET_DTV(descr) \
+ (((tcbhead_t *) (descr))->dtv)
+
+#if defined NEED_DL_SYSINFO && defined SHARED
+# define INIT_SYSINFO \
+ _head->sysinfo = GLRO(dl_sysinfo)
+#else
+# define INIT_SYSINFO
+#endif
+
+/* Code to initially initialize the thread pointer. This might need
+ special attention since 'errno' is not yet available and if the
+ operation can cause a failure 'errno' must not be touched. */
+# define TLS_INIT_TP(thrdescr, secondcall) \
+ ({ void *_thrdescr = (thrdescr); \
+ tcbhead_t *_head = _thrdescr; \
+ \
+ _head->tcb = _thrdescr; \
+ /* For now the thread descriptor is at the same address. */ \
+ _head->self = _thrdescr; \
+ /* New syscall handling support. */ \
+ INIT_SYSINFO; \
+ \
+ __builtin_set_thread_pointer (_thrdescr); \
+ NULL; \
+ })
+
+/* Return the address of the dtv for the current thread. */
+# define THREAD_DTV() \
+ (((tcbhead_t *) __builtin_thread_pointer ())->dtv)
+
+/* Return the thread descriptor for the current thread. */
+# define THREAD_SELF ((struct pthread *) __builtin_thread_pointer ())
+
+/* Magic for libthread_db to know how to do THREAD_SELF. */
+# define DB_THREAD_SELF REGISTER (32, 32, 18 * 4, 0) \
+ REGISTER (64, __WORDSIZE, 18 * 8, 0)
+
+/* Access to data in the thread descriptor is easy. */
+#define THREAD_GETMEM(descr, member) \
+ descr->member
+#define THREAD_GETMEM_NC(descr, member, idx) \
+ descr->member[idx]
+#define THREAD_SETMEM(descr, member, value) \
+ descr->member = (value)
+#define THREAD_SETMEM_NC(descr, member, idx, value) \
+ descr->member[idx] = (value)
+
+/* Set the stack guard field in TCB head. */
+#define THREAD_SET_STACK_GUARD(value) \
+ THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
+#define THREAD_COPY_STACK_GUARD(descr) \
+ ((descr)->header.stack_guard \
+ = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
+
+/* s390 doesn't have HP_TIMING_*, so for the time being
+ use stack_guard as pointer_guard. */
+#define THREAD_GET_POINTER_GUARD() \
+ THREAD_GETMEM (THREAD_SELF, header.stack_guard)
+#define THREAD_SET_POINTER_GUARD(value)
+#define THREAD_COPY_POINTER_GUARD(descr)
+
+#endif /* __ASSEMBLER__ */
+
+#endif /* tls.h */
diff --git a/libc/nptl/sysdeps/sh/Makefile b/libc/nptl/sysdeps/sh/Makefile
new file mode 100644
index 000000000..81bddf688
--- /dev/null
+++ b/libc/nptl/sysdeps/sh/Makefile
@@ -0,0 +1,3 @@
+ifeq ($(subdir),csu)
+gen-as-const-headers += tcb-offsets.sym
+endif
diff --git a/libc/nptl/sysdeps/sh/pthread_spin_init.c b/libc/nptl/sysdeps/sh/pthread_spin_init.c
new file mode 100644
index 000000000..0a47981aa
--- /dev/null
+++ b/libc/nptl/sysdeps/sh/pthread_spin_init.c
@@ -0,0 +1,20 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+/* Not needed. pthread_spin_init is an alias for pthread_spin_unlock. */
diff --git a/libc/nptl/sysdeps/sh/pthread_spin_lock.c b/libc/nptl/sysdeps/sh/pthread_spin_lock.c
new file mode 100644
index 000000000..e73264108
--- /dev/null
+++ b/libc/nptl/sysdeps/sh/pthread_spin_lock.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 "pthreadP.h"
+
+int
+pthread_spin_lock (lock)
+ pthread_spinlock_t *lock;
+{
+ unsigned int val;
+
+ do
+ asm volatile ("tas.b @%1; movt %0"
+ : "=&r" (val)
+ : "r" (lock)
+ : "memory");
+ while (val == 0);
+
+ return 0;
+}
diff --git a/libc/nptl/sysdeps/sh/pthread_spin_trylock.S b/libc/nptl/sysdeps/sh/pthread_spin_trylock.S
new file mode 100644
index 000000000..18112ba23
--- /dev/null
+++ b/libc/nptl/sysdeps/sh/pthread_spin_trylock.S
@@ -0,0 +1,32 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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-errnos.h>
+
+ .globl pthread_spin_trylock
+ .type pthread_spin_trylock,@function
+ .align 5
+pthread_spin_trylock:
+ tas.b @r4
+ bf/s 1f
+ mov #EBUSY, r0
+ mov #0, r0
+1:
+ rts
+ nop
+ .size pthread_spin_trylock,.-pthread_spin_trylock
diff --git a/libc/nptl/sysdeps/sh/pthread_spin_unlock.S b/libc/nptl/sysdeps/sh/pthread_spin_unlock.S
new file mode 100644
index 000000000..c77acaffe
--- /dev/null
+++ b/libc/nptl/sysdeps/sh/pthread_spin_unlock.S
@@ -0,0 +1,30 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+ .globl pthread_spin_unlock
+ .type pthread_spin_unlock,@function
+ .align 5
+pthread_spin_unlock:
+ mov #0,r0
+ rts
+ mov.l r0,@r4
+ .size pthread_spin_unlock,.-pthread_spin_unlock
+
+ /* The implementation of pthread_spin_init is identical. */
+ .globl pthread_spin_init
+pthread_spin_init = pthread_spin_unlock
diff --git a/libc/nptl/sysdeps/sh/pthreaddef.h b/libc/nptl/sysdeps/sh/pthreaddef.h
new file mode 100644
index 000000000..70c6a850b
--- /dev/null
+++ b/libc/nptl/sysdeps/sh/pthreaddef.h
@@ -0,0 +1,49 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+
+/* Default stack size. */
+#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024)
+
+/* Required stack pointer alignment at beginning. */
+#define STACK_ALIGN 8
+
+/* Minimal stack size after allocating thread descriptor and guard size. */
+#define MINIMAL_REST_STACK 2048
+
+/* Alignment requirement for TCB. */
+#define TCB_ALIGNMENT 8
+
+
+/* Location of current stack frame. */
+#define CURRENT_STACK_FRAME __builtin_frame_address (0)
+
+
+/* XXX Until we have a better place keep the definitions here. */
+
+/* While there is no such syscall. */
+#define __exit_thread_inline(val) \
+ while (1) { \
+ if (__builtin_constant_p (val) && (val) == 0) \
+ asm volatile ("mov #0,r4; mov %0,r3; trapa #0x11\n\t" SYSCALL_INST_PAD \
+ :: "i" (__NR_exit)); \
+ else \
+ asm volatile ("mov %1,r4; mov %0,r3; trapa #0x11\n\t" SYSCALL_INST_PAD \
+ :: "i" (__NR_exit), "r" (val)); \
+ }
diff --git a/libc/nptl/sysdeps/sh/tcb-offsets.sym b/libc/nptl/sysdeps/sh/tcb-offsets.sym
new file mode 100644
index 000000000..4ad866335
--- /dev/null
+++ b/libc/nptl/sysdeps/sh/tcb-offsets.sym
@@ -0,0 +1,12 @@
+#include <sysdep.h>
+#include <tls.h>
+
+RESULT offsetof (struct pthread, result)
+TID offsetof (struct pthread, tid)
+PID offsetof (struct pthread, pid)
+CANCELHANDLING offsetof (struct pthread, cancelhandling)
+CLEANUP_JMP_BUF offsetof (struct pthread, cleanup_jmp_buf)
+MULTIPLE_THREADS_OFFSET offsetof (struct pthread, header.multiple_threads)
+TLS_PRE_TCB_SIZE sizeof (struct pthread)
+MUTEX_FUTEX offsetof (pthread_mutex_t, __data.__lock)
+POINTER_GUARD offsetof (tcbhead_t, pointer_guard)
diff --git a/libc/nptl/sysdeps/sh/tls.h b/libc/nptl/sysdeps/sh/tls.h
new file mode 100644
index 000000000..49d105518
--- /dev/null
+++ b/libc/nptl/sysdeps/sh/tls.h
@@ -0,0 +1,158 @@
+/* Definition for thread-local data handling. NPTL/SH version.
+ Copyright (C) 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+#ifndef _TLS_H
+#define _TLS_H
+
+# include <dl-sysdep.h>
+
+#ifndef __ASSEMBLER__
+# include <stdbool.h>
+# include <stddef.h>
+# include <stdint.h>
+
+/* Type for the dtv. */
+typedef union dtv
+{
+ size_t counter;
+ struct
+ {
+ void *val;
+ bool is_static;
+ } pointer;
+} dtv_t;
+
+typedef struct
+{
+ dtv_t *dtv;
+ uintptr_t pointer_guard;
+} tcbhead_t;
+
+# define TLS_MULTIPLE_THREADS_IN_TCB 1
+
+#else /* __ASSEMBLER__ */
+# include <tcb-offsets.h>
+#endif /* __ASSEMBLER__ */
+
+
+/* We require TLS support in the tools. */
+#ifndef HAVE_TLS_SUPPORT
+# error "TLS support is required."
+#endif
+
+/* Signal that TLS support is available. */
+# define USE_TLS 1
+
+#ifndef __ASSEMBLER__
+
+/* Get system call information. */
+# include <sysdep.h>
+
+/* This is the size of the initial TCB. */
+# define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
+
+/* Alignment requirements for the initial TCB. */
+# define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
+
+/* This is the size of the TCB. */
+# define TLS_TCB_SIZE sizeof (tcbhead_t)
+
+/* This is the size we need before TCB. */
+# define TLS_PRE_TCB_SIZE sizeof (struct pthread)
+
+/* Alignment requirements for the TCB. */
+# define TLS_TCB_ALIGN __alignof__ (struct pthread)
+
+/* The TLS blocks start right after the TCB. */
+# define TLS_DTV_AT_TP 1
+
+/* Get the thread descriptor definition. */
+# include <nptl/descr.h>
+
+/* Install the dtv pointer. The pointer passed is to the element with
+ index -1 which contain the length. */
+# define INSTALL_DTV(tcbp, dtvp) \
+ ((tcbhead_t *) (tcbp))->dtv = (dtvp) + 1
+
+/* Install new dtv for current thread. */
+# define INSTALL_NEW_DTV(dtv) \
+ ({ tcbhead_t *__tcbp; \
+ __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
+ __tcbp->dtv = (dtv);})
+
+/* Return dtv of given thread descriptor. */
+# define GET_DTV(tcbp) \
+ (((tcbhead_t *) (tcbp))->dtv)
+
+/* Code to initially initialize the thread pointer. This might need
+ special attention since 'errno' is not yet available and if the
+ operation can cause a failure 'errno' must not be touched. */
+# define TLS_INIT_TP(tcbp, secondcall) \
+ ({ __asm __volatile ("ldc %0,gbr" : : "r" (tcbp)); 0; })
+
+/* Return the address of the dtv for the current thread. */
+# define THREAD_DTV() \
+ ({ tcbhead_t *__tcbp; \
+ __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
+ __tcbp->dtv;})
+
+/* Return the thread descriptor for the current thread.
+ The contained asm must *not* be marked volatile since otherwise
+ assignments like
+ struct pthread *self = thread_self();
+ do not get optimized away. */
+# define THREAD_SELF \
+ ({ struct pthread *__self; \
+ __asm ("stc gbr,%0" : "=r" (__self)); \
+ __self - 1;})
+
+/* Magic for libthread_db to know how to do THREAD_SELF. */
+# define DB_THREAD_SELF \
+ REGISTER (32, 32, REG_GBR * 4, -sizeof (struct pthread))
+
+/* Read member of the thread descriptor directly. */
+# define THREAD_GETMEM(descr, member) (descr->member)
+
+/* Same as THREAD_GETMEM, but the member offset can be non-constant. */
+# define THREAD_GETMEM_NC(descr, member, idx) (descr->member[idx])
+
+/* Set member of the thread descriptor directly. */
+# define THREAD_SETMEM(descr, member, value) \
+ descr->member = (value)
+
+/* Same as THREAD_SETMEM, but the member offset can be non-constant. */
+# define THREAD_SETMEM_NC(descr, member, idx, value) \
+ descr->member[idx] = (value)
+
+#define THREAD_GET_POINTER_GUARD() \
+ ({ tcbhead_t *__tcbp; \
+ __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
+ __tcbp->pointer_guard;})
+ #define THREAD_SET_POINTER_GUARD(value) \
+ ({ tcbhead_t *__tcbp; \
+ __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
+ __tcbp->pointer_guard = (value);})
+#define THREAD_COPY_POINTER_GUARD(descr) \
+ ({ tcbhead_t *__tcbp; \
+ __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
+ ((tcbhead_t *) (descr + 1))->pointer_guard = __tcbp->pointer_guard;})
+
+#endif /* __ASSEMBLER__ */
+
+#endif /* tls.h */
diff --git a/libc/nptl/sysdeps/sparc/Makefile b/libc/nptl/sysdeps/sparc/Makefile
new file mode 100644
index 000000000..81bddf688
--- /dev/null
+++ b/libc/nptl/sysdeps/sparc/Makefile
@@ -0,0 +1,3 @@
+ifeq ($(subdir),csu)
+gen-as-const-headers += tcb-offsets.sym
+endif
diff --git a/libc/nptl/sysdeps/sparc/sparc32/pthread_spin_lock.c b/libc/nptl/sysdeps/sparc/sparc32/pthread_spin_lock.c
new file mode 100644
index 000000000..d3c6e3049
--- /dev/null
+++ b/libc/nptl/sysdeps/sparc/sparc32/pthread_spin_lock.c
@@ -0,0 +1,40 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 "pthreadP.h"
+
+int
+pthread_spin_lock (pthread_spinlock_t *lock)
+{
+ __asm __volatile
+ ("1: ldstub [%0], %%g2\n"
+ " orcc %%g2, 0x0, %%g0\n"
+ " bne,a 2f\n"
+ " ldub [%0], %%g2\n"
+ ".subsection 2\n"
+ "2: orcc %%g2, 0x0, %%g0\n"
+ " bne,a 2b\n"
+ " ldub [%0], %%g2\n"
+ " b,a 1b\n"
+ ".previous"
+ : /* no outputs */
+ : "r" (lock)
+ : "g2", "memory", "cc");
+ return 0;
+}
diff --git a/libc/nptl/sysdeps/sparc/sparc32/pthread_spin_trylock.c b/libc/nptl/sysdeps/sparc/sparc32/pthread_spin_trylock.c
new file mode 100644
index 000000000..bcc3158fd
--- /dev/null
+++ b/libc/nptl/sysdeps/sparc/sparc32/pthread_spin_trylock.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 <errno.h>
+#include "pthreadP.h"
+
+int
+pthread_spin_trylock (pthread_spinlock_t *lock)
+{
+ int res;
+ __asm __volatile ("ldstub [%1], %0" : "=r" (res) : "r" (lock) : "memory");
+ return res == 0 ? 0 : EBUSY;
+}
diff --git a/libc/nptl/sysdeps/sparc/sparc32/pthreaddef.h b/libc/nptl/sysdeps/sparc/sparc32/pthreaddef.h
new file mode 100644
index 000000000..9908df9e9
--- /dev/null
+++ b/libc/nptl/sysdeps/sparc/sparc32/pthreaddef.h
@@ -0,0 +1,40 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+/* Default stack size. */
+#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024)
+
+/* Required stack pointer alignment at beginning. */
+#define STACK_ALIGN 16
+
+/* Minimal stack size after allocating thread descriptor and guard size. */
+#define MINIMAL_REST_STACK 2048
+
+/* Alignment requirement for TCB. */
+#define TCB_ALIGNMENT 16
+
+
+/* Location of current stack frame. */
+#define CURRENT_STACK_FRAME (stack_pointer + (2 * 64))
+register char *stack_pointer __asm__("%sp");
+
+/* XXX Until we have a better place keep the definitions here. */
+
+/* While there is no such syscall. */
+#define __exit_thread_inline(val) \
+ INLINE_SYSCALL (exit, 1, (val))
diff --git a/libc/nptl/sysdeps/sparc/sparc32/sparcv9/pthread_spin_lock.c b/libc/nptl/sysdeps/sparc/sparc32/sparcv9/pthread_spin_lock.c
new file mode 100644
index 000000000..8880f535b
--- /dev/null
+++ b/libc/nptl/sysdeps/sparc/sparc32/sparcv9/pthread_spin_lock.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 "pthreadP.h"
+
+int
+pthread_spin_lock (pthread_spinlock_t *lock)
+{
+ __asm __volatile
+ ("1: ldstub [%0], %%g2\n"
+ " brnz,pn %%g2, 2f\n"
+ " membar #StoreLoad | #StoreStore\n"
+ ".subsection 2\n"
+ "2: ldub [%0], %%g2\n"
+ " brnz,pt %%g2, 2b\n"
+ " membar #LoadLoad\n"
+ " b,a,pt %%xcc, 1b\n"
+ ".previous"
+ : /* no outputs */
+ : "r" (lock)
+ : "g2", "memory");
+ return 0;
+}
diff --git a/libc/nptl/sysdeps/sparc/sparc32/sparcv9/pthread_spin_trylock.c b/libc/nptl/sysdeps/sparc/sparc32/sparcv9/pthread_spin_trylock.c
new file mode 100644
index 000000000..3b20a2180
--- /dev/null
+++ b/libc/nptl/sysdeps/sparc/sparc32/sparcv9/pthread_spin_trylock.c
@@ -0,0 +1 @@
+#include <sparc64/pthread_spin_trylock.c>
diff --git a/libc/nptl/sysdeps/sparc/sparc32/sparcv9/pthread_spin_unlock.c b/libc/nptl/sysdeps/sparc/sparc32/sparcv9/pthread_spin_unlock.c
new file mode 100644
index 000000000..482cbe3d7
--- /dev/null
+++ b/libc/nptl/sysdeps/sparc/sparc32/sparcv9/pthread_spin_unlock.c
@@ -0,0 +1 @@
+#include <sparc64/pthread_spin_unlock.c>
diff --git a/libc/nptl/sysdeps/sparc/sparc64/pthread_spin_lock.c b/libc/nptl/sysdeps/sparc/sparc64/pthread_spin_lock.c
new file mode 100644
index 000000000..77171d9b9
--- /dev/null
+++ b/libc/nptl/sysdeps/sparc/sparc64/pthread_spin_lock.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 "pthreadP.h"
+
+int
+pthread_spin_lock (pthread_spinlock_t *lock)
+{
+ __asm __volatile
+ ("1: ldstub [%0], %%g5\n"
+ " brnz,pn %%g5, 2f\n"
+ " membar #StoreLoad | #StoreStore\n"
+ ".subsection 2\n"
+ "2: ldub [%0], %%g5\n"
+ " brnz,pt %%g5, 2b\n"
+ " membar #LoadLoad\n"
+ " b,a,pt %%xcc, 1b\n"
+ ".previous"
+ : /* no outputs */
+ : "r" (lock)
+ : "g5", "memory");
+ return 0;
+}
diff --git a/libc/nptl/sysdeps/sparc/sparc64/pthread_spin_trylock.c b/libc/nptl/sysdeps/sparc/sparc64/pthread_spin_trylock.c
new file mode 100644
index 000000000..2bda809da
--- /dev/null
+++ b/libc/nptl/sysdeps/sparc/sparc64/pthread_spin_trylock.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 <errno.h>
+#include "pthreadP.h"
+
+int
+pthread_spin_trylock (pthread_spinlock_t *lock)
+{
+ int res;
+ __asm __volatile
+ ("ldstub [%1], %0\n"
+ "membar #StoreLoad | #StoreStore"
+ : "=r" (res)
+ : "r" (lock)
+ : "memory");
+ return res == 0 ? 0 : EBUSY;
+}
diff --git a/libc/nptl/sysdeps/sparc/sparc64/pthread_spin_unlock.c b/libc/nptl/sysdeps/sparc/sparc64/pthread_spin_unlock.c
new file mode 100644
index 000000000..7037675a2
--- /dev/null
+++ b/libc/nptl/sysdeps/sparc/sparc64/pthread_spin_unlock.c
@@ -0,0 +1,30 @@
+/* pthread_spin_unlock -- unlock a spin lock. Generic version.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus@au.ibm.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 "pthreadP.h"
+#include <atomic.h>
+
+int
+pthread_spin_unlock (pthread_spinlock_t *lock)
+{
+ __asm __volatile ("membar #StoreStore | #LoadStore");
+ *lock = 0;
+ return 0;
+}
diff --git a/libc/nptl/sysdeps/sparc/sparc64/pthreaddef.h b/libc/nptl/sysdeps/sparc/sparc64/pthreaddef.h
new file mode 100644
index 000000000..ec7651211
--- /dev/null
+++ b/libc/nptl/sysdeps/sparc/sparc64/pthreaddef.h
@@ -0,0 +1,40 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+/* Default stack size. */
+#define ARCH_STACK_DEFAULT_SIZE (4 * 1024 * 1024)
+
+/* Required stack pointer alignment at beginning. */
+#define STACK_ALIGN 16
+
+/* Minimal stack size after allocating thread descriptor and guard size. */
+#define MINIMAL_REST_STACK 4096
+
+/* Alignment requirement for TCB. */
+#define TCB_ALIGNMENT 16
+
+
+/* Location of current stack frame. */
+#define CURRENT_STACK_FRAME (stack_pointer + (2 * 128))
+register char *stack_pointer __asm__("%sp");
+
+/* XXX Until we have a better place keep the definitions here. */
+
+/* While there is no such syscall. */
+#define __exit_thread_inline(val) \
+ INLINE_SYSCALL (exit, 1, (val))
diff --git a/libc/nptl/sysdeps/sparc/tcb-offsets.sym b/libc/nptl/sysdeps/sparc/tcb-offsets.sym
new file mode 100644
index 000000000..923af8a5b
--- /dev/null
+++ b/libc/nptl/sysdeps/sparc/tcb-offsets.sym
@@ -0,0 +1,7 @@
+#include <sysdep.h>
+#include <tls.h>
+
+MULTIPLE_THREADS_OFFSET offsetof (tcbhead_t, multiple_threads)
+POINTER_GUARD offsetof (tcbhead_t, pointer_guard)
+PID offsetof (struct pthread, pid)
+TID offsetof (struct pthread, tid)
diff --git a/libc/nptl/sysdeps/sparc/tls.h b/libc/nptl/sysdeps/sparc/tls.h
new file mode 100644
index 000000000..127bbf695
--- /dev/null
+++ b/libc/nptl/sysdeps/sparc/tls.h
@@ -0,0 +1,149 @@
+/* Definitions for thread-local data handling. NPTL/sparc version.
+ Copyright (C) 2003, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+#ifndef _TLS_H
+#define _TLS_H
+
+#include <dl-sysdep.h>
+#ifndef __ASSEMBLER__
+# include <stdbool.h>
+# include <stddef.h>
+# include <stdint.h>
+# include <stdlib.h>
+# include <list.h>
+
+/* Type for the dtv. */
+typedef union dtv
+{
+ size_t counter;
+ struct
+ {
+ void *val;
+ bool is_static;
+ } pointer;
+} dtv_t;
+
+typedef struct
+{
+ void *tcb; /* Pointer to the TCB. Not necessary the
+ thread descriptor used by libpthread. */
+ dtv_t *dtv;
+ void *self;
+ int multiple_threads;
+ uintptr_t sysinfo;
+ uintptr_t stack_guard;
+ uintptr_t pointer_guard;
+} tcbhead_t;
+
+#else /* __ASSEMBLER__ */
+# include <tcb-offsets.h>
+#endif /* __ASSEMBLER__ */
+
+/* We require TLS support in the tools. */
+#ifndef HAVE_TLS_SUPPORT
+# error "TLS support is required."
+#endif
+
+/* Signal that TLS support is available. */
+#define USE_TLS 1
+
+#ifndef __ASSEMBLER__
+/* Get system call information. */
+# include <sysdep.h>
+
+/* Get the thread descriptor definition. */
+# include <nptl/descr.h>
+
+register struct pthread *__thread_self __asm__("%g7");
+
+/* This is the size of the initial TCB. Can't be just sizeof (tcbhead_t),
+ because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
+ struct pthread even when not linked with -lpthread. */
+# define TLS_INIT_TCB_SIZE sizeof (struct pthread)
+
+/* Alignment requirements for the initial TCB. */
+# define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
+
+/* This is the size of the TCB. */
+# define TLS_TCB_SIZE sizeof (struct pthread)
+
+/* Alignment requirements for the TCB. */
+# define TLS_TCB_ALIGN __alignof__ (struct pthread)
+
+/* The TCB can have any size and the memory following the address the
+ thread pointer points to is unspecified. Allocate the TCB there. */
+# define TLS_TCB_AT_TP 1
+
+/* Install the dtv pointer. The pointer passed is to the element with
+ index -1 which contain the length. */
+# define INSTALL_DTV(descr, dtvp) \
+ ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
+
+/* Install new dtv for current thread. */
+# define INSTALL_NEW_DTV(DTV) \
+ (((tcbhead_t *) __thread_self)->dtv = (DTV))
+
+/* Return dtv of given thread descriptor. */
+# define GET_DTV(descr) \
+ (((tcbhead_t *) (descr))->dtv)
+
+/* Code to initially initialize the thread pointer. */
+# define TLS_INIT_TP(descr, secondcall) \
+ (__thread_self = (__typeof (__thread_self)) (descr), NULL)
+
+/* Return the address of the dtv for the current thread. */
+# define THREAD_DTV() \
+ (((tcbhead_t *) __thread_self)->dtv)
+
+/* Return the thread descriptor for the current thread. */
+#define THREAD_SELF __thread_self
+
+/* Magic for libthread_db to know how to do THREAD_SELF. */
+# define DB_THREAD_SELF_INCLUDE <sys/ucontext.h>
+# define DB_THREAD_SELF \
+ REGISTER (32, 32, REG_G7 * 4, 0) REGISTER (64, 64, REG_G7 * 8, 0)
+
+/* Access to data in the thread descriptor is easy. */
+#define THREAD_GETMEM(descr, member) \
+ descr->member
+#define THREAD_GETMEM_NC(descr, member, idx) \
+ descr->member[idx]
+#define THREAD_SETMEM(descr, member, value) \
+ descr->member = (value)
+#define THREAD_SETMEM_NC(descr, member, idx, value) \
+ descr->member[idx] = (value)
+
+/* Set the stack guard field in TCB head. */
+#define THREAD_SET_STACK_GUARD(value) \
+ THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
+# define THREAD_COPY_STACK_GUARD(descr) \
+ ((descr)->header.stack_guard \
+ = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
+
+/* Get/set the stack guard field in TCB head. */
+#define THREAD_GET_POINTER_GUARD() \
+ THREAD_GETMEM (THREAD_SELF, header.pointer_guard)
+#define THREAD_SET_POINTER_GUARD(value) \
+ THREAD_SETMEM (THREAD_SELF, header.pointer_guard, value)
+# define THREAD_COPY_POINTER_GUARD(descr) \
+ ((descr)->header.pointer_guard = THREAD_GET_POINTER_GUARD ())
+
+#endif /* !ASSEMBLER */
+
+#endif /* tls.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/Implies b/libc/nptl/sysdeps/unix/sysv/linux/Implies
new file mode 100644
index 000000000..f1b3e8939
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/Implies
@@ -0,0 +1 @@
+pthread
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/Makefile b/libc/nptl/sysdeps/unix/sysv/linux/Makefile
new file mode 100644
index 000000000..cfcdb6d97
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/Makefile
@@ -0,0 +1,38 @@
+# Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+# Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+# 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. */
+
+ifeq ($(subdir),nptl)
+sysdep_routines += register-atfork unregister-atfork libc_pthread_init \
+ libc_multiple_threads
+
+libpthread-sysdep_routines += pt-fork pthread_mutex_cond_lock
+
+gen-as-const-headers += lowlevelcond.sym lowlevelrwlock.sym \
+ lowlevelbarrier.sym unwindbuf.sym \
+ lowlevelrobustlock.sym pthread-pi-defines.sym
+endif
+
+ifeq ($(subdir),posix)
+CFLAGS-fork.c = -D_IO_MTSAFE_IO
+CFLAGS-getpid.o = -fomit-frame-pointer
+CFLAGS-getpid.os = -fomit-frame-pointer
+endif
+
+# Needed in both the signal and nptl subdir.
+CFLAGS-sigaction.c = -DWRAPPER_INCLUDE='<nptl/sigaction.c>'
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/Versions b/libc/nptl/sysdeps/unix/sysv/linux/Versions
new file mode 100644
index 000000000..d18255521
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/Versions
@@ -0,0 +1,15 @@
+libc {
+ GLIBC_2.3.2 {
+ __register_atfork;
+ }
+ GLIBC_PRIVATE {
+ __libc_pthread_init;
+ __libc_current_sigrtmin_private; __libc_current_sigrtmax_private;
+ __libc_allocate_rtsig_private;
+ }
+}
+libpthread {
+ GLIBC_2.0 {
+ fork; __fork;
+ }
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/aio_misc.h b/libc/nptl/sysdeps/unix/sysv/linux/aio_misc.h
new file mode 100644
index 000000000..406d96e86
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/aio_misc.h
@@ -0,0 +1,69 @@
+/* Copyright (C) 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _AIO_MISC_H
+# include_next <aio_misc.h>
+# include <limits.h>
+# include <pthread.h>
+# include <signal.h>
+# include <sysdep.h>
+
+# define aio_start_notify_thread __aio_start_notify_thread
+# define aio_create_helper_thread __aio_create_helper_thread
+
+extern inline void
+__aio_start_notify_thread (void)
+{
+ sigset_t ss;
+ sigemptyset (&ss);
+ INTERNAL_SYSCALL_DECL (err);
+ INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, &ss, NULL, _NSIG / 8);
+}
+
+extern inline int
+__aio_create_helper_thread (pthread_t *threadp, void *(*tf) (void *),
+ void *arg)
+{
+ pthread_attr_t attr;
+
+ /* Make sure the thread is created detached. */
+ pthread_attr_init (&attr);
+ pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
+
+ /* The helper thread needs only very little resources. */
+ (void) pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
+
+ /* Block all signals in the helper thread. To do this thoroughly we
+ temporarily have to block all signals here. */
+ sigset_t ss;
+ sigset_t oss;
+ sigfillset (&ss);
+ INTERNAL_SYSCALL_DECL (err);
+ INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, &ss, &oss, _NSIG / 8);
+
+ int ret = pthread_create (threadp, &attr, tf, arg);
+
+ /* Restore the signal mask. */
+ INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, &oss, NULL,
+ _NSIG / 8);
+
+ (void) pthread_attr_destroy (&attr);
+ return ret;
+}
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/allocrtsig.c b/libc/nptl/sysdeps/unix/sysv/linux/allocrtsig.c
new file mode 100644
index 000000000..b37d54d65
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/allocrtsig.c
@@ -0,0 +1,56 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <signal.h>
+
+
+static int current_rtmin = __SIGRTMIN + 2;
+static int current_rtmax = __SIGRTMAX;
+
+
+/* We reserve __SIGRTMIN for use as the cancelation signal. This
+ signal is used internally. */
+int
+__libc_current_sigrtmin (void)
+{
+ return current_rtmin;
+}
+libc_hidden_def (__libc_current_sigrtmin)
+strong_alias (__libc_current_sigrtmin, __libc_current_sigrtmin_private)
+
+
+int
+__libc_current_sigrtmax (void)
+{
+ return current_rtmax;
+}
+libc_hidden_def (__libc_current_sigrtmax)
+strong_alias (__libc_current_sigrtmax, __libc_current_sigrtmax_private)
+
+
+int
+__libc_allocate_rtsig (int high)
+{
+ if (current_rtmin == -1 || current_rtmin > current_rtmax)
+ /* We don't have anymore signal available. */
+ return -1;
+
+ return high ? current_rtmin++ : current_rtmax--;
+}
+strong_alias (__libc_allocate_rtsig, __libc_allocate_rtsig_private)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/alpha/Makefile b/libc/nptl/sysdeps/unix/sysv/linux/alpha/Makefile
new file mode 100644
index 000000000..8c8084079
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/alpha/Makefile
@@ -0,0 +1,2 @@
+# pull in __syscall_error routine, __sigprocmask, __syscall_rt_sigaction
+libpthread-routines += ptw-sysdep ptw-sigprocmask ptw-rt_sigaction
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/alpha/Versions b/libc/nptl/sysdeps/unix/sysv/linux/alpha/Versions
new file mode 100644
index 000000000..437c4da28
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/alpha/Versions
@@ -0,0 +1,13 @@
+libpthread {
+ GLIBC_2.3.3 {
+ # Changed PTHREAD_STACK_MIN.
+ pthread_attr_setstack; pthread_attr_setstacksize;
+ }
+}
+librt {
+ GLIBC_2.3.3 {
+ # Changed timer_t.
+ timer_create; timer_delete; timer_getoverrun; timer_gettime;
+ timer_settime;
+ }
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/alpha/aio_cancel.c b/libc/nptl/sysdeps/unix/sysv/linux/alpha/aio_cancel.c
new file mode 100644
index 000000000..0d6da8291
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/alpha/aio_cancel.c
@@ -0,0 +1,33 @@
+#include <shlib-compat.h>
+
+#define aio_cancel64 XXX
+#include <aio.h>
+#undef aio_cancel64
+#include <errno.h>
+
+extern __typeof (aio_cancel) __new_aio_cancel;
+extern __typeof (aio_cancel) __old_aio_cancel;
+
+#define aio_cancel __new_aio_cancel
+
+#include <sysdeps/pthread/aio_cancel.c>
+
+#undef aio_cancel
+strong_alias (__new_aio_cancel, __new_aio_cancel64);
+versioned_symbol (librt, __new_aio_cancel, aio_cancel, GLIBC_2_3);
+versioned_symbol (librt, __new_aio_cancel64, aio_cancel64, GLIBC_2_3);
+
+#if SHLIB_COMPAT (librt, GLIBC_2_1, GLIBC_2_3)
+
+#undef ECANCELED
+#define aio_cancel __old_aio_cancel
+#define ECANCELED 125
+
+#include <sysdeps/pthread/aio_cancel.c>
+
+#undef aio_cancel
+strong_alias (__old_aio_cancel, __old_aio_cancel64);
+compat_symbol (librt, __old_aio_cancel, aio_cancel, GLIBC_2_1);
+compat_symbol (librt, __old_aio_cancel64, aio_cancel64, GLIBC_2_1);
+
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/alpha/bits/local_lim.h b/libc/nptl/sysdeps/unix/sysv/linux/alpha/bits/local_lim.h
new file mode 100644
index 000000000..e0718780c
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/alpha/bits/local_lim.h
@@ -0,0 +1,89 @@
+/* Minimum guaranteed maximum values for system limits. Linux/Alpha version.
+ Copyright (C) 1993-1998,2000,2002,2003,2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* The kernel header pollutes the namespace with the NR_OPEN symbol
+ and defines LINK_MAX although filesystems have different maxima. A
+ similar thing is true for OPEN_MAX: the limit can be changed at
+ runtime and therefore the macro must not be defined. Remove this
+ after including the header if necessary. */
+#ifndef NR_OPEN
+# define __undef_NR_OPEN
+#endif
+#ifndef LINK_MAX
+# define __undef_LINK_MAX
+#endif
+#ifndef OPEN_MAX
+# define __undef_OPEN_MAX
+#endif
+
+/* The kernel sources contain a file with all the needed information. */
+#include <linux/limits.h>
+
+/* Have to remove NR_OPEN? */
+#ifdef __undef_NR_OPEN
+# undef NR_OPEN
+# undef __undef_NR_OPEN
+#endif
+/* Have to remove LINK_MAX? */
+#ifdef __undef_LINK_MAX
+# undef LINK_MAX
+# undef __undef_LINK_MAX
+#endif
+/* Have to remove OPEN_MAX? */
+#ifdef __undef_OPEN_MAX
+# undef OPEN_MAX
+# undef __undef_OPEN_MAX
+#endif
+
+/* The number of data keys per process. */
+#define _POSIX_THREAD_KEYS_MAX 128
+/* This is the value this implementation supports. */
+#define PTHREAD_KEYS_MAX 1024
+
+/* Controlling the iterations of destructors for thread-specific data. */
+#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
+/* Number of iterations this implementation does. */
+#define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS
+
+/* The number of threads per process. */
+#define _POSIX_THREAD_THREADS_MAX 64
+/* We have no predefined limit on the number of threads. */
+#undef PTHREAD_THREADS_MAX
+
+/* Maximum amount by which a process can descrease its asynchronous I/O
+ priority level. */
+#define AIO_PRIO_DELTA_MAX 20
+
+/* Minimum size for a thread. We are free to choose a reasonable value. */
+#define PTHREAD_STACK_MIN 24576
+
+/* Maximum number of timer expiration overruns. */
+#define DELAYTIMER_MAX 2147483647
+
+/* Maximum tty name length. */
+#define TTY_NAME_MAX 32
+
+/* Maximum login name length. This is arbitrary. */
+#define LOGIN_NAME_MAX 256
+
+/* Maximum host name length. */
+#define HOST_NAME_MAX 64
+
+/* Maximum message queue priority level. */
+#define MQ_PRIO_MAX 32768
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h b/libc/nptl/sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h
new file mode 100644
index 000000000..41a54d4b0
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h
@@ -0,0 +1,168 @@
+/* Machine-specific pthread type layouts. Alpha version.
+ Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+#ifndef _BITS_PTHREADTYPES_H
+#define _BITS_PTHREADTYPES_H 1
+
+#define __SIZEOF_PTHREAD_ATTR_T 56
+#define __SIZEOF_PTHREAD_MUTEX_T 40
+#define __SIZEOF_PTHREAD_MUTEXATTR_T 4
+#define __SIZEOF_PTHREAD_COND_T 48
+#define __SIZEOF_PTHREAD_CONDATTR_T 4
+#define __SIZEOF_PTHREAD_RWLOCK_T 56
+#define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
+#define __SIZEOF_PTHREAD_BARRIER_T 32
+#define __SIZEOF_PTHREAD_BARRIERATTR_T 4
+
+
+/* Thread identifiers. The structure of the attribute type is
+ deliberately not exposed. */
+typedef unsigned long int pthread_t;
+
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_ATTR_T];
+ long int __align;
+} pthread_attr_t;
+
+
+typedef struct __pthread_internal_list
+{
+ struct __pthread_internal_list *__prev;
+ struct __pthread_internal_list *__next;
+} __pthread_list_t;
+
+
+/* Data structures for mutex handling. The structure of the attribute
+ type is deliberately not exposed. */
+typedef union
+{
+ struct __pthread_mutex_s
+ {
+ int __lock;
+ unsigned int __count;
+ int __owner;
+ unsigned int __nusers;
+ /* KIND must stay at this position in the structure to maintain
+ binary compatibility. */
+ int __kind;
+ int __spins;
+ __pthread_list_t __list;
+#define __PTHREAD_MUTEX_HAVE_PREV 1
+ } __data;
+ char __size[__SIZEOF_PTHREAD_MUTEX_T];
+ long int __align;
+} pthread_mutex_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_MUTEXATTR_T];
+ int __align;
+} pthread_mutexattr_t;
+
+
+/* Data structure for conditional variable handling. The structure of
+ the attribute type is deliberately not exposed. */
+typedef union
+{
+ struct
+ {
+ int __lock;
+ unsigned int __futex;
+ __extension__ unsigned long long int __total_seq;
+ __extension__ unsigned long long int __wakeup_seq;
+ __extension__ unsigned long long int __woken_seq;
+ void *__mutex;
+ unsigned int __nwaiters;
+ unsigned int __broadcast_seq;
+ } __data;
+ char __size[__SIZEOF_PTHREAD_COND_T];
+ __extension__ long long int __align;
+} pthread_cond_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_CONDATTR_T];
+ int __align;
+} pthread_condattr_t;
+
+
+/* Keys for thread-specific data */
+typedef unsigned int pthread_key_t;
+
+
+/* Once-only execution */
+typedef int pthread_once_t;
+
+
+#if defined __USE_UNIX98 || defined __USE_XOPEN2K
+/* Data structure for read-write lock variable handling. The
+ structure of the attribute type is deliberately not exposed. */
+typedef union
+{
+ struct
+ {
+ int __lock;
+ unsigned int __nr_readers;
+ unsigned int __readers_wakeup;
+ unsigned int __writer_wakeup;
+ unsigned int __nr_readers_queued;
+ unsigned int __nr_writers_queued;
+ int __writer;
+ int __pad1;
+ unsigned long int __pad2;
+ unsigned long int __pad3;
+ /* FLAGS must stay at this position in the structure to maintain
+ binary compatibility. */
+ unsigned int __flags;
+ } __data;
+ char __size[__SIZEOF_PTHREAD_RWLOCK_T];
+ long int __align;
+} pthread_rwlock_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_RWLOCKATTR_T];
+ long int __align;
+} pthread_rwlockattr_t;
+#endif
+
+
+#ifdef __USE_XOPEN2K
+/* POSIX spinlock data type. */
+typedef volatile int pthread_spinlock_t;
+
+/* POSIX barriers data type. The structure of the type is
+ deliberately not exposed. */
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_BARRIER_T];
+ long int __align;
+} pthread_barrier_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_BARRIERATTR_T];
+ int __align;
+} pthread_barrierattr_t;
+#endif
+
+
+#endif /* bits/pthreadtypes.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/alpha/bits/semaphore.h b/libc/nptl/sysdeps/unix/sysv/linux/alpha/bits/semaphore.h
new file mode 100644
index 000000000..6dadfda20
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/alpha/bits/semaphore.h
@@ -0,0 +1,37 @@
+/* Machine-specific POSIX semaphore type layouts. Alpha version.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+#ifndef _SEMAPHORE_H
+# error "Never use <bits/semaphore.h> directly; include <semaphore.h> instead."
+#endif
+
+# define __SIZEOF_SEM_T 32
+
+/* Value returned if `sem_open' failed. */
+#define SEM_FAILED ((sem_t *) 0)
+
+/* Maximum value the semaphore can have. */
+#define SEM_VALUE_MAX (2147483647)
+
+
+typedef union
+{
+ char __size[__SIZEOF_SEM_T];
+ long int __align;
+} sem_t;
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/alpha/clone.S b/libc/nptl/sysdeps/unix/sysv/linux/alpha/clone.S
new file mode 100644
index 000000000..675a997e9
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/alpha/clone.S
@@ -0,0 +1,9 @@
+/* We want an #include_next, but we are the main source file.
+ So, #include ourselves and in that incarnation we can use #include_next. */
+#ifndef INCLUDED_SELF
+# define INCLUDED_SELF
+# include <clone.S>
+#else
+# define RESET_PID
+# include_next <clone.S>
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/alpha/createthread.c b/libc/nptl/sysdeps/unix/sysv/linux/alpha/createthread.c
new file mode 100644
index 000000000..6a51e73da
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/alpha/createthread.c
@@ -0,0 +1,23 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+/* Value passed to 'clone' for initialization of the thread register. */
+#define TLS_VALUE (pd + 1)
+
+/* Get the real implementation. */
+#include <nptl/sysdeps/pthread/createthread.c>
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/alpha/fork.c b/libc/nptl/sysdeps/unix/sysv/linux/alpha/fork.c
new file mode 100644
index 000000000..ca85fc008
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/alpha/fork.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sched.h>
+#include <signal.h>
+#include <sysdep.h>
+#include <tls.h>
+
+
+#define ARCH_FORK() \
+ INLINE_SYSCALL (clone, 5, \
+ CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, \
+ NULL, NULL, &THREAD_SELF->tid, NULL)
+
+#include "../fork.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/alpha/lowlevellock.h b/libc/nptl/sysdeps/unix/sysv/linux/alpha/lowlevellock.h
new file mode 100644
index 000000000..58b4806eb
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/alpha/lowlevellock.h
@@ -0,0 +1,296 @@
+/* Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 Libr \ary; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _LOWLEVELLOCK_H
+#define _LOWLEVELLOCK_H 1
+
+#include <time.h>
+#include <sys/param.h>
+#include <bits/pthreadtypes.h>
+#include <atomic.h>
+#include <sysdep.h>
+
+
+#define __NR_futex 394
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+#define FUTEX_REQUEUE 3
+#define FUTEX_CMP_REQUEUE 4
+#define FUTEX_WAKE_OP 5
+#define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE ((4 << 24) | 1)
+#define FUTEX_LOCK_PI 6
+#define FUTEX_UNLOCK_PI 7
+#define FUTEX_TRYLOCK_PI 8
+
+/* Initializer for compatibility lock. */
+#define LLL_MUTEX_LOCK_INITIALIZER (0)
+
+#define lll_futex_wait(futexp, val) \
+ ({ \
+ INTERNAL_SYSCALL_DECL (__err); \
+ long int __ret; \
+ __ret = INTERNAL_SYSCALL (futex, __err, 4, \
+ (futexp), FUTEX_WAIT, (val), 0); \
+ INTERNAL_SYSCALL_ERROR_P (__ret, __err)? -__ret : __ret; \
+ })
+
+#define lll_futex_timed_wait(futexp, val, timespec) \
+ ({ \
+ INTERNAL_SYSCALL_DECL (__err); \
+ long int __ret; \
+ __ret = INTERNAL_SYSCALL (futex, __err, 4, \
+ (futexp), FUTEX_WAIT, (val), (timespec)); \
+ INTERNAL_SYSCALL_ERROR_P (__ret, __err)? -__ret : __ret; \
+ })
+
+#define lll_futex_wake(futexp, nr) \
+ ({ \
+ INTERNAL_SYSCALL_DECL (__err); \
+ long int __ret; \
+ __ret = INTERNAL_SYSCALL (futex, __err, 4, \
+ (futexp), FUTEX_WAKE, (nr), 0); \
+ INTERNAL_SYSCALL_ERROR_P (__ret, __err)? -__ret : __ret; \
+ })
+
+#define lll_robust_mutex_dead(futexv) \
+ do \
+ { \
+ int *__futexp = &(futexv); \
+ atomic_or (__futexp, FUTEX_OWNER_DIED); \
+ lll_futex_wake (__futexp, 1); \
+ } \
+ while (0)
+
+/* Returns non-zero if error happened, zero if success. */
+#define lll_futex_requeue(futexp, nr_wake, nr_move, mutex, val) \
+ ({ \
+ INTERNAL_SYSCALL_DECL (__err); \
+ long int __ret; \
+ __ret = INTERNAL_SYSCALL (futex, __err, 6, \
+ (futexp), FUTEX_CMP_REQUEUE, (nr_wake), \
+ (nr_move), (mutex), (val)); \
+ INTERNAL_SYSCALL_ERROR_P (__ret, __err); \
+ })
+
+/* Returns non-zero if error happened, zero if success. */
+#define lll_futex_wake_unlock(futexp, nr_wake, nr_wake2, futexp2) \
+ ({ \
+ INTERNAL_SYSCALL_DECL (__err); \
+ long int __ret; \
+ __ret = INTERNAL_SYSCALL (futex, __err, 6, \
+ (futexp), FUTEX_WAKE_OP, (nr_wake), \
+ (nr_wake2), (futexp2), \
+ FUTEX_OP_CLEAR_WAKE_IF_GT_ONE); \
+ INTERNAL_SYSCALL_ERROR_P (__ret, __err); \
+ })
+
+
+
+
+static inline int __attribute__((always_inline))
+__lll_mutex_trylock(int *futex)
+{
+ return atomic_compare_and_exchange_val_acq (futex, 1, 0) != 0;
+}
+#define lll_mutex_trylock(lock) __lll_mutex_trylock (&(lock))
+
+
+static inline int __attribute__((always_inline))
+__lll_mutex_cond_trylock(int *futex)
+{
+ return atomic_compare_and_exchange_val_acq (futex, 2, 0) != 0;
+}
+#define lll_mutex_cond_trylock(lock) __lll_mutex_cond_trylock (&(lock))
+
+
+static inline int __attribute__((always_inline))
+__lll_robust_mutex_trylock(int *futex, int id)
+{
+ return atomic_compare_and_exchange_val_acq (futex, id, 0) != 0;
+}
+#define lll_robust_mutex_trylock(lock, id) \
+ __lll_robust_mutex_trylock (&(lock), id)
+
+extern void __lll_lock_wait (int *futex) attribute_hidden;
+extern int __lll_robust_lock_wait (int *futex) attribute_hidden;
+
+static inline void __attribute__((always_inline))
+__lll_mutex_lock(int *futex)
+{
+ if (atomic_compare_and_exchange_bool_acq (futex, 1, 0) != 0)
+ __lll_lock_wait (futex);
+}
+#define lll_mutex_lock(futex) __lll_mutex_lock (&(futex))
+
+
+static inline int __attribute__ ((always_inline))
+__lll_robust_mutex_lock (int *futex, int id)
+{
+ int result = 0;
+ if (atomic_compare_and_exchange_bool_acq (futex, id, 0) != 0)
+ result = __lll_robust_lock_wait (futex);
+ return result;
+}
+#define lll_robust_mutex_lock(futex, id) \
+ __lll_robust_mutex_lock (&(futex), id)
+
+
+static inline void __attribute__ ((always_inline))
+__lll_mutex_cond_lock (int *futex)
+{
+ if (atomic_compare_and_exchange_bool_acq (futex, 2, 0) != 0)
+ __lll_lock_wait (futex);
+}
+#define lll_mutex_cond_lock(futex) __lll_mutex_cond_lock (&(futex))
+
+
+#define lll_robust_mutex_cond_lock(futex, id) \
+ __lll_robust_mutex_lock (&(futex), (id) | FUTEX_WAITERS)
+
+
+extern int __lll_timedlock_wait (int *futex, const struct timespec *)
+ attribute_hidden;
+extern int __lll_robust_timedlock_wait (int *futex, const struct timespec *)
+ attribute_hidden;
+
+static inline int __attribute__ ((always_inline))
+__lll_mutex_timedlock (int *futex, const struct timespec *abstime)
+{
+ int result = 0;
+ if (atomic_compare_and_exchange_bool_acq (futex, 1, 0) != 0)
+ result = __lll_timedlock_wait (futex, abstime);
+ return result;
+}
+#define lll_mutex_timedlock(futex, abstime) \
+ __lll_mutex_timedlock (&(futex), abstime)
+
+
+static inline int __attribute__ ((always_inline))
+__lll_robust_mutex_timedlock (int *futex, const struct timespec *abstime,
+ int id)
+{
+ int result = 0;
+ if (atomic_compare_and_exchange_bool_acq (futex, id, 0) != 0)
+ result = __lll_robust_timedlock_wait (futex, abstime);
+ return result;
+}
+#define lll_robust_mutex_timedlock(futex, abstime, id) \
+ __lll_robust_mutex_timedlock (&(futex), abstime, id)
+
+
+static inline void __attribute__ ((always_inline))
+__lll_mutex_unlock (int *futex)
+{
+ int val = atomic_exchange_rel (futex, 0);
+ if (__builtin_expect (val > 1, 0))
+ lll_futex_wake (futex, 1);
+}
+#define lll_mutex_unlock(futex) __lll_mutex_unlock(&(futex))
+
+
+static inline void __attribute__ ((always_inline))
+__lll_robust_mutex_unlock (int *futex, int mask)
+{
+ int val = atomic_exchange_rel (futex, 0);
+ if (__builtin_expect (val & mask, 0))
+ lll_futex_wake (futex, 1);
+}
+#define lll_robust_mutex_unlock(futex) \
+ __lll_robust_mutex_unlock(&(futex), FUTEX_WAITERS)
+
+
+static inline void __attribute__ ((always_inline))
+__lll_mutex_unlock_force (int *futex)
+{
+ (void) atomic_exchange_rel (futex, 0);
+ lll_futex_wake (futex, 1);
+}
+#define lll_mutex_unlock_force(futex) __lll_mutex_unlock_force(&(futex))
+
+
+#define lll_mutex_islocked(futex) \
+ (futex != 0)
+
+
+/* Our internal lock implementation is identical to the binary-compatible
+ mutex implementation. */
+
+/* Type for lock object. */
+typedef int lll_lock_t;
+
+/* Initializers for lock. */
+#define LLL_LOCK_INITIALIZER (0)
+#define LLL_LOCK_INITIALIZER_LOCKED (1)
+
+extern int lll_unlock_wake_cb (int *__futex) attribute_hidden;
+
+/* The states of a lock are:
+ 0 - untaken
+ 1 - taken by one user
+ >1 - taken by more users */
+
+#define lll_trylock(lock) lll_mutex_trylock (lock)
+#define lll_lock(lock) lll_mutex_lock (lock)
+#define lll_unlock(lock) lll_mutex_unlock (lock)
+#define lll_islocked(lock) lll_mutex_islocked (lock)
+
+/* The kernel notifies a process which uses CLONE_CLEARTID via futex
+ wakeup when the clone terminates. The memory location contains the
+ thread ID while the clone is running and is reset to zero
+ afterwards. */
+#define lll_wait_tid(tid) \
+ do { \
+ __typeof (tid) __tid; \
+ while ((__tid = (tid)) != 0) \
+ lll_futex_wait (&(tid), __tid); \
+ } while (0)
+
+extern int __lll_timedwait_tid (int *, const struct timespec *)
+ attribute_hidden;
+
+#define lll_timedwait_tid(tid, abstime) \
+ ({ \
+ int __res = 0; \
+ if ((tid) != 0) \
+ __res = __lll_timedwait_tid (&(tid), (abstime)); \
+ __res; \
+ })
+
+
+/* Conditional variable handling. */
+
+extern void __lll_cond_wait (pthread_cond_t *cond)
+ attribute_hidden;
+extern int __lll_cond_timedwait (pthread_cond_t *cond,
+ const struct timespec *abstime)
+ attribute_hidden;
+extern void __lll_cond_wake (pthread_cond_t *cond)
+ attribute_hidden;
+extern void __lll_cond_broadcast (pthread_cond_t *cond)
+ attribute_hidden;
+
+#define lll_cond_wait(cond) \
+ __lll_cond_wait (cond)
+#define lll_cond_timedwait(cond, abstime) \
+ __lll_cond_timedwait (cond, abstime)
+#define lll_cond_wake(cond) \
+ __lll_cond_wake (cond)
+#define lll_cond_broadcast(cond) \
+ __lll_cond_broadcast (cond)
+
+#endif /* lowlevellock.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/alpha/pt-vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/alpha/pt-vfork.S
new file mode 100644
index 000000000..ec5d175be
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/alpha/pt-vfork.S
@@ -0,0 +1,43 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#include <tcb-offsets.h>
+
+#undef PSEUDO_PREPARE_ARGS
+#define PSEUDO_PREPARE_ARGS \
+ /* Load the current cached pid value across the vfork. */ \
+ rduniq; \
+ ldl a2, PID_OFFSET(v0); \
+ mov v0, a1; \
+ /* Write back its negation, to indicate that the pid value is \
+ uninitialized in the the child, and in the window between \
+ here and the point at which we restore the value. */ \
+ negl a2, t0; \
+ stl t0, PID_OFFSET(v0);
+
+PSEUDO (__vfork, vfork, 0)
+
+ /* If we're back in the parent, restore the saved pid. */
+ beq v0, 1f
+ stl a2, PID_OFFSET(a1)
+1: ret
+
+PSEUDO_END (__vfork)
+
+weak_alias (__vfork, vfork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/alpha/pthread_once.c b/libc/nptl/sysdeps/unix/sysv/linux/alpha/pthread_once.c
new file mode 100644
index 000000000..79a3c47ae
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/alpha/pthread_once.c
@@ -0,0 +1,96 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 "pthreadP.h"
+#include <lowlevellock.h>
+
+
+unsigned long int __fork_generation attribute_hidden;
+
+static void
+clear_once_control (void *arg)
+{
+ pthread_once_t *once_control = (pthread_once_t *) arg;
+
+ *once_control = 0;
+ lll_futex_wake (once_control, INT_MAX);
+}
+
+int
+__pthread_once (pthread_once_t *once_control, void (*init_routine) (void))
+{
+ for (;;)
+ {
+ int oldval;
+ int newval;
+ int tmp;
+
+ /* Pseudo code:
+ newval = __fork_generation | 1;
+ oldval = *once_control;
+ if ((oldval & 2) == 0)
+ *once_control = newval;
+ Do this atomically.
+ */
+ newval = __fork_generation | 1;
+ __asm __volatile (
+ "1: ldl_l %0, %2\n"
+ " and %0, 2, %1\n"
+ " bne %1, 2f\n"
+ " mov %3, %1\n"
+ " stl_c %1, %2\n"
+ " beq %1, 1b\n"
+ "2: mb"
+ : "=&r" (oldval), "=&r" (tmp), "=m" (*once_control)
+ : "r" (newval), "m" (*once_control));
+
+ /* Check if the initializer has already been done. */
+ if ((oldval & 2) != 0)
+ return 0;
+
+ /* Check if another thread already runs the initializer. */
+ if ((oldval & 1) == 0)
+ break;
+
+ /* Check whether the initializer execution was interrupted by a fork. */
+ if (oldval != newval)
+ break;
+
+ /* Same generation, some other thread was faster. Wait. */
+ lll_futex_wait (once_control, oldval);
+ }
+
+ /* This thread is the first here. Do the initialization.
+ Register a cleanup handler so that in case the thread gets
+ interrupted the initialization can be restarted. */
+ pthread_cleanup_push (clear_once_control, once_control);
+
+ init_routine ();
+
+ pthread_cleanup_pop (0);
+
+ /* Add one to *once_control to take the bottom 2 bits from 01 to 10. */
+ atomic_increment (once_control);
+
+ /* Wake up all other threads. */
+ lll_futex_wake (once_control, INT_MAX);
+
+ return 0;
+}
+weak_alias (__pthread_once, pthread_once)
+strong_alias (__pthread_once, __pthread_once_internal)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/alpha/sem_post.c b/libc/nptl/sysdeps/unix/sysv/linux/alpha/sem_post.c
new file mode 100644
index 000000000..27fd817e6
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/alpha/sem_post.c
@@ -0,0 +1,5 @@
+/* ??? This is an ass-backwards way to do this. We should simply define
+ the acquire/release semantics of atomic_exchange_and_add. And even if
+ we don't do this, we should be using atomic_full_barrier or otherwise. */
+#define __lll_rel_instr "mb"
+#include "../sem_post.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h b/libc/nptl/sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h
new file mode 100644
index 000000000..f3f7718e3
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h
@@ -0,0 +1,169 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#include <tls.h>
+#ifndef __ASSEMBLER__
+# include <nptl/pthreadP.h>
+#endif
+
+#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
+
+# ifdef PROF
+# define PSEUDO_PROF \
+ .set noat; \
+ lda AT, _mcount; \
+ jsr AT, (AT), _mcount; \
+ .set at
+# else
+# define PSEUDO_PROF
+# endif
+
+/* ??? Assumes that nothing comes between PSEUDO and PSEUDO_END
+ besides "ret". */
+
+# undef PSEUDO
+# define PSEUDO(name, syscall_name, args) \
+ .globl name; \
+ .align 4; \
+ .type name, @function; \
+ .usepv name, std; \
+ cfi_startproc; \
+__LABEL(name) \
+ ldgp gp, 0(pv); \
+ PSEUDO_PROF; \
+ PSEUDO_PREPARE_ARGS \
+ SINGLE_THREAD_P(t0); \
+ bne t0, $pseudo_cancel; \
+ lda v0, SYS_ify(syscall_name); \
+ call_pal PAL_callsys; \
+ bne a3, SYSCALL_ERROR_LABEL; \
+__LABEL($pseudo_ret) \
+ .subsection 2; \
+__LABEL($pseudo_cancel) \
+ subq sp, 64, sp; \
+ cfi_def_cfa_offset(64); \
+ stq ra, 0(sp); \
+ cfi_offset(ra, -64); \
+ SAVE_ARGS_##args; \
+ CENABLE; \
+ LOAD_ARGS_##args; \
+ /* Save the CENABLE return value in RA. That register \
+ is preserved across syscall and the real return \
+ address is saved on the stack. */ \
+ mov v0, ra; \
+ lda v0, SYS_ify(syscall_name); \
+ call_pal PAL_callsys; \
+ stq v0, 8(sp); \
+ mov ra, a0; \
+ bne a3, $multi_error; \
+ CDISABLE; \
+ ldq ra, 0(sp); \
+ ldq v0, 8(sp); \
+ addq sp, 64, sp; \
+ cfi_remember_state; \
+ cfi_restore(ra); \
+ cfi_def_cfa_offset(0); \
+ ret; \
+ cfi_restore_state; \
+__LABEL($multi_error) \
+ CDISABLE; \
+ ldq ra, 0(sp); \
+ ldq v0, 8(sp); \
+ addq sp, 64, sp; \
+ cfi_restore(ra); \
+ cfi_def_cfa_offset(0); \
+__LABEL($syscall_error) \
+ SYSCALL_ERROR_HANDLER; \
+ .previous
+
+# undef PSEUDO_END
+# define PSEUDO_END(sym) \
+ .subsection 2; \
+ cfi_endproc; \
+ .size sym, .-sym
+
+# define SAVE_ARGS_0 /* Nothing. */
+# define SAVE_ARGS_1 SAVE_ARGS_0; stq a0, 8(sp)
+# define SAVE_ARGS_2 SAVE_ARGS_1; stq a1, 16(sp)
+# define SAVE_ARGS_3 SAVE_ARGS_2; stq a2, 24(sp)
+# define SAVE_ARGS_4 SAVE_ARGS_3; stq a3, 32(sp)
+# define SAVE_ARGS_5 SAVE_ARGS_4; stq a4, 40(sp)
+# define SAVE_ARGS_6 SAVE_ARGS_5; stq a5, 48(sp)
+
+# define LOAD_ARGS_0 /* Nothing. */
+# define LOAD_ARGS_1 LOAD_ARGS_0; ldq a0, 8(sp)
+# define LOAD_ARGS_2 LOAD_ARGS_1; ldq a1, 16(sp)
+# define LOAD_ARGS_3 LOAD_ARGS_2; ldq a2, 24(sp)
+# define LOAD_ARGS_4 LOAD_ARGS_3; ldq a3, 32(sp)
+# define LOAD_ARGS_5 LOAD_ARGS_4; ldq a4, 40(sp)
+# define LOAD_ARGS_6 LOAD_ARGS_5; ldq a5, 48(sp)
+
+# ifdef IS_IN_libpthread
+# define __local_enable_asynccancel __pthread_enable_asynccancel
+# define __local_disable_asynccancel __pthread_disable_asynccancel
+# define __local_multiple_threads __pthread_multiple_threads
+# elif !defined NOT_IN_libc
+# define __local_enable_asynccancel __libc_enable_asynccancel
+# define __local_disable_asynccancel __libc_disable_asynccancel
+# define __local_multiple_threads __libc_multiple_threads
+# elif defined IS_IN_librt
+# define __local_enable_asynccancel __librt_enable_asynccancel
+# define __local_disable_asynccancel __librt_disable_asynccancel
+# else
+# error Unsupported library
+# endif
+
+# ifdef PIC
+# define CENABLE bsr ra, __local_enable_asynccancel !samegp
+# define CDISABLE bsr ra, __local_disable_asynccancel !samegp
+# else
+# define CENABLE jsr ra, __local_enable_asynccancel; ldgp ra, 0(gp)
+# define CDISABLE jsr ra, __local_disable_asynccancel; ldgp ra, 0(gp)
+# endif
+
+# 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)
+# elif defined(PIC)
+# define SINGLE_THREAD_P(reg) ldl reg, __local_multiple_threads(gp) !gprel
+# else
+# define SINGLE_THREAD_P(reg) \
+ ldah reg, __local_multiple_threads(gp) !gprelhigh; \
+ ldl reg, __local_multiple_threads(reg) !gprellow
+# endif
+# else
+# ifndef __ASSEMBLER__
+# define SINGLE_THREAD_P \
+ __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+ header.multiple_threads) == 0, 1)
+# else
+# define SINGLE_THREAD_P(reg) \
+ call_pal PAL_rduniq; \
+ ldl reg, MULTIPLE_THREADS_OFFSET($0)
+# endif
+# endif
+
+#else
+
+# define SINGLE_THREAD_P (1)
+# define NO_CANCELLATION 1
+
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/alpha/timer_create.c b/libc/nptl/sysdeps/unix/sysv/linux/alpha/timer_create.c
new file mode 100644
index 000000000..172223af3
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/alpha/timer_create.c
@@ -0,0 +1 @@
+#include "../x86_64/timer_create.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/alpha/timer_delete.c b/libc/nptl/sysdeps/unix/sysv/linux/alpha/timer_delete.c
new file mode 100644
index 000000000..537516e0a
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/alpha/timer_delete.c
@@ -0,0 +1 @@
+#include "../x86_64/timer_delete.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/alpha/timer_getoverr.c b/libc/nptl/sysdeps/unix/sysv/linux/alpha/timer_getoverr.c
new file mode 100644
index 000000000..3f21a73c9
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/alpha/timer_getoverr.c
@@ -0,0 +1 @@
+#include "../x86_64/timer_getoverr.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/alpha/timer_gettime.c b/libc/nptl/sysdeps/unix/sysv/linux/alpha/timer_gettime.c
new file mode 100644
index 000000000..a50143adc
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/alpha/timer_gettime.c
@@ -0,0 +1 @@
+#include "../x86_64/timer_gettime.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/alpha/timer_settime.c b/libc/nptl/sysdeps/unix/sysv/linux/alpha/timer_settime.c
new file mode 100644
index 000000000..37baeffac
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/alpha/timer_settime.c
@@ -0,0 +1 @@
+#include "../x86_64/timer_settime.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/alpha/vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/alpha/vfork.S
new file mode 100644
index 000000000..f4ed9311b
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/alpha/vfork.S
@@ -0,0 +1,46 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#include <tcb-offsets.h>
+
+#undef PSEUDO_PREPARE_ARGS
+#define PSEUDO_PREPARE_ARGS \
+ /* Load the current cached pid value across the vfork. */ \
+ rduniq; \
+ ldl a2, PID_OFFSET(v0); \
+ mov v0, a1; \
+ /* If the cached value is initialized (nonzero), then write \
+ back its negation, or INT_MIN, to indicate that the pid \
+ value is uninitialized in the the child, and in the window \
+ between here and the point at which we restore the value. */ \
+ ldah t0, -0x8000; \
+ negl a2, t1; \
+ cmovne a2, t1, t0; \
+ stl t0, PID_OFFSET(v0);
+
+PSEUDO (__vfork, vfork, 0)
+
+ /* If we're back in the parent, restore the saved pid. */
+ beq v0, 1f
+ stl a2, PID_OFFSET(a1)
+1: ret
+
+PSEUDO_END (__vfork)
+libc_hidden_def (__vfork)
+weak_alias (__vfork, vfork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/bits/local_lim.h b/libc/nptl/sysdeps/unix/sysv/linux/bits/local_lim.h
new file mode 100644
index 000000000..b639ba44a
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/bits/local_lim.h
@@ -0,0 +1,89 @@
+/* Minimum guaranteed maximum values for system limits. Linux version.
+ Copyright (C) 1993-1998,2000,2002,2003,2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* The kernel header pollutes the namespace with the NR_OPEN symbol
+ and defines LINK_MAX although filesystems have different maxima. A
+ similar thing is true for OPEN_MAX: the limit can be changed at
+ runtime and therefore the macro must not be defined. Remove this
+ after including the header if necessary. */
+#ifndef NR_OPEN
+# define __undef_NR_OPEN
+#endif
+#ifndef LINK_MAX
+# define __undef_LINK_MAX
+#endif
+#ifndef OPEN_MAX
+# define __undef_OPEN_MAX
+#endif
+
+/* The kernel sources contain a file with all the needed information. */
+#include <linux/limits.h>
+
+/* Have to remove NR_OPEN? */
+#ifdef __undef_NR_OPEN
+# undef NR_OPEN
+# undef __undef_NR_OPEN
+#endif
+/* Have to remove LINK_MAX? */
+#ifdef __undef_LINK_MAX
+# undef LINK_MAX
+# undef __undef_LINK_MAX
+#endif
+/* Have to remove OPEN_MAX? */
+#ifdef __undef_OPEN_MAX
+# undef OPEN_MAX
+# undef __undef_OPEN_MAX
+#endif
+
+/* The number of data keys per process. */
+#define _POSIX_THREAD_KEYS_MAX 128
+/* This is the value this implementation supports. */
+#define PTHREAD_KEYS_MAX 1024
+
+/* Controlling the iterations of destructors for thread-specific data. */
+#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
+/* Number of iterations this implementation does. */
+#define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS
+
+/* The number of threads per process. */
+#define _POSIX_THREAD_THREADS_MAX 64
+/* We have no predefined limit on the number of threads. */
+#undef PTHREAD_THREADS_MAX
+
+/* Maximum amount by which a process can descrease its asynchronous I/O
+ priority level. */
+#define AIO_PRIO_DELTA_MAX 20
+
+/* Minimum size for a thread. We are free to choose a reasonable value. */
+#define PTHREAD_STACK_MIN 16384
+
+/* Maximum number of timer expiration overruns. */
+#define DELAYTIMER_MAX 2147483647
+
+/* Maximum tty name length. */
+#define TTY_NAME_MAX 32
+
+/* Maximum login name length. This is arbitrary. */
+#define LOGIN_NAME_MAX 256
+
+/* Maximum host name length. */
+#define HOST_NAME_MAX 64
+
+/* Maximum message queue priority level. */
+#define MQ_PRIO_MAX 32768
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/bits/posix_opt.h b/libc/nptl/sysdeps/unix/sysv/linux/bits/posix_opt.h
new file mode 100644
index 000000000..40160c54d
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/bits/posix_opt.h
@@ -0,0 +1,181 @@
+/* Define POSIX options for Linux.
+ Copyright (C) 1996-2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _POSIX_OPT_H
+#define _POSIX_OPT_H 1
+
+/* Job control is supported. */
+#define _POSIX_JOB_CONTROL 1
+
+/* Processes have a saved set-user-ID and a saved set-group-ID. */
+#define _POSIX_SAVED_IDS 1
+
+/* Priority scheduling is supported. */
+#define _POSIX_PRIORITY_SCHEDULING 200112L
+
+/* Synchronizing file data is supported. */
+#define _POSIX_SYNCHRONIZED_IO 200112L
+
+/* The fsync function is present. */
+#define _POSIX_FSYNC 200112L
+
+/* Mapping of files to memory is supported. */
+#define _POSIX_MAPPED_FILES 200112L
+
+/* Locking of all memory is supported. */
+#define _POSIX_MEMLOCK 200112L
+
+/* Locking of ranges of memory is supported. */
+#define _POSIX_MEMLOCK_RANGE 200112L
+
+/* Setting of memory protections is supported. */
+#define _POSIX_MEMORY_PROTECTION 200112L
+
+/* Only root can change owner of file. */
+#define _POSIX_CHOWN_RESTRICTED 1
+
+/* `c_cc' member of 'struct termios' structure can be disabled by
+ using the value _POSIX_VDISABLE. */
+#define _POSIX_VDISABLE '\0'
+
+/* Filenames are not silently truncated. */
+#define _POSIX_NO_TRUNC 1
+
+/* X/Open realtime support is available. */
+#define _XOPEN_REALTIME 1
+
+/* XPG4.2 shared memory is supported. */
+#define _XOPEN_SHM 1
+
+/* Tell we have POSIX threads. */
+#define _POSIX_THREADS 200112L
+
+/* We have the reentrant functions described in POSIX. */
+#define _POSIX_REENTRANT_FUNCTIONS 1
+#define _POSIX_THREAD_SAFE_FUNCTIONS 200112L
+
+/* We provide priority scheduling for threads. */
+#define _POSIX_THREAD_PRIORITY_SCHEDULING 200112L
+
+/* We support user-defined stack sizes. */
+#define _POSIX_THREAD_ATTR_STACKSIZE 200112L
+
+/* We support user-defined stacks. */
+#define _POSIX_THREAD_ATTR_STACKADDR 200112L
+
+/* We support priority inheritence. */
+#define _POSIX_THREAD_PRIO_INHERIT 200112L
+
+/* We support priority protection, though only for non-robust
+ mutexes. */
+#define _POSIX_THREAD_PRIO_PROTECT 200112L
+
+/* We support POSIX.1b semaphores. */
+#define _POSIX_SEMAPHORES 200112L
+
+/* Real-time signals are supported. */
+#define _POSIX_REALTIME_SIGNALS 200112L
+
+/* We support asynchronous I/O. */
+#define _POSIX_ASYNCHRONOUS_IO 200112L
+#define _POSIX_ASYNC_IO 1
+/* Alternative name for Unix98. */
+#define _LFS_ASYNCHRONOUS_IO 1
+/* Support for prioritization is also available. */
+#define _POSIX_PRIORITIZED_IO 200112L
+
+/* The LFS support in asynchronous I/O is also available. */
+#define _LFS64_ASYNCHRONOUS_IO 1
+
+/* The rest of the LFS is also available. */
+#define _LFS_LARGEFILE 1
+#define _LFS64_LARGEFILE 1
+#define _LFS64_STDIO 1
+
+/* POSIX shared memory objects are implemented. */
+#define _POSIX_SHARED_MEMORY_OBJECTS 200112L
+
+/* CPU-time clocks support needs to be checked at runtime. */
+#define _POSIX_CPUTIME 0
+
+/* Clock support in threads must be also checked at runtime. */
+#define _POSIX_THREAD_CPUTIME 0
+
+/* GNU libc provides regular expression handling. */
+#define _POSIX_REGEXP 1
+
+/* Reader/Writer locks are available. */
+#define _POSIX_READER_WRITER_LOCKS 200112L
+
+/* We have a POSIX shell. */
+#define _POSIX_SHELL 1
+
+/* We support the Timeouts option. */
+#define _POSIX_TIMEOUTS 200112L
+
+/* We support spinlocks. */
+#define _POSIX_SPIN_LOCKS 200112L
+
+/* The `spawn' function family is supported. */
+#define _POSIX_SPAWN 200112L
+
+/* We have POSIX timers. */
+#define _POSIX_TIMERS 200112L
+
+/* The barrier functions are available. */
+#define _POSIX_BARRIERS 200112L
+
+/* POSIX message queues are available. */
+#define _POSIX_MESSAGE_PASSING 200112L
+
+/* Thread process-shared synchronization is supported. */
+#define _POSIX_THREAD_PROCESS_SHARED 200112L
+
+/* The monotonic clock might be available. */
+#define _POSIX_MONOTONIC_CLOCK 0
+
+/* The clock selection interfaces are available. */
+#define _POSIX_CLOCK_SELECTION 200112L
+
+/* Advisory information interfaces are available. */
+#define _POSIX_ADVISORY_INFO 200112L
+
+/* IPv6 support is available. */
+#define _POSIX_IPV6 200112L
+
+/* Raw socket support is available. */
+#define _POSIX_RAW_SOCKETS 200112L
+
+/* We have at least one terminal. */
+#define _POSIX2_CHAR_TERM 200112L
+
+/* Neither process nor thread sporadic server interfaces is available. */
+#define _POSIX_SPORADIC_SERVER -1
+#define _POSIX_THREAD_SPORADIC_SERVER -1
+
+/* trace.h is not available. */
+#define _POSIX_TRACE -1
+#define _POSIX_TRACE_EVENT_FILTER -1
+#define _POSIX_TRACE_INHERIT -1
+#define _POSIX_TRACE_LOG -1
+
+/* Typed memory objects are not available. */
+#define _POSIX_TYPED_MEMORY_OBJECTS -1
+
+#endif /* posix_opt.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/createthread.c b/libc/nptl/sysdeps/unix/sysv/linux/createthread.c
new file mode 100644
index 000000000..9defac619
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/createthread.c
@@ -0,0 +1,24 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>.
+
+ 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. */
+
+/* Value passed to 'clone' for initialization of the thread register. */
+#define TLS_VALUE pd
+
+/* Get the real implementation. */
+#include <nptl/sysdeps/pthread/createthread.c>
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/fork.c b/libc/nptl/sysdeps/unix/sysv/linux/fork.c
new file mode 100644
index 000000000..840974401
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/fork.c
@@ -0,0 +1,213 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <assert.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sysdep.h>
+#include <libio/libioP.h>
+#include <tls.h>
+#include "fork.h"
+#include <hp-timing.h>
+#include <ldsodefs.h>
+#include <bits/stdio-lock.h>
+#include <atomic.h>
+
+
+unsigned long int *__fork_generation_pointer;
+
+
+
+/* The single linked list of all currently registered for handlers. */
+struct fork_handler *__fork_handlers;
+
+
+static void
+fresetlockfiles (void)
+{
+ _IO_ITER i;
+
+ for (i = _IO_iter_begin(); i != _IO_iter_end(); i = _IO_iter_next(i))
+ _IO_lock_init (*((_IO_lock_t *) _IO_iter_file(i)->_lock));
+}
+
+
+pid_t
+__libc_fork (void)
+{
+ pid_t pid;
+ struct used_handler
+ {
+ struct fork_handler *handler;
+ struct used_handler *next;
+ } *allp = NULL;
+
+ /* Run all the registered preparation handlers. In reverse order.
+ While doing this we build up a list of all the entries. */
+ struct fork_handler *runp;
+ while ((runp = __fork_handlers) != NULL)
+ {
+ unsigned int oldval = runp->refcntr;
+
+ if (oldval == 0)
+ /* This means some other thread removed the list just after
+ the pointer has been loaded. Try again. Either the list
+ is empty or we can retry it. */
+ continue;
+
+ /* Bump the reference counter. */
+ if (atomic_compare_and_exchange_bool_acq (&__fork_handlers->refcntr,
+ oldval + 1, oldval))
+ /* The value changed, try again. */
+ continue;
+
+ /* We bumped the reference counter for the first entry in the
+ list. That means that none of the following entries will
+ just go away. The unloading code works in the order of the
+ list.
+
+ While executing the registered handlers we are building a
+ list of all the entries so that we can go backward later on. */
+ while (1)
+ {
+ /* Execute the handler if there is one. */
+ if (runp->prepare_handler != NULL)
+ runp->prepare_handler ();
+
+ /* Create a new element for the list. */
+ struct used_handler *newp
+ = (struct used_handler *) alloca (sizeof (*newp));
+ newp->handler = runp;
+ newp->next = allp;
+ allp = newp;
+
+ /* Advance to the next handler. */
+ runp = runp->next;
+ if (runp == NULL)
+ break;
+
+ /* Bump the reference counter for the next entry. */
+ atomic_increment (&runp->refcntr);
+ }
+
+ /* We are done. */
+ break;
+ }
+
+ _IO_list_lock ();
+
+#ifndef NDEBUG
+ pid_t ppid = THREAD_GETMEM (THREAD_SELF, tid);
+#endif
+
+ /* We need to prevent the getpid() code to update the PID field so
+ that, if a signal arrives in the child very early and the signal
+ handler uses getpid(), the value returned is correct. */
+ pid_t parentpid = THREAD_GETMEM (THREAD_SELF, pid);
+ THREAD_SETMEM (THREAD_SELF, pid, -parentpid);
+
+#ifdef ARCH_FORK
+ pid = ARCH_FORK ();
+#else
+# error "ARCH_FORK must be defined so that the CLONE_SETTID flag is used"
+ pid = INLINE_SYSCALL (fork, 0);
+#endif
+
+
+ if (pid == 0)
+ {
+ struct pthread *self = THREAD_SELF;
+
+ assert (THREAD_GETMEM (self, tid) != ppid);
+
+ if (__fork_generation_pointer != NULL)
+ *__fork_generation_pointer += 4;
+
+ /* Adjust the PID field for the new process. */
+ THREAD_SETMEM (self, pid, THREAD_GETMEM (self, tid));
+
+#if HP_TIMING_AVAIL
+ /* The CPU clock of the thread and process have to be set to zero. */
+ hp_timing_t now;
+ HP_TIMING_NOW (now);
+ THREAD_SETMEM (self, cpuclock_offset, now);
+ GL(dl_cpuclock_offset) = now;
+#endif
+
+ /* Reset the file list. These are recursive mutexes. */
+ fresetlockfiles ();
+
+ /* Reset locks in the I/O code. */
+ _IO_list_resetlock ();
+
+ /* Reset the lock the dynamic loader uses to protect its data. */
+ __rtld_lock_initialize (GL(dl_load_lock));
+
+ /* Run the handlers registered for the child. */
+ while (allp != NULL)
+ {
+ if (allp->handler->child_handler != NULL)
+ allp->handler->child_handler ();
+
+ /* Note that we do not have to wake any possible waiter.
+ This is the only thread in the new process. */
+ --allp->handler->refcntr;
+
+ /* XXX We could at this point look through the object pool
+ and mark all objects not on the __fork_handlers list as
+ unused. This is necessary in case the fork() happened
+ while another thread called dlclose() and that call had
+ to create a new list. */
+
+ allp = allp->next;
+ }
+
+ /* Initialize the fork lock. */
+ __fork_lock = (lll_lock_t) LLL_LOCK_INITIALIZER;
+ }
+ else
+ {
+ assert (THREAD_GETMEM (THREAD_SELF, tid) == ppid);
+
+ /* Restore the PID value. */
+ THREAD_SETMEM (THREAD_SELF, pid, parentpid);
+
+ /* We execute this even if the 'fork' call failed. */
+ _IO_list_unlock ();
+
+ /* Run the handlers registered for the parent. */
+ while (allp != NULL)
+ {
+ if (allp->handler->parent_handler != NULL)
+ allp->handler->parent_handler ();
+
+ if (atomic_decrement_and_test (&allp->handler->refcntr)
+ && allp->handler->need_signal)
+ lll_futex_wake (allp->handler->refcntr, 1);
+
+ allp = allp->next;
+ }
+ }
+
+ return pid;
+}
+weak_alias (__libc_fork, __fork)
+libc_hidden_def (__fork)
+weak_alias (__libc_fork, fork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/fork.h b/libc/nptl/sysdeps/unix/sysv/linux/fork.h
new file mode 100644
index 000000000..6458977b9
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/fork.h
@@ -0,0 +1,57 @@
+/* Copyright (C) 2002, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <lowlevellock.h>
+
+/* The fork generation counter, defined in libpthread. */
+extern unsigned long int __fork_generation attribute_hidden;
+
+/* Pointer to the fork generation counter in the thread library. */
+extern unsigned long int *__fork_generation_pointer attribute_hidden;
+
+/* Lock to protect allocation and deallocation of fork handlers. */
+extern lll_lock_t __fork_lock attribute_hidden;
+
+/* Elements of the fork handler lists. */
+struct fork_handler
+{
+ struct fork_handler *next;
+ void (*prepare_handler) (void);
+ void (*parent_handler) (void);
+ void (*child_handler) (void);
+ void *dso_handle;
+ unsigned int refcntr;
+ int need_signal;
+};
+
+/* The single linked list of all currently registered for handlers. */
+extern struct fork_handler *__fork_handlers attribute_hidden;
+
+
+/* Function to call to unregister fork handlers. */
+extern void __unregister_atfork (void *dso_handle) attribute_hidden;
+#define UNREGISTER_ATFORK(dso_handle) __unregister_atfork (dso_handle)
+
+
+/* C library side function to register new fork handlers. */
+extern int __register_atfork (void (*__prepare) (void),
+ void (*__parent) (void),
+ void (*__child) (void),
+ void *dso_handle);
+libc_hidden_proto (__register_atfork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/getpid.c b/libc/nptl/sysdeps/unix/sysv/linux/getpid.c
new file mode 100644
index 000000000..98307ff21
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/getpid.c
@@ -0,0 +1,65 @@
+/* Copyright (C) 2003, 2004 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 <unistd.h>
+#include <tls.h>
+#include <sysdep.h>
+
+
+#ifndef NOT_IN_libc
+static inline __attribute__((always_inline)) pid_t really_getpid (pid_t oldval);
+
+static inline __attribute__((always_inline)) pid_t
+really_getpid (pid_t oldval)
+{
+ if (__builtin_expect (oldval == 0, 1))
+ {
+ pid_t selftid = THREAD_GETMEM (THREAD_SELF, tid);
+ if (__builtin_expect (selftid != 0, 1))
+ return selftid;
+ }
+
+ INTERNAL_SYSCALL_DECL (err);
+ pid_t result = INTERNAL_SYSCALL (getpid, err, 0);
+
+ /* We do not set the PID field in the TID here since we might be
+ called from a signal handler while the thread executes fork. */
+ if (oldval == 0)
+ THREAD_SETMEM (THREAD_SELF, tid, result);
+ return result;
+}
+#endif
+
+pid_t
+__getpid (void)
+{
+#ifdef NOT_IN_libc
+ INTERNAL_SYSCALL_DECL (err);
+ pid_t result = INTERNAL_SYSCALL (getpid, err, 0);
+#else
+ pid_t result = THREAD_GETMEM (THREAD_SELF, pid);
+ if (__builtin_expect (result <= 0, 0))
+ result = really_getpid (result);
+#endif
+ return result;
+}
+
+libc_hidden_def (__getpid)
+weak_alias (__getpid, getpid)
+libc_hidden_def (getpid)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h b/libc/nptl/sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h
new file mode 100644
index 000000000..f53d0e5a7
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/bits/pthreadtypes.h
@@ -0,0 +1,170 @@
+/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+#ifndef _BITS_PTHREADTYPES_H
+#define _BITS_PTHREADTYPES_H 1
+
+#define __SIZEOF_PTHREAD_ATTR_T 36
+#define __SIZEOF_PTHREAD_MUTEX_T 24
+#define __SIZEOF_PTHREAD_MUTEXATTR_T 4
+#define __SIZEOF_PTHREAD_COND_T 48
+#define __SIZEOF_PTHREAD_COND_COMPAT_T 12
+#define __SIZEOF_PTHREAD_CONDATTR_T 4
+#define __SIZEOF_PTHREAD_RWLOCK_T 32
+#define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
+#define __SIZEOF_PTHREAD_BARRIER_T 20
+#define __SIZEOF_PTHREAD_BARRIERATTR_T 4
+
+
+/* Thread identifiers. The structure of the attribute type is not
+ exposed on purpose. */
+typedef unsigned long int pthread_t;
+
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_ATTR_T];
+ long int __align;
+} pthread_attr_t;
+
+
+typedef struct __pthread_internal_slist
+{
+ struct __pthread_internal_slist *__next;
+} __pthread_slist_t;
+
+
+/* Data structures for mutex handling. The structure of the attribute
+ type is not exposed on purpose. */
+typedef union
+{
+ struct __pthread_mutex_s
+ {
+ int __lock;
+ unsigned int __count;
+ int __owner;
+ /* KIND must stay at this position in the structure to maintain
+ binary compatibility. */
+ int __kind;
+ unsigned int __nusers;
+ __extension__ union
+ {
+ int __spins;
+ __pthread_slist_t __list;
+ };
+ } __data;
+ char __size[__SIZEOF_PTHREAD_MUTEX_T];
+ long int __align;
+} pthread_mutex_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_MUTEXATTR_T];
+ long int __align;
+} pthread_mutexattr_t;
+
+
+/* Data structure for conditional variable handling. The structure of
+ the attribute type is not exposed on purpose. */
+typedef union
+{
+ struct
+ {
+ int __lock;
+ unsigned int __futex;
+ __extension__ unsigned long long int __total_seq;
+ __extension__ unsigned long long int __wakeup_seq;
+ __extension__ unsigned long long int __woken_seq;
+ void *__mutex;
+ unsigned int __nwaiters;
+ unsigned int __broadcast_seq;
+ } __data;
+ char __size[__SIZEOF_PTHREAD_COND_T];
+ __extension__ long long int __align;
+} pthread_cond_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_CONDATTR_T];
+ long int __align;
+} pthread_condattr_t;
+
+
+/* Keys for thread-specific data */
+typedef unsigned int pthread_key_t;
+
+
+/* Once-only execution */
+typedef int pthread_once_t;
+
+
+#if defined __USE_UNIX98 || defined __USE_XOPEN2K
+/* Data structure for read-write lock variable handling. The
+ structure of the attribute type is not exposed on purpose. */
+typedef union
+{
+ struct
+ {
+ int __lock;
+ unsigned int __nr_readers;
+ unsigned int __readers_wakeup;
+ unsigned int __writer_wakeup;
+ unsigned int __nr_readers_queued;
+ unsigned int __nr_writers_queued;
+ /* FLAGS must stay at this position in the structure to maintain
+ binary compatibility. */
+ unsigned int __flags;
+ int __writer;
+ } __data;
+ char __size[__SIZEOF_PTHREAD_RWLOCK_T];
+ long int __align;
+} pthread_rwlock_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_RWLOCKATTR_T];
+ long int __align;
+} pthread_rwlockattr_t;
+#endif
+
+
+#ifdef __USE_XOPEN2K
+/* POSIX spinlock data type. */
+typedef volatile int pthread_spinlock_t;
+
+
+/* POSIX barriers data type. The structure of the type is
+ deliberately not exposed. */
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_BARRIER_T];
+ long int __align;
+} pthread_barrier_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_BARRIERATTR_T];
+ int __align;
+} pthread_barrierattr_t;
+#endif
+
+
+/* Extra attributes for the cleanup functions. */
+#define __cleanup_fct_attribute __attribute__ ((__regparm__ (1)))
+
+#endif /* bits/pthreadtypes.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/bits/semaphore.h b/libc/nptl/sysdeps/unix/sysv/linux/i386/bits/semaphore.h
new file mode 100644
index 000000000..e6c5d845c
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/bits/semaphore.h
@@ -0,0 +1,39 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+#ifndef _SEMAPHORE_H
+# error "Never use <bits/semaphore.h> directly; include <semaphore.h> instead."
+#endif
+
+
+#define __SIZEOF_SEM_T 16
+
+
+/* Value returned if `sem_open' failed. */
+#define SEM_FAILED ((sem_t *) 0)
+
+/* Maximum value the semaphore can have. */
+#define SEM_VALUE_MAX (2147483647)
+
+
+typedef union
+{
+ char __size[__SIZEOF_SEM_T];
+ long int __align;
+} sem_t;
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/clone.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/clone.S
new file mode 100644
index 000000000..675a997e9
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/clone.S
@@ -0,0 +1,9 @@
+/* We want an #include_next, but we are the main source file.
+ So, #include ourselves and in that incarnation we can use #include_next. */
+#ifndef INCLUDED_SELF
+# define INCLUDED_SELF
+# include <clone.S>
+#else
+# define RESET_PID
+# include_next <clone.S>
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/createthread.c b/libc/nptl/sysdeps/unix/sysv/linux/i386/createthread.c
new file mode 100644
index 000000000..37e3d9499
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/createthread.c
@@ -0,0 +1,49 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+/* The "thread register" gets initialized from a segment descriptor.
+ Initialize such a descriptor first. */
+#define PREPARE_CREATE \
+ union user_desc_init desc; \
+ \
+ /* Describe the thread-local storage segment. */ \
+ \
+ /* The 'entry_number' field. The first three bits of the segment \
+ register value select the GDT, ignore them. We get the index \
+ from the value of the %gs register in the current thread. */ \
+ desc.vals[0] = TLS_GET_GS () >> 3; \
+ /* The 'base_addr' field. Pointer to the TCB. */ \
+ desc.vals[1] = (unsigned long int) pd; \
+ /* The 'limit' field. We use 4GB which is 0xfffff pages. */ \
+ desc.vals[2] = 0xfffff; \
+ /* Collapsed value of the bitfield: \
+ .seg_32bit = 1 \
+ .contents = 0 \
+ .read_exec_only = 0 \
+ .limit_in_pages = 1 \
+ .seg_not_present = 0 \
+ .useable = 1 */ \
+ desc.vals[3] = 0x51
+
+/* Value passed to 'clone' for initialization of the thread register. */
+#define TLS_VALUE &desc.desc
+
+
+/* Get the real implementation. */
+#include <nptl/sysdeps/pthread/createthread.c>
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/dl-sysdep.h b/libc/nptl/sysdeps/unix/sysv/linux/i386/dl-sysdep.h
new file mode 100644
index 000000000..109ffd1cf
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/dl-sysdep.h
@@ -0,0 +1,64 @@
+/* System-specific settings for dynamic linker code. IA-32 version.
+ Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+#ifndef _DL_SYSDEP_H
+#define _DL_SYSDEP_H 1
+
+/* This macro must be defined to either 0 or 1.
+
+ If 1, then an errno global variable hidden in ld.so will work right with
+ all the errno-using libc code compiled for ld.so, and there is never a
+ need to share the errno location with libc. This is appropriate only if
+ all the libc functions that ld.so uses are called without PLT and always
+ get the versions linked into ld.so rather than the libc ones. */
+
+#ifdef IS_IN_rtld
+# define RTLD_PRIVATE_ERRNO 1
+#else
+# define RTLD_PRIVATE_ERRNO 0
+#endif
+
+/* Traditionally system calls have been made using int $0x80. A
+ second method was introduced which, if possible, will use the
+ sysenter/syscall instructions. To signal the presence and where to
+ find the code the kernel passes an AT_SYSINFO value in the
+ auxiliary vector to the application.
+ sysenter/syscall is not useful on i386 through i586, but the dynamic
+ linker and dl code in libc.a has to be able to load i686 compiled
+ libraries. */
+#define NEED_DL_SYSINFO 1
+#undef USE_DL_SYSINFO
+
+#if defined NEED_DL_SYSINFO && !defined __ASSEMBLER__
+extern void _dl_sysinfo_int80 (void) attribute_hidden;
+# define DL_SYSINFO_DEFAULT (uintptr_t) _dl_sysinfo_int80
+# define DL_SYSINFO_IMPLEMENTATION \
+ asm (".text\n\t" \
+ ".type _dl_sysinfo_int80,@function\n\t" \
+ ".hidden _dl_sysinfo_int80\n\t" \
+ CFI_STARTPROC "\n" \
+ "_dl_sysinfo_int80:\n\t" \
+ "int $0x80;\n\t" \
+ "ret;\n\t" \
+ CFI_ENDPROC "\n" \
+ ".size _dl_sysinfo_int80,.-_dl_sysinfo_int80\n\t" \
+ ".previous;");
+#endif
+
+#endif /* dl-sysdep.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/fork.c b/libc/nptl/sysdeps/unix/sysv/linux/i386/fork.c
new file mode 100644
index 000000000..813e5299a
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/fork.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sched.h>
+#include <signal.h>
+#include <sysdep.h>
+#include <tls.h>
+
+
+#define ARCH_FORK() \
+ INLINE_SYSCALL (clone, 5, \
+ CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, 0, \
+ NULL, NULL, &THREAD_SELF->tid)
+
+#include "../fork.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S
new file mode 100644
index 000000000..88885b735
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/libc-lowlevellock.S
@@ -0,0 +1,30 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+/* In libc.so we do not unconditionally use the lock prefix. Only if
+ the application is using threads. */
+#ifndef UP
+# define LOCK \
+ cmpl $0, %gs:MULTIPLE_THREADS_OFFSET; \
+ je 0f; \
+ lock; \
+0:
+#endif
+
+#include "lowlevellock.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S
new file mode 100644
index 000000000..ae6ce9453
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S
@@ -0,0 +1,285 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <pthread-errnos.h>
+
+ .text
+
+#ifndef LOCK
+# ifdef UP
+# define LOCK
+# else
+# define LOCK lock
+# endif
+#endif
+
+#define SYS_gettimeofday __NR_gettimeofday
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+
+ .globl __lll_mutex_lock_wait
+ .type __lll_mutex_lock_wait,@function
+ .hidden __lll_mutex_lock_wait
+ .align 16
+__lll_mutex_lock_wait:
+ pushl %edx
+ pushl %ebx
+ pushl %esi
+
+ movl $2, %edx
+ movl %ecx, %ebx
+ xorl %esi, %esi /* No timeout. */
+ xorl %ecx, %ecx /* movl $FUTEX_WAIT, %ecx */
+
+ cmpl %edx, %eax /* NB: %edx == 2 */
+ jne 2f
+
+1: movl $SYS_futex, %eax
+ ENTER_KERNEL
+
+2: movl %edx, %eax
+ xchgl %eax, (%ebx) /* NB: lock is implied */
+
+ testl %eax, %eax
+ jnz 1b
+
+ popl %esi
+ popl %ebx
+ popl %edx
+ ret
+ .size __lll_mutex_lock_wait,.-__lll_mutex_lock_wait
+
+
+#ifdef NOT_IN_libc
+ .globl __lll_mutex_timedlock_wait
+ .type __lll_mutex_timedlock_wait,@function
+ .hidden __lll_mutex_timedlock_wait
+ .align 16
+__lll_mutex_timedlock_wait:
+ /* Check for a valid timeout value. */
+ cmpl $1000000000, 4(%edx)
+ jae 3f
+
+ pushl %edi
+ pushl %esi
+ pushl %ebx
+ pushl %ebp
+
+ /* Stack frame for the timespec and timeval structs. */
+ subl $8, %esp
+
+ movl %ecx, %ebp
+ movl %edx, %edi
+
+1:
+ /* Get current time. */
+ movl %esp, %ebx
+ xorl %ecx, %ecx
+ movl $SYS_gettimeofday, %eax
+ ENTER_KERNEL
+
+ /* Compute relative timeout. */
+ movl 4(%esp), %eax
+ movl $1000, %edx
+ mul %edx /* Milli seconds to nano seconds. */
+ movl (%edi), %ecx
+ movl 4(%edi), %edx
+ subl (%esp), %ecx
+ subl %eax, %edx
+ jns 4f
+ addl $1000000000, %edx
+ subl $1, %ecx
+4: testl %ecx, %ecx
+ js 5f /* Time is already up. */
+
+ /* Store relative timeout. */
+ movl %ecx, (%esp)
+ movl %edx, 4(%esp)
+
+ movl %ebp, %ebx
+
+ movl $1, %eax
+ movl $2, %edx
+ LOCK
+ cmpxchgl %edx, (%ebx)
+
+ testl %eax, %eax
+ je 8f
+
+ /* Futex call. */
+ movl %esp, %esi
+ xorl %ecx, %ecx /* movl $FUTEX_WAIT, %ecx */
+ movl $SYS_futex, %eax
+ ENTER_KERNEL
+ movl %eax, %ecx
+
+8: /* NB: %edx == 2 */
+ xorl %eax, %eax
+ LOCK
+ cmpxchgl %edx, (%ebx)
+
+ jnz 7f
+
+6: addl $8, %esp
+ popl %ebp
+ popl %ebx
+ popl %esi
+ popl %edi
+ ret
+
+ /* Check whether the time expired. */
+7: cmpl $-ETIMEDOUT, %ecx
+ je 5f
+
+ /* Make sure the current holder knows we are going to sleep. */
+ movl %edx, %eax
+ xchgl %eax, (%ebx)
+ testl %eax, %eax
+ jz 6b
+ jmp 1b
+
+3: movl $EINVAL, %eax
+ ret
+
+5: movl $ETIMEDOUT, %eax
+ jmp 6b
+ .size __lll_mutex_timedlock_wait,.-__lll_mutex_timedlock_wait
+#endif
+
+
+#ifdef NOT_IN_libc
+ .globl lll_unlock_wake_cb
+ .type lll_unlock_wake_cb,@function
+ .hidden lll_unlock_wake_cb
+ .align 16
+lll_unlock_wake_cb:
+ pushl %ebx
+ pushl %ecx
+ pushl %edx
+
+ movl 20(%esp), %ebx
+ LOCK
+ subl $1, (%ebx)
+ je 1f
+
+ movl $FUTEX_WAKE, %ecx
+ movl $1, %edx /* Wake one thread. */
+ movl $SYS_futex, %eax
+ movl $0, (%ebx)
+ ENTER_KERNEL
+
+1: popl %edx
+ popl %ecx
+ popl %ebx
+ ret
+ .size lll_unlock_wake_cb,.-lll_unlock_wake_cb
+#endif
+
+
+ .globl __lll_mutex_unlock_wake
+ .type __lll_mutex_unlock_wake,@function
+ .hidden __lll_mutex_unlock_wake
+ .align 16
+__lll_mutex_unlock_wake:
+ pushl %ebx
+ pushl %ecx
+ pushl %edx
+
+ movl %eax, %ebx
+ movl $0, (%eax)
+ movl $FUTEX_WAKE, %ecx
+ movl $1, %edx /* Wake one thread. */
+ movl $SYS_futex, %eax
+ ENTER_KERNEL
+
+ popl %edx
+ popl %ecx
+ popl %ebx
+ ret
+ .size __lll_mutex_unlock_wake,.-__lll_mutex_unlock_wake
+
+
+#ifdef NOT_IN_libc
+ .globl __lll_timedwait_tid
+ .type __lll_timedwait_tid,@function
+ .hidden __lll_timedwait_tid
+ .align 16
+__lll_timedwait_tid:
+ pushl %edi
+ pushl %esi
+ pushl %ebx
+ pushl %ebp
+
+ movl %eax, %ebp
+ movl %edx, %edi
+ subl $8, %esp
+
+ /* Get current time. */
+2: movl %esp, %ebx
+ xorl %ecx, %ecx
+ movl $SYS_gettimeofday, %eax
+ ENTER_KERNEL
+
+ /* Compute relative timeout. */
+ movl 4(%esp), %eax
+ movl $1000, %edx
+ mul %edx /* Milli seconds to nano seconds. */
+ movl (%edi), %ecx
+ movl 4(%edi), %edx
+ subl (%esp), %ecx
+ subl %eax, %edx
+ jns 5f
+ addl $1000000000, %edx
+ subl $1, %ecx
+5: testl %ecx, %ecx
+ js 6f /* Time is already up. */
+
+ movl %ecx, (%esp) /* Store relative timeout. */
+ movl %edx, 4(%esp)
+
+ movl (%ebp), %edx
+ testl %edx, %edx
+ jz 4f
+
+ movl %esp, %esi
+ xorl %ecx, %ecx /* movl $FUTEX_WAIT, %ecx */
+ movl %ebp, %ebx
+ movl $SYS_futex, %eax
+ ENTER_KERNEL
+
+ cmpl $0, (%ebx)
+ jne 1f
+4: xorl %eax, %eax
+
+3: addl $8, %esp
+ popl %ebp
+ popl %ebx
+ popl %esi
+ popl %edi
+ ret
+
+1: cmpl $-ETIMEDOUT, %eax
+ jne 2b
+6: movl $ETIMEDOUT, %eax
+ jmp 3b
+ .size __lll_timedwait_tid,.-__lll_timedwait_tid
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/lowlevelrobustlock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/lowlevelrobustlock.S
new file mode 100644
index 000000000..ff0974506
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/lowlevelrobustlock.S
@@ -0,0 +1,188 @@
+/* Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <pthread-errnos.h>
+#include <lowlevelrobustlock.h>
+
+ .text
+
+#ifndef LOCK
+# ifdef UP
+# define LOCK
+# else
+# define LOCK lock
+# endif
+#endif
+
+#define SYS_gettimeofday __NR_gettimeofday
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+#define FUTEX_WAITERS 0x80000000
+#define FUTEX_OWNER_DIED 0x40000000
+
+
+ .globl __lll_robust_mutex_lock_wait
+ .type __lll_robust_mutex_lock_wait,@function
+ .hidden __lll_robust_mutex_lock_wait
+ .align 16
+__lll_robust_mutex_lock_wait:
+ pushl %edx
+ pushl %ebx
+ pushl %esi
+
+ movl %ecx, %ebx
+ xorl %esi, %esi /* No timeout. */
+ xorl %ecx, %ecx /* movl $FUTEX_WAIT, %ecx */
+
+4: movl %eax, %edx
+ orl $FUTEX_WAITERS, %edx
+
+ testl $FUTEX_OWNER_DIED, %eax
+ jnz 3f
+
+ cmpl %edx, %eax /* NB: %edx == 2 */
+ je 1f
+
+ LOCK
+ cmpxchgl %edx, (%ebx)
+ jnz 2f
+
+1: movl $SYS_futex, %eax
+ ENTER_KERNEL
+
+ movl (%ebx), %eax
+
+2: test %eax, %eax
+ jne 4b
+
+ movl %gs:TID, %edx
+ orl $FUTEX_WAITERS, %edx
+ LOCK
+ cmpxchgl %edx, (%ebx)
+ jnz 4b
+ /* NB: %eax == 0 */
+
+3: popl %esi
+ popl %ebx
+ popl %edx
+ ret
+ .size __lll_robust_mutex_lock_wait,.-__lll_robust_mutex_lock_wait
+
+
+ .globl __lll_robust_mutex_timedlock_wait
+ .type __lll_robust_mutex_timedlock_wait,@function
+ .hidden __lll_robust_mutex_timedlock_wait
+ .align 16
+__lll_robust_mutex_timedlock_wait:
+ /* Check for a valid timeout value. */
+ cmpl $1000000000, 4(%edx)
+ jae 3f
+
+ pushl %edi
+ pushl %esi
+ pushl %ebx
+ pushl %ebp
+
+ /* Stack frame for the timespec and timeval structs. */
+ subl $12, %esp
+
+ movl %ecx, %ebp
+ movl %edx, %edi
+
+1: movl %eax, 8(%esp)
+
+ /* Get current time. */
+ movl %esp, %ebx
+ xorl %ecx, %ecx
+ movl $SYS_gettimeofday, %eax
+ ENTER_KERNEL
+
+ /* Compute relative timeout. */
+ movl 4(%esp), %eax
+ movl $1000, %edx
+ mul %edx /* Milli seconds to nano seconds. */
+ movl (%edi), %ecx
+ movl 4(%edi), %edx
+ subl (%esp), %ecx
+ subl %eax, %edx
+ jns 4f
+ addl $1000000000, %edx
+ subl $1, %ecx
+4: testl %ecx, %ecx
+ js 8f /* Time is already up. */
+
+ /* Store relative timeout. */
+ movl %ecx, (%esp)
+ movl %edx, 4(%esp)
+
+ movl %ebp, %ebx
+
+ movl 8(%esp), %edx
+ movl %edx, %eax
+ orl $FUTEX_WAITERS, %edx
+
+ testl $FUTEX_OWNER_DIED, %eax
+ jnz 6f
+
+ cmpl %eax, %edx
+ je 2f
+
+ LOCK
+ cmpxchgl %edx, (%ebx)
+ movl $0, %ecx /* Must use mov to avoid changing cc. */
+ jnz 5f
+
+2:
+ /* Futex call. */
+ movl %esp, %esi
+ xorl %ecx, %ecx /* movl $FUTEX_WAIT, %ecx */
+ movl $SYS_futex, %eax
+ ENTER_KERNEL
+ movl %eax, %ecx
+
+ movl (%ebx), %eax
+
+5: testl %eax, %eax
+ jne 7f
+
+ movl %gs:TID, %edx
+ orl $FUTEX_WAITERS, %edx
+ LOCK
+ cmpxchgl %edx, (%ebx)
+ jnz 7f
+
+6: addl $12, %esp
+ popl %ebp
+ popl %ebx
+ popl %esi
+ popl %edi
+ ret
+
+ /* Check whether the time expired. */
+7: cmpl $-ETIMEDOUT, %ecx
+ jne 1b
+
+8: movl $ETIMEDOUT, %eax
+ jmp 6b
+
+3: movl $EINVAL, %eax
+ ret
+ .size __lll_robust_mutex_timedlock_wait,.-__lll_robust_mutex_timedlock_wait
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_barrier_wait.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_barrier_wait.S
new file mode 100644
index 000000000..fe7a8b9c6
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_barrier_wait.S
@@ -0,0 +1,163 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <lowlevelbarrier.h>
+
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+#ifndef UP
+# define LOCK lock
+#else
+# define LOCK
+#endif
+
+
+ .text
+
+ .globl pthread_barrier_wait
+ .type pthread_barrier_wait,@function
+ .align 16
+pthread_barrier_wait:
+ pushl %ebx
+
+ movl 8(%esp), %ebx
+
+ /* Get the mutex. */
+ movl $1, %edx
+ xorl %eax, %eax
+ LOCK
+ cmpxchgl %edx, MUTEX(%ebx)
+ jnz 1f
+
+ /* One less waiter. If this was the last one needed wake
+ everybody. */
+2: subl $1, LEFT(%ebx)
+ je 3f
+
+ /* There are more threads to come. */
+ pushl %esi
+
+#if CURR_EVENT == 0
+ movl (%ebx), %edx
+#else
+ movl CURR_EVENT(%ebx), %edx
+#endif
+
+ /* Release the mutex. */
+ LOCK
+ subl $1, MUTEX(%ebx)
+ jne 6f
+
+ /* Wait for the remaining threads. The call will return immediately
+ if the CURR_EVENT memory has meanwhile been changed. */
+7: xorl %ecx, %ecx /* movl $FUTEX_WAIT, %ecx */
+ xorl %esi, %esi
+8: movl $SYS_futex, %eax
+ ENTER_KERNEL
+
+ /* Don't return on spurious wakeups. The syscall does not change
+ any register except %eax so there is no need to reload any of
+ them. */
+#if CURR_EVENT == 0
+ cmpl %edx, (%ebx)
+#else
+ cmpl %edx, CURR_EVENT(%ebx)
+#endif
+ je 8b
+
+ /* Increment LEFT. If this brings the count back to the
+ initial count unlock the object. */
+ movl $1, %edx
+ movl INIT_COUNT(%ebx), %ecx
+ LOCK
+ xaddl %edx, LEFT(%ebx)
+ subl $1, %ecx
+ cmpl %ecx, %edx
+ jne 10f
+
+ /* Release the mutex. We cannot release the lock before
+ waking the waiting threads since otherwise a new thread might
+ arrive and gets waken up, too. */
+ LOCK
+ subl $1, MUTEX(%ebx)
+ jne 9f
+
+ /* Note: %esi is still zero. */
+10: movl %esi, %eax /* != PTHREAD_BARRIER_SERIAL_THREAD */
+
+ popl %esi
+ popl %ebx
+ ret
+
+ /* The necessary number of threads arrived. */
+3:
+#if CURR_EVENT == 0
+ addl $1, (%ebx)
+#else
+ addl $1, CURR_EVENT(%ebx)
+#endif
+
+ /* Wake up all waiters. The count is a signed number in the kernel
+ so 0x7fffffff is the highest value. */
+ movl $0x7fffffff, %edx
+ movl $FUTEX_WAKE, %ecx
+ movl $SYS_futex, %eax
+ ENTER_KERNEL
+
+ /* Increment LEFT. If this brings the count back to the
+ initial count unlock the object. */
+ movl $1, %edx
+ movl INIT_COUNT(%ebx), %ecx
+ LOCK
+ xaddl %edx, LEFT(%ebx)
+ subl $1, %ecx
+ cmpl %ecx, %edx
+ jne 5f
+
+ /* Release the mutex. We cannot release the lock before
+ waking the waiting threads since otherwise a new thread might
+ arrive and gets waken up, too. */
+ LOCK
+ subl $1, MUTEX(%ebx)
+ jne 4f
+
+5: orl $-1, %eax /* == PTHREAD_BARRIER_SERIAL_THREAD */
+
+ popl %ebx
+ ret
+
+1: leal MUTEX(%ebx), %ecx
+ call __lll_mutex_lock_wait
+ jmp 2b
+
+4: leal MUTEX(%ebx), %eax
+ call __lll_mutex_unlock_wake
+ jmp 5b
+
+6: leal MUTEX(%ebx), %eax
+ call __lll_mutex_unlock_wake
+ jmp 7b
+
+9: leal MUTEX(%ebx), %eax
+ call __lll_mutex_unlock_wake
+ jmp 10b
+ .size pthread_barrier_wait,.-pthread_barrier_wait
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_broadcast.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_broadcast.S
new file mode 100644
index 000000000..56f7be824
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_broadcast.S
@@ -0,0 +1,169 @@
+/* Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <lowlevelcond.h>
+#include <kernel-features.h>
+#include <pthread-pi-defines.h>
+
+#ifdef UP
+# define LOCK
+#else
+# define LOCK lock
+#endif
+
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+#define FUTEX_REQUEUE 3
+#define FUTEX_CMP_REQUEUE 4
+
+#define EINVAL 22
+
+
+ .text
+
+ /* int pthread_cond_broadcast (pthread_cond_t *cond) */
+ .globl __pthread_cond_broadcast
+ .type __pthread_cond_broadcast, @function
+ .align 16
+__pthread_cond_broadcast:
+
+ pushl %ebx
+ pushl %esi
+ pushl %edi
+ pushl %ebp
+
+ movl 20(%esp), %ebx
+
+ /* Get internal lock. */
+ movl $1, %edx
+ xorl %eax, %eax
+ LOCK
+#if cond_lock == 0
+ cmpxchgl %edx, (%ebx)
+#else
+ cmpxchgl %edx, cond_lock(%ebx)
+#endif
+ jnz 1f
+
+2: addl $cond_futex, %ebx
+ movl total_seq+4-cond_futex(%ebx), %eax
+ movl total_seq-cond_futex(%ebx), %ebp
+ cmpl wakeup_seq+4-cond_futex(%ebx), %eax
+ ja 3f
+ jb 4f
+ cmpl wakeup_seq-cond_futex(%ebx), %ebp
+ jna 4f
+
+ /* Cause all currently waiting threads to recognize they are
+ woken up. */
+3: movl %ebp, wakeup_seq-cond_futex(%ebx)
+ movl %eax, wakeup_seq-cond_futex+4(%ebx)
+ movl %ebp, woken_seq-cond_futex(%ebx)
+ movl %eax, woken_seq-cond_futex+4(%ebx)
+ addl %ebp, %ebp
+ addl $1, broadcast_seq-cond_futex(%ebx)
+ movl %ebp, (%ebx)
+
+ /* Get the address of the mutex used. */
+ movl dep_mutex-cond_futex(%ebx), %edi
+
+ /* Unlock. */
+ LOCK
+ subl $1, cond_lock-cond_futex(%ebx)
+ jne 7f
+
+ /* Don't use requeue for pshared condvars. */
+8: cmpl $-1, %edi
+ je 9f
+
+ /* XXX: The kernel so far doesn't support requeue to PI futex. */
+ testl $PI_BIT, MUTEX_KIND(%edi)
+ jne 9f
+
+ /* Wake up all threads. */
+ movl $FUTEX_CMP_REQUEUE, %ecx
+ movl $SYS_futex, %eax
+ movl $0x7fffffff, %esi
+ movl $1, %edx
+ /* Get the address of the futex involved. */
+# if MUTEX_FUTEX != 0
+ addl $MUTEX_FUTEX, %edi
+# endif
+/* FIXME: Until Ingo fixes 4G/4G vDSO, 6 arg syscalls are broken for sysenter.
+ ENTER_KERNEL */
+ int $0x80
+
+ /* For any kind of error, which mainly is EAGAIN, we try again
+ with WAKE. The general test also covers running on old
+ kernels. */
+ cmpl $0xfffff001, %eax
+ jae 9f
+
+10: xorl %eax, %eax
+ popl %ebp
+ popl %edi
+ popl %esi
+ popl %ebx
+ ret
+
+ .align 16
+ /* Unlock. */
+4: LOCK
+ subl $1, cond_lock-cond_futex(%ebx)
+ jne 5f
+
+6: xorl %eax, %eax
+ popl %ebp
+ popl %edi
+ popl %esi
+ popl %ebx
+ ret
+
+ /* Initial locking failed. */
+1:
+#if cond_lock == 0
+ movl %ebx, %ecx
+#else
+ leal cond_lock(%ebx), %ecx
+#endif
+ call __lll_mutex_lock_wait
+ jmp 2b
+
+ /* Unlock in loop requires waekup. */
+5: leal cond_lock-cond_futex(%ebx), %eax
+ call __lll_mutex_unlock_wake
+ jmp 6b
+
+ /* Unlock in loop requires waekup. */
+7: leal cond_lock-cond_futex(%ebx), %eax
+ call __lll_mutex_unlock_wake
+ jmp 8b
+
+9: /* The futex requeue functionality is not available. */
+ movl $0x7fffffff, %edx
+ movl $FUTEX_WAKE, %ecx
+ movl $SYS_futex, %eax
+ ENTER_KERNEL
+ jmp 10b
+ .size __pthread_cond_broadcast, .-__pthread_cond_broadcast
+versioned_symbol (libpthread, __pthread_cond_broadcast, pthread_cond_broadcast,
+ GLIBC_2_3_2)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_signal.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_signal.S
new file mode 100644
index 000000000..d0f931ff1
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_signal.S
@@ -0,0 +1,137 @@
+/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <lowlevelcond.h>
+#include <kernel-features.h>
+
+#ifdef UP
+# define LOCK
+#else
+# define LOCK lock
+#endif
+
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+#define FUTEX_WAKE_OP 5
+
+#define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE ((4 << 24) | 1)
+
+#define EINVAL 22
+
+
+ .text
+
+ /* int pthread_cond_signal (pthread_cond_t *cond) */
+ .globl __pthread_cond_signal
+ .type __pthread_cond_signal, @function
+ .align 16
+__pthread_cond_signal:
+
+ pushl %ebx
+ pushl %edi
+
+ movl 12(%esp), %edi
+
+ /* Get internal lock. */
+ movl $1, %edx
+ xorl %eax, %eax
+ LOCK
+#if cond_lock == 0
+ cmpxchgl %edx, (%edi)
+#else
+ cmpxchgl %edx, cond_lock(%edi)
+#endif
+ jnz 1f
+
+2: leal cond_futex(%edi), %ebx
+ movl total_seq+4(%edi), %eax
+ movl total_seq(%edi), %ecx
+ cmpl wakeup_seq+4(%edi), %eax
+#if cond_lock != 0
+ /* Must use leal to preserve the flags. */
+ leal cond_lock(%edi), %edi
+#endif
+ ja 3f
+ jb 4f
+ cmpl wakeup_seq-cond_futex(%ebx), %ecx
+ jbe 4f
+
+ /* Bump the wakeup number. */
+3: addl $1, wakeup_seq-cond_futex(%ebx)
+ adcl $0, wakeup_seq-cond_futex+4(%ebx)
+ addl $1, (%ebx)
+
+ /* Wake up one thread. */
+ pushl %esi
+ pushl %ebp
+ movl $FUTEX_WAKE_OP, %ecx
+ movl $SYS_futex, %eax
+ movl $1, %edx
+ movl $1, %esi
+ movl $FUTEX_OP_CLEAR_WAKE_IF_GT_ONE, %ebp
+ /* FIXME: Until Ingo fixes 4G/4G vDSO, 6 arg syscalls are broken for
+ sysenter.
+ ENTER_KERNEL */
+ int $0x80
+ popl %ebp
+ popl %esi
+
+ /* For any kind of error, we try again with WAKE.
+ The general test also covers running on old kernels. */
+ cmpl $-4095, %eax
+ jae 7f
+
+6: xorl %eax, %eax
+ popl %edi
+ popl %ebx
+ ret
+
+7: movl $FUTEX_WAKE, %ecx
+ movl $SYS_futex, %eax
+ /* %edx should be 1 already from $FUTEX_WAKE_OP syscall.
+ movl $1, %edx */
+ ENTER_KERNEL
+
+ /* Unlock. Note that at this point %edi always points to
+ cond_lock. */
+4: LOCK
+ subl $1, (%edi)
+ je 6b
+
+ /* Unlock in loop requires wakeup. */
+5: movl %edi, %eax
+ call __lll_mutex_unlock_wake
+ jmp 6b
+
+ /* Initial locking failed. */
+1:
+#if cond_lock == 0
+ movl %edi, %ecx
+#else
+ leal cond_lock(%edi), %ecx
+#endif
+ call __lll_mutex_lock_wait
+ jmp 2b
+
+ .size __pthread_cond_signal, .-__pthread_cond_signal
+versioned_symbol (libpthread, __pthread_cond_signal, pthread_cond_signal,
+ GLIBC_2_3_2)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S
new file mode 100644
index 000000000..699c2cb22
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S
@@ -0,0 +1,637 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <lowlevelcond.h>
+#include <pthread-errnos.h>
+
+#ifdef UP
+# define LOCK
+#else
+# define LOCK lock
+#endif
+
+#define SYS_gettimeofday __NR_gettimeofday
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+
+ .text
+
+/* int pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
+ const struct timespec *abstime) */
+ .globl __pthread_cond_timedwait
+ .type __pthread_cond_timedwait, @function
+ .align 16
+__pthread_cond_timedwait:
+.LSTARTCODE:
+ pushl %ebp
+.Lpush_ebp:
+ pushl %edi
+.Lpush_edi:
+ pushl %esi
+.Lpush_esi:
+ pushl %ebx
+.Lpush_ebx:
+
+ movl 20(%esp), %ebx
+ movl 28(%esp), %ebp
+
+ cmpl $1000000000, 4(%ebp)
+ movl $EINVAL, %eax
+ jae 18f
+
+ /* Get internal lock. */
+ movl $1, %edx
+ xorl %eax, %eax
+ LOCK
+#if cond_lock == 0
+ cmpxchgl %edx, (%ebx)
+#else
+ cmpxchgl %edx, cond_lock(%ebx)
+#endif
+ jnz 1f
+
+ /* Store the reference to the mutex. If there is already a
+ different value in there this is a bad user bug. */
+2: cmpl $-1, dep_mutex(%ebx)
+ movl 24(%esp), %eax
+ je 17f
+ movl %eax, dep_mutex(%ebx)
+
+ /* Unlock the mutex. */
+17: xorl %edx, %edx
+ call __pthread_mutex_unlock_usercnt
+
+ testl %eax, %eax
+ jne 16f
+
+ addl $1, total_seq(%ebx)
+ adcl $0, total_seq+4(%ebx)
+ addl $1, cond_futex(%ebx)
+ addl $(1 << clock_bits), cond_nwaiters(%ebx)
+
+#define FRAME_SIZE 24
+ subl $FRAME_SIZE, %esp
+.Lsubl:
+
+ /* Get and store current wakeup_seq value. */
+ movl wakeup_seq(%ebx), %edi
+ movl wakeup_seq+4(%ebx), %edx
+ movl broadcast_seq(%ebx), %eax
+ movl %edi, 12(%esp)
+ movl %edx, 16(%esp)
+ movl %eax, 20(%esp)
+
+ /* Get the current time. */
+8: movl %ebx, %edx
+#ifdef __NR_clock_gettime
+ /* Get the clock number. */
+ movl cond_nwaiters(%ebx), %ebx
+ andl $((1 << clock_bits) - 1), %ebx
+ /* Only clocks 0 and 1 are allowed so far. Both are handled in the
+ kernel. */
+ leal 4(%esp), %ecx
+ movl $__NR_clock_gettime, %eax
+ ENTER_KERNEL
+# ifndef __ASSUME_POSIX_TIMERS
+ cmpl $-ENOSYS, %eax
+ je 19f
+# endif
+ movl %edx, %ebx
+
+ /* Compute relative timeout. */
+ movl (%ebp), %ecx
+ movl 4(%ebp), %edx
+ subl 4(%esp), %ecx
+ subl 8(%esp), %edx
+#else
+ /* Get the current time. */
+ leal 4(%esp), %ebx
+ xorl %ecx, %ecx
+ movl $SYS_gettimeofday, %eax
+ ENTER_KERNEL
+ movl %edx, %ebx
+
+ /* Compute relative timeout. */
+ movl 8(%esp), %eax
+ movl $1000, %edx
+ mul %edx /* Milli seconds to nano seconds. */
+ movl (%ebp), %ecx
+ movl 4(%ebp), %edx
+ subl 4(%esp), %ecx
+ subl %eax, %edx
+#endif
+ jns 12f
+ addl $1000000000, %edx
+ subl $1, %ecx
+12: testl %ecx, %ecx
+ movl $-ETIMEDOUT, %esi
+ js 6f
+
+ /* Store relative timeout. */
+21: movl %ecx, 4(%esp)
+ movl %edx, 8(%esp)
+
+ movl cond_futex(%ebx), %edi
+
+ /* Unlock. */
+ LOCK
+#if cond_lock == 0
+ subl $1, (%ebx)
+#else
+ subl $1, cond_lock(%ebx)
+#endif
+ jne 3f
+
+.LcleanupSTART:
+4: call __pthread_enable_asynccancel
+ movl %eax, (%esp)
+
+ leal 4(%esp), %esi
+ xorl %ecx, %ecx /* movl $FUTEX_WAIT, %ecx */
+ movl %edi, %edx
+ addl $cond_futex, %ebx
+.Ladd_cond_futex:
+ movl $SYS_futex, %eax
+ ENTER_KERNEL
+ subl $cond_futex, %ebx
+.Lsub_cond_futex:
+ movl %eax, %esi
+
+ movl (%esp), %eax
+ call __pthread_disable_asynccancel
+.LcleanupEND:
+
+ /* Lock. */
+ movl $1, %edx
+ xorl %eax, %eax
+ LOCK
+#if cond_lock == 0
+ cmpxchgl %edx, (%ebx)
+#else
+ cmpxchgl %edx, cond_lock(%ebx)
+#endif
+ jnz 5f
+
+6: movl broadcast_seq(%ebx), %eax
+ cmpl 20(%esp), %eax
+ jne 23f
+
+ movl woken_seq(%ebx), %eax
+ movl woken_seq+4(%ebx), %ecx
+
+ movl wakeup_seq(%ebx), %edi
+ movl wakeup_seq+4(%ebx), %edx
+
+ cmpl 16(%esp), %edx
+ jne 7f
+ cmpl 12(%esp), %edi
+ je 15f
+
+7: cmpl %ecx, %edx
+ jne 9f
+ cmp %eax, %edi
+ jne 9f
+
+15: cmpl $-ETIMEDOUT, %esi
+ jne 8b
+
+ addl $1, wakeup_seq(%ebx)
+ adcl $0, wakeup_seq+4(%ebx)
+ addl $1, cond_futex(%ebx)
+ movl $ETIMEDOUT, %esi
+ jmp 14f
+
+23: xorl %esi, %esi
+ jmp 24f
+
+9: xorl %esi, %esi
+14: addl $1, woken_seq(%ebx)
+ adcl $0, woken_seq+4(%ebx)
+
+24: subl $(1 << clock_bits), cond_nwaiters(%ebx)
+
+ /* Wake up a thread which wants to destroy the condvar object. */
+ movl total_seq(%ebx), %eax
+ andl total_seq+4(%ebx), %eax
+ cmpl $0xffffffff, %eax
+ jne 25f
+ movl cond_nwaiters(%ebx), %eax
+ andl $~((1 << clock_bits) - 1), %eax
+ jne 25f
+
+ addl $cond_nwaiters, %ebx
+ movl $SYS_futex, %eax
+ movl $FUTEX_WAKE, %ecx
+ movl $1, %edx
+ ENTER_KERNEL
+ subl $cond_nwaiters, %ebx
+
+25: LOCK
+#if cond_lock == 0
+ subl $1, (%ebx)
+#else
+ subl $1, cond_lock(%ebx)
+#endif
+ jne 10f
+
+ /* Remove cancellation handler. */
+11: movl 24+FRAME_SIZE(%esp), %eax
+ call __pthread_mutex_cond_lock
+ addl $FRAME_SIZE, %esp
+.Laddl:
+
+ /* We return the result of the mutex_lock operation if it failed. */
+ testl %eax, %eax
+#ifdef HAVE_CMOV
+ cmovel %esi, %eax
+#else
+ jne 22f
+ movl %esi, %eax
+22:
+#endif
+
+18: popl %ebx
+.Lpop_ebx:
+ popl %esi
+.Lpop_esi:
+ popl %edi
+.Lpop_edi:
+ popl %ebp
+.Lpop_ebp:
+
+ ret
+
+ /* Initial locking failed. */
+1:
+.LSbl1:
+#if cond_lock == 0
+ movl %ebx, %ecx
+#else
+ leal cond_lock(%ebx), %ecx
+#endif
+ call __lll_mutex_lock_wait
+ jmp 2b
+
+ /* Unlock in loop requires wakeup. */
+3:
+.LSbl2:
+#if cond_lock == 0
+ movl %ebx, %eax
+#else
+ leal cond_lock(%ebx), %eax
+#endif
+ call __lll_mutex_unlock_wake
+ jmp 4b
+
+ /* Locking in loop failed. */
+5:
+#if cond_lock == 0
+ movl %ebx, %ecx
+#else
+ leal cond_lock(%ebx), %ecx
+#endif
+ call __lll_mutex_lock_wait
+ jmp 6b
+
+ /* Unlock after loop requires wakeup. */
+10:
+#if cond_lock == 0
+ movl %ebx, %eax
+#else
+ leal cond_lock(%ebx), %eax
+#endif
+ call __lll_mutex_unlock_wake
+ jmp 11b
+
+ /* The initial unlocking of the mutex failed. */
+16:
+.LSbl3:
+ LOCK
+#if cond_lock == 0
+ subl $1, (%ebx)
+#else
+ subl $1, cond_lock(%ebx)
+#endif
+ jne 18b
+
+ movl %eax, %esi
+#if cond_lock == 0
+ movl %ebx, %eax
+#else
+ leal cond_lock(%ebx), %eax
+#endif
+ call __lll_mutex_unlock_wake
+
+ movl %esi, %eax
+ jmp 18b
+
+#if defined __NR_clock_gettime && !defined __ASSUME_POSIX_TIMERS
+ /* clock_gettime not available. */
+.LSbl4:
+19: leal 4(%esp), %ebx
+ xorl %ecx, %ecx
+ movl $SYS_gettimeofday, %eax
+ ENTER_KERNEL
+ movl %edx, %ebx
+
+ /* Compute relative timeout. */
+ movl 8(%esp), %eax
+ movl $1000, %edx
+ mul %edx /* Milli seconds to nano seconds. */
+ movl (%ebp), %ecx
+ movl 4(%ebp), %edx
+ subl 4(%esp), %ecx
+ subl %eax, %edx
+ jns 20f
+ addl $1000000000, %edx
+ subl $1, %ecx
+20: testl %ecx, %ecx
+ movl $-ETIMEDOUT, %esi
+ js 6b
+ jmp 21b
+#endif
+ .size __pthread_cond_timedwait, .-__pthread_cond_timedwait
+versioned_symbol (libpthread, __pthread_cond_timedwait, pthread_cond_timedwait,
+ GLIBC_2_3_2)
+
+
+ .type __condvar_tw_cleanup2, @function
+__condvar_tw_cleanup2:
+ subl $cond_futex, %ebx
+.LSbl5:
+ .size __condvar_tw_cleanup2, .-__condvar_tw_cleanup2
+ .type __condvar_tw_cleanup, @function
+__condvar_tw_cleanup:
+ movl %eax, %esi
+
+ /* Get internal lock. */
+ movl $1, %edx
+ xorl %eax, %eax
+ LOCK
+#if cond_lock == 0
+ cmpxchgl %edx, (%ebx)
+#else
+ cmpxchgl %edx, cond_lock(%ebx)
+#endif
+ jz 1f
+
+#if cond_lock == 0
+ movl %ebx, %ecx
+#else
+ leal cond_lock(%ebx), %ecx
+#endif
+ call __lll_mutex_lock_wait
+
+1: movl broadcast_seq(%ebx), %eax
+ cmpl 20(%esp), %eax
+ jne 3f
+
+ addl $1, wakeup_seq(%ebx)
+ adcl $0, wakeup_seq+4(%ebx)
+
+ addl $1, cond_futex(%ebx)
+
+ addl $1, woken_seq(%ebx)
+ adcl $0, woken_seq+4(%ebx)
+
+3: subl $(1 << clock_bits), cond_nwaiters(%ebx)
+
+ /* Wake up a thread which wants to destroy the condvar object. */
+ xorl %edi, %edi
+ movl total_seq(%ebx), %eax
+ andl total_seq+4(%ebx), %eax
+ cmpl $0xffffffff, %eax
+ jne 4f
+ movl cond_nwaiters(%ebx), %eax
+ andl $~((1 << clock_bits) - 1), %eax
+ jne 4f
+
+ addl $cond_nwaiters, %ebx
+ movl $SYS_futex, %eax
+ movl $FUTEX_WAKE, %ecx
+ movl $1, %edx
+ ENTER_KERNEL
+ subl $cond_nwaiters, %ebx
+ movl $1, %edi
+
+4: LOCK
+#if cond_lock == 0
+ subl $1, (%ebx)
+#else
+ subl $1, cond_lock(%ebx)
+#endif
+ je 2f
+
+#if cond_lock == 0
+ movl %ebx, %eax
+#else
+ leal cond_lock(%ebx), %eax
+#endif
+ call __lll_mutex_unlock_wake
+
+ /* Wake up all waiters to make sure no signal gets lost. */
+2: testl %edi, %edi
+ jnz 5f
+ addl $cond_futex, %ebx
+ movl $FUTEX_WAKE, %ecx
+ movl $SYS_futex, %eax
+ movl $0x7fffffff, %edx
+ ENTER_KERNEL
+
+5: movl 24+FRAME_SIZE(%esp), %eax
+ call __pthread_mutex_cond_lock
+
+ movl %esi, (%esp)
+.LcallUR:
+ call _Unwind_Resume
+ hlt
+.LENDCODE:
+ .size __condvar_tw_cleanup, .-__condvar_tw_cleanup
+
+
+ .section .gcc_except_table,"a",@progbits
+.LexceptSTART:
+ .byte 0xff # @LPStart format (omit)
+ .byte 0xff # @TType format (omit)
+ .byte 0x0b # call-site format
+ # DW_EH_PE_sdata4
+ .uleb128 .Lcstend-.Lcstbegin
+.Lcstbegin:
+ .long .LcleanupSTART-.LSTARTCODE
+ .long .Ladd_cond_futex-.LcleanupSTART
+ .long __condvar_tw_cleanup-.LSTARTCODE
+ .uleb128 0
+ .long .Ladd_cond_futex-.LSTARTCODE
+ .long .Lsub_cond_futex-.Ladd_cond_futex
+ .long __condvar_tw_cleanup2-.LSTARTCODE
+ .uleb128 0
+ .long .Lsub_cond_futex-.LSTARTCODE
+ .long .LcleanupEND-.Lsub_cond_futex
+ .long __condvar_tw_cleanup-.LSTARTCODE
+ .uleb128 0
+ .long .LcallUR-.LSTARTCODE
+ .long .LENDCODE-.LcallUR
+ .long 0
+ .uleb128 0
+.Lcstend:
+
+
+ .section .eh_frame,"a",@progbits
+.LSTARTFRAME:
+ .long L(ENDCIE)-L(STARTCIE) # Length of the CIE.
+.LSTARTCIE:
+ .long 0 # CIE ID.
+ .byte 1 # Version number.
+#ifdef SHARED
+ .string "zPLR" # NUL-terminated augmentation
+ # string.
+#else
+ .string "zPL" # NUL-terminated augmentation
+ # string.
+#endif
+ .uleb128 1 # Code alignment factor.
+ .sleb128 -4 # Data alignment factor.
+ .byte 8 # Return address register
+ # column.
+#ifdef SHARED
+ .uleb128 7 # Augmentation value length.
+ .byte 0x9b # Personality: DW_EH_PE_pcrel
+ # + DW_EH_PE_sdata4
+ # + DW_EH_PE_indirect
+ .long DW.ref.__gcc_personality_v0-.
+ .byte 0x1b # LSDA Encoding: DW_EH_PE_pcrel
+ # + DW_EH_PE_sdata4.
+ .byte 0x1b # FDE Encoding: DW_EH_PE_pcrel
+ # + DW_EH_PE_sdata4.
+#else
+ .uleb128 6 # Augmentation value length.
+ .byte 0x0 # Personality: absolute
+ .long __gcc_personality_v0
+ .byte 0x0 # LSDA Encoding: absolute
+#endif
+ .byte 0x0c # DW_CFA_def_cfa
+ .uleb128 4
+ .uleb128 4
+ .byte 0x88 # DW_CFA_offset, column 0x8
+ .uleb128 1
+ .align 4
+.LENDCIE:
+
+ .long .LENDFDE-.LSTARTFDE # Length of the FDE.
+.LSTARTFDE:
+ .long .LSTARTFDE-.LSTARTFRAME # CIE pointer.
+#ifdef SHARED
+ .long .LSTARTCODE-. # PC-relative start address
+ # of the code
+#else
+ .long .LSTARTCODE # Start address of the code.
+#endif
+ .long .LENDCODE-.LSTARTCODE # Length of the code.
+ .uleb128 4 # Augmentation size
+#ifdef SHARED
+ .long .LexceptSTART-.
+#else
+ .long .LexceptSTART
+#endif
+ .byte 0x40+.Lpush_ebp-.LSTARTCODE # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 8
+ .byte 0x85 # DW_CFA_offset %ebp
+ .uleb128 2
+ .byte 0x40+ .Lpush_edi-.Lpush_ebp # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 12
+ .byte 0x87 # DW_CFA_offset %edi
+ .uleb128 3
+ .byte 0x40+.Lpush_esi-.Lpush_edi # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 16
+ .byte 0x86 # DW_CFA_offset %esi
+ .uleb128 4
+ .byte 0x40+.Lpush_ebx-.Lpush_esi # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 20
+ .byte 0x83 # DW_CFA_offset %ebx
+ .uleb128 5
+ .byte 2 # DW_CFA_advance_loc1
+ .byte .Lsubl-.Lpush_ebx
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 20+FRAME_SIZE
+ .byte 3 # DW_CFA_advance_loc2
+ .2byte .Laddl-.Lsubl
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 20
+ .byte 0x40+.Lpop_ebx-.Laddl # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 16
+ .byte 0xc3 # DW_CFA_restore %ebx
+ .byte 0x40+.Lpop_esi-.Lpop_ebx # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 12
+ .byte 0xc6 # DW_CFA_restore %esi
+ .byte 0x40+.Lpop_edi-.Lpop_esi # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 8
+ .byte 0xc7 # DW_CFA_restore %edi
+ .byte 0x40+.Lpop_ebp-.Lpop_edi # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 4
+ .byte 0xc5 # DW_CFA_restore %ebp
+ .byte 0x40+.LSbl1-.Lpop_edi # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 20
+ .byte 0x40+.LSbl2-.LSbl1 # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 20+FRAME_SIZE
+ .byte 0x85 # DW_CFA_offset %ebp
+ .uleb128 2
+ .byte 0x87 # DW_CFA_offset %edi
+ .uleb128 3
+ .byte 0x86 # DW_CFA_offset %esi
+ .uleb128 4
+ .byte 0x83 # DW_CFA_offset %ebx
+ .uleb128 5
+ .byte 0x40+.LSbl3-.LSbl2 # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 20
+#if defined __NR_clock_gettime && !defined __ASSUME_POSIX_TIMERS
+ .byte 0x40+.LSbl4-.LSbl3 # DW_CFA_advance_loc+N
+#else
+ .byte 4 # DW_CFA_advance_loc4
+ .long .LSbl5-.LSbl3
+#endif
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 20+FRAME_SIZE
+ .align 4
+.LENDFDE:
+
+#ifdef SHARED
+ .hidden DW.ref.__gcc_personality_v0
+ .weak DW.ref.__gcc_personality_v0
+ .section .gnu.linkonce.d.DW.ref.__gcc_personality_v0,"aw",@progbits
+ .align 4
+ .type DW.ref.__gcc_personality_v0, @object
+ .size DW.ref.__gcc_personality_v0, 4
+DW.ref.__gcc_personality_v0:
+ .long __gcc_personality_v0
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S
new file mode 100644
index 000000000..d28278515
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S
@@ -0,0 +1,523 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <lowlevelcond.h>
+#include <tcb-offsets.h>
+
+#ifdef UP
+# define LOCK
+#else
+# define LOCK lock
+#endif
+
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+
+ .text
+
+/* int pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex) */
+ .globl __pthread_cond_wait
+ .type __pthread_cond_wait, @function
+ .align 16
+__pthread_cond_wait:
+.LSTARTCODE:
+
+ pushl %edi
+.Lpush_edi:
+ pushl %esi
+.Lpush_esi:
+ pushl %ebx
+.Lpush_ebx:
+
+ xorl %esi, %esi
+ movl 16(%esp), %ebx
+
+ /* Get internal lock. */
+ movl $1, %edx
+ xorl %eax, %eax
+ LOCK
+#if cond_lock == 0
+ cmpxchgl %edx, (%ebx)
+#else
+ cmpxchgl %edx, cond_lock(%ebx)
+#endif
+ jnz 1f
+
+ /* Store the reference to the mutex. If there is already a
+ different value in there this is a bad user bug. */
+2: cmpl $-1, dep_mutex(%ebx)
+ movl 20(%esp), %eax
+ je 15f
+ movl %eax, dep_mutex(%ebx)
+
+ /* Unlock the mutex. */
+15: xorl %edx, %edx
+ call __pthread_mutex_unlock_usercnt
+
+ testl %eax, %eax
+ jne 12f
+
+ addl $1, total_seq(%ebx)
+ adcl $0, total_seq+4(%ebx)
+ addl $1, cond_futex(%ebx)
+ addl $(1 << clock_bits), cond_nwaiters(%ebx)
+
+#define FRAME_SIZE 16
+ subl $FRAME_SIZE, %esp
+.Lsubl:
+
+ /* Get and store current wakeup_seq value. */
+ movl wakeup_seq(%ebx), %edi
+ movl wakeup_seq+4(%ebx), %edx
+ movl broadcast_seq(%ebx), %eax
+ movl %edi, 4(%esp)
+ movl %edx, 8(%esp)
+ movl %eax, 12(%esp)
+
+8: movl cond_futex(%ebx), %edi
+
+ /* Unlock. */
+ LOCK
+#if cond_lock == 0
+ subl $1, (%ebx)
+#else
+ subl $1, cond_lock(%ebx)
+#endif
+ jne 3f
+
+.LcleanupSTART:
+4: call __pthread_enable_asynccancel
+ movl %eax, (%esp)
+
+ movl %esi, %ecx /* movl $FUTEX_WAIT, %ecx */
+ movl %edi, %edx
+ addl $cond_futex, %ebx
+.Ladd_cond_futex:
+ movl $SYS_futex, %eax
+ ENTER_KERNEL
+ subl $cond_futex, %ebx
+.Lsub_cond_futex:
+
+ movl (%esp), %eax
+ call __pthread_disable_asynccancel
+.LcleanupEND:
+
+ /* Lock. */
+ movl $1, %edx
+ xorl %eax, %eax
+ LOCK
+#if cond_lock == 0
+ cmpxchgl %edx, (%ebx)
+#else
+ cmpxchgl %edx, cond_lock(%ebx)
+#endif
+ jnz 5f
+
+6: movl broadcast_seq(%ebx), %eax
+ cmpl 12(%esp), %eax
+ jne 16f
+
+ movl woken_seq(%ebx), %eax
+ movl woken_seq+4(%ebx), %ecx
+
+ movl wakeup_seq(%ebx), %edi
+ movl wakeup_seq+4(%ebx), %edx
+
+ cmpl 8(%esp), %edx
+ jne 7f
+ cmpl 4(%esp), %edi
+ je 8b
+
+7: cmpl %ecx, %edx
+ jne 9f
+ cmp %eax, %edi
+ je 8b
+
+9: addl $1, woken_seq(%ebx)
+ adcl $0, woken_seq+4(%ebx)
+
+ /* Unlock */
+16: subl $(1 << clock_bits), cond_nwaiters(%ebx)
+
+ /* Wake up a thread which wants to destroy the condvar object. */
+ movl total_seq(%ebx), %eax
+ andl total_seq+4(%ebx), %eax
+ cmpl $0xffffffff, %eax
+ jne 17f
+ movl cond_nwaiters(%ebx), %eax
+ andl $~((1 << clock_bits) - 1), %eax
+ jne 17f
+
+ addl $cond_nwaiters, %ebx
+ movl $SYS_futex, %eax
+ movl $FUTEX_WAKE, %ecx
+ movl $1, %edx
+ ENTER_KERNEL
+ subl $cond_nwaiters, %ebx
+
+17: LOCK
+#if cond_lock == 0
+ subl $1, (%ebx)
+#else
+ subl $1, cond_lock(%ebx)
+#endif
+ jne 10f
+
+11: movl 20+FRAME_SIZE(%esp), %eax
+ call __pthread_mutex_cond_lock
+ addl $FRAME_SIZE, %esp
+.Laddl:
+
+14: popl %ebx
+.Lpop_ebx:
+ popl %esi
+.Lpop_esi:
+ popl %edi
+.Lpop_edi:
+
+ /* We return the result of the mutex_lock operation. */
+ ret
+
+ /* Initial locking failed. */
+1:
+.LSbl1:
+#if cond_lock == 0
+ movl %ebx, %ecx
+#else
+ leal cond_lock(%ebx), %ecx
+#endif
+ call __lll_mutex_lock_wait
+ jmp 2b
+
+ /* Unlock in loop requires waekup. */
+3:
+.LSbl2:
+#if cond_lock == 0
+ movl %ebx, %eax
+#else
+ leal cond_lock(%ebx), %eax
+#endif
+ call __lll_mutex_unlock_wake
+ jmp 4b
+
+ /* Locking in loop failed. */
+5:
+#if cond_lock == 0
+ movl %ebx, %ecx
+#else
+ leal cond_lock(%ebx), %ecx
+#endif
+ call __lll_mutex_lock_wait
+ jmp 6b
+
+ /* Unlock after loop requires wakeup. */
+10:
+#if cond_lock == 0
+ movl %ebx, %eax
+#else
+ leal cond_lock(%ebx), %eax
+#endif
+ call __lll_mutex_unlock_wake
+ jmp 11b
+
+ /* The initial unlocking of the mutex failed. */
+12:
+.LSbl3:
+ LOCK
+#if cond_lock == 0
+ subl $1, (%ebx)
+#else
+ subl $1, cond_lock(%ebx)
+#endif
+ jne 14b
+
+ movl %eax, %esi
+#if cond_lock == 0
+ movl %ebx, %eax
+#else
+ leal cond_lock(%ebx), %eax
+#endif
+ call __lll_mutex_unlock_wake
+
+ movl %esi, %eax
+ jmp 14b
+ .size __pthread_cond_wait, .-__pthread_cond_wait
+versioned_symbol (libpthread, __pthread_cond_wait, pthread_cond_wait,
+ GLIBC_2_3_2)
+
+
+ .type __condvar_w_cleanup2, @function
+__condvar_w_cleanup2:
+ subl $cond_futex, %ebx
+ .size __condvar_w_cleanup2, .-__condvar_w_cleanup2
+.LSbl4:
+ .type __condvar_w_cleanup, @function
+__condvar_w_cleanup:
+ movl %eax, %esi
+
+ /* Get internal lock. */
+ movl $1, %edx
+ xorl %eax, %eax
+ LOCK
+#if cond_lock == 0
+ cmpxchgl %edx, (%ebx)
+#else
+ cmpxchgl %edx, cond_lock(%ebx)
+#endif
+ jz 1f
+
+#if cond_lock == 0
+ movl %ebx, %ecx
+#else
+ leal cond_lock(%ebx), %ecx
+#endif
+ call __lll_mutex_lock_wait
+
+1: movl broadcast_seq(%ebx), %eax
+ cmpl 12(%esp), %eax
+ jne 3f
+
+ addl $1, wakeup_seq(%ebx)
+ adcl $0, wakeup_seq+4(%ebx)
+
+ addl $1, cond_futex(%ebx)
+
+ addl $1, woken_seq(%ebx)
+ adcl $0, woken_seq+4(%ebx)
+
+3: subl $(1 << clock_bits), cond_nwaiters(%ebx)
+
+ /* Wake up a thread which wants to destroy the condvar object. */
+ xorl %edi, %edi
+ movl total_seq(%ebx), %eax
+ andl total_seq+4(%ebx), %eax
+ cmpl $0xffffffff, %eax
+ jne 4f
+ movl cond_nwaiters(%ebx), %eax
+ andl $~((1 << clock_bits) - 1), %eax
+ jne 4f
+
+ addl $cond_nwaiters, %ebx
+ movl $SYS_futex, %eax
+ movl $FUTEX_WAKE, %ecx
+ movl $1, %edx
+ ENTER_KERNEL
+ subl $cond_nwaiters, %ebx
+ movl $1, %edi
+
+4: LOCK
+#if cond_lock == 0
+ subl $1, (%ebx)
+#else
+ subl $1, cond_lock(%ebx)
+#endif
+ je 2f
+
+#if cond_lock == 0
+ movl %ebx, %eax
+#else
+ leal cond_lock(%ebx), %eax
+#endif
+ call __lll_mutex_unlock_wake
+
+ /* Wake up all waiters to make sure no signal gets lost. */
+2: testl %edi, %edi
+ jnz 5f
+ addl $cond_futex, %ebx
+ movl $FUTEX_WAKE, %ecx
+ movl $SYS_futex, %eax
+ movl $0x7fffffff, %edx
+ ENTER_KERNEL
+
+5: movl 20+FRAME_SIZE(%esp), %eax
+ call __pthread_mutex_cond_lock
+
+ movl %esi, (%esp)
+.LcallUR:
+ call _Unwind_Resume
+ hlt
+.LENDCODE:
+ .size __condvar_w_cleanup, .-__condvar_w_cleanup
+
+
+ .section .gcc_except_table,"a",@progbits
+.LexceptSTART:
+ .byte 0xff # @LPStart format (omit)
+ .byte 0xff # @TType format (omit)
+ .byte 0x0b # call-site format
+ # DW_EH_PE_sdata4
+ .uleb128 .Lcstend-.Lcstbegin
+.Lcstbegin:
+ .long .LcleanupSTART-.LSTARTCODE
+ .long .Ladd_cond_futex-.LcleanupSTART
+ .long __condvar_w_cleanup-.LSTARTCODE
+ .uleb128 0
+ .long .Ladd_cond_futex-.LSTARTCODE
+ .long .Lsub_cond_futex-.Ladd_cond_futex
+ .long __condvar_w_cleanup2-.LSTARTCODE
+ .uleb128 0
+ .long .Lsub_cond_futex-.LSTARTCODE
+ .long .LcleanupEND-.Lsub_cond_futex
+ .long __condvar_w_cleanup-.LSTARTCODE
+ .uleb128 0
+ .long .LcallUR-.LSTARTCODE
+ .long .LENDCODE-.LcallUR
+ .long 0
+ .uleb128 0
+.Lcstend:
+
+ .section .eh_frame,"a",@progbits
+.LSTARTFRAME:
+ .long L(ENDCIE)-L(STARTCIE) # Length of the CIE.
+.LSTARTCIE:
+ .long 0 # CIE ID.
+ .byte 1 # Version number.
+#ifdef SHARED
+ .string "zPLR" # NUL-terminated augmentation
+ # string.
+#else
+ .string "zPL" # NUL-terminated augmentation
+ # string.
+#endif
+ .uleb128 1 # Code alignment factor.
+ .sleb128 -4 # Data alignment factor.
+ .byte 8 # Return address register
+ # column.
+#ifdef SHARED
+ .uleb128 7 # Augmentation value length.
+ .byte 0x9b # Personality: DW_EH_PE_pcrel
+ # + DW_EH_PE_sdata4
+ # + DW_EH_PE_indirect
+ .long DW.ref.__gcc_personality_v0-.
+ .byte 0x1b # LSDA Encoding: DW_EH_PE_pcrel
+ # + DW_EH_PE_sdata4.
+ .byte 0x1b # FDE Encoding: DW_EH_PE_pcrel
+ # + DW_EH_PE_sdata4.
+#else
+ .uleb128 6 # Augmentation value length.
+ .byte 0x0 # Personality: absolute
+ .long __gcc_personality_v0
+ .byte 0x0 # LSDA Encoding: absolute
+#endif
+ .byte 0x0c # DW_CFA_def_cfa
+ .uleb128 4
+ .uleb128 4
+ .byte 0x88 # DW_CFA_offset, column 0x8
+ .uleb128 1
+ .align 4
+.LENDCIE:
+
+ .long .LENDFDE-.LSTARTFDE # Length of the FDE.
+.LSTARTFDE:
+ .long .LSTARTFDE-.LSTARTFRAME # CIE pointer.
+#ifdef SHARED
+ .long .LSTARTCODE-. # PC-relative start address
+ # of the code.
+#else
+ .long .LSTARTCODE # Start address of the code.
+#endif
+ .long .LENDCODE-.LSTARTCODE # Length of the code.
+ .uleb128 4 # Augmentation size
+#ifdef SHARED
+ .long .LexceptSTART-.
+#else
+ .long .LexceptSTART
+#endif
+ .byte 0x40+.Lpush_edi-.LSTARTCODE # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 8
+ .byte 0x87 # DW_CFA_offset %edi
+ .uleb128 2
+ .byte 0x40+.Lpush_esi-.Lpush_edi # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 12
+ .byte 0x86 # DW_CFA_offset %esi
+ .uleb128 3
+ .byte 0x40+.Lpush_ebx-.Lpush_esi # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 16
+ .byte 0x83 # DW_CFA_offset %ebx
+ .uleb128 4
+ .byte 2 # DW_CFA_advance_loc1
+ .byte .Lsubl-.Lpush_ebx
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 16+FRAME_SIZE
+ .byte 2 # DW_CFA_advance_loc1
+ .byte .Laddl-.Lsubl
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 16
+ .byte 0x40+ .Lpop_ebx-.Laddl # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 12
+ .byte 0xc3 # DW_CFA_restore %ebx
+ .byte 0x40+.Lpop_esi-.Lpop_ebx # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 8
+ .byte 0xc6 # DW_CFA_restore %esi
+ .byte 0x40+.Lpop_edi-.Lpop_esi # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 4
+ .byte 0xc7 # DW_CFA_restore %edi
+ .byte 0x40+.LSbl1-.Lpop_edi # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 16
+ .byte 0x87 # DW_CFA_offset %edi
+ .uleb128 2
+ .byte 0x86 # DW_CFA_offset %esi
+ .uleb128 3
+ .byte 0x83 # DW_CFA_offset %ebx
+ .uleb128 4
+ .byte 0x40+.LSbl2-.LSbl1 # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 16+FRAME_SIZE
+ .byte 0x40+.LSbl3-.LSbl2 # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 16
+ .byte 0x40+.LSbl4-.LSbl3 # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 16+FRAME_SIZE
+ .align 4
+.LENDFDE:
+
+
+#ifdef PIC
+ .section .gnu.linkonce.t.__i686.get_pc_thunk.cx,"ax",@progbits
+ .globl __i686.get_pc_thunk.cx
+ .hidden __i686.get_pc_thunk.cx
+ .type __i686.get_pc_thunk.cx,@function
+__i686.get_pc_thunk.cx:
+ movl (%esp), %ecx;
+ ret
+ .size __i686.get_pc_thunk.cx,.-__i686.get_pc_thunk.cx
+#endif
+
+#ifdef SHARED
+ .hidden DW.ref.__gcc_personality_v0
+ .weak DW.ref.__gcc_personality_v0
+ .section .gnu.linkonce.d.DW.ref.__gcc_personality_v0,"aw",@progbits
+ .align 4
+ .type DW.ref.__gcc_personality_v0, @object
+ .size DW.ref.__gcc_personality_v0, 4
+DW.ref.__gcc_personality_v0:
+ .long __gcc_personality_v0
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_rdlock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_rdlock.S
new file mode 100644
index 000000000..db0639d21
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_rdlock.S
@@ -0,0 +1,175 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <lowlevelrwlock.h>
+#include <pthread-errnos.h>
+
+
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+#ifndef UP
+# define LOCK lock
+#else
+# define LOCK
+#endif
+
+
+ .text
+
+ .globl __pthread_rwlock_rdlock
+ .type __pthread_rwlock_rdlock,@function
+ .align 16
+__pthread_rwlock_rdlock:
+ pushl %esi
+ pushl %ebx
+
+ xorl %esi, %esi
+ movl 12(%esp), %ebx
+
+ /* Get the lock. */
+ movl $1, %edx
+ xorl %eax, %eax
+ LOCK
+#if MUTEX == 0
+ cmpxchgl %edx, (%ebx)
+#else
+ cmpxchgl %edx, MUTEX(%ebx)
+#endif
+ jnz 1f
+
+2: movl WRITER(%ebx), %eax
+ testl %eax, %eax
+ jne 14f
+ cmpl $0, WRITERS_QUEUED(%ebx)
+ je 5f
+ cmpl $0, FLAGS(%ebx)
+ je 5f
+
+3: addl $1, READERS_QUEUED(%ebx)
+ je 4f
+
+ movl READERS_WAKEUP(%ebx), %edx
+
+ LOCK
+#if MUTEX == 0
+ subl $1, (%ebx)
+#else
+ subl $1, MUTEX(%ebx)
+#endif
+ jne 10f
+
+11: addl $READERS_WAKEUP, %ebx
+ movl %esi, %ecx /* movl $FUTEX_WAIT, %ecx */
+ movl $SYS_futex, %eax
+ ENTER_KERNEL
+
+ subl $READERS_WAKEUP, %ebx
+
+ /* Reget the lock. */
+ movl $1, %edx
+ xorl %eax, %eax
+ LOCK
+#if MUTEX == 0
+ cmpxchgl %edx, (%ebx)
+#else
+ cmpxchgl %edx, MUTEX(%ebx)
+#endif
+ jnz 12f
+
+13: subl $1, READERS_QUEUED(%ebx)
+ jmp 2b
+
+5: xorl %ecx, %ecx
+ addl $1, NR_READERS(%ebx)
+ je 8f
+9: LOCK
+#if MUTEX == 0
+ subl $1, (%ebx)
+#else
+ subl $1, MUTEX(%ebx)
+#endif
+ jne 6f
+7:
+
+ movl %ecx, %eax
+ popl %ebx
+ popl %esi
+ ret
+
+1:
+#if MUTEX == 0
+ movl %ebx, %ecx
+#else
+ leal MUTEX(%ebx), %ecx
+#endif
+ call __lll_mutex_lock_wait
+ jmp 2b
+
+14: cmpl %gs:TID, %eax
+ jne 3b
+ /* Deadlock detected. */
+ movl $EDEADLK, %ecx
+ jmp 9b
+
+6:
+#if MUTEX == 0
+ movl %ebx, %eax
+#else
+ leal MUTEX(%ebx), %eax
+#endif
+ call __lll_mutex_unlock_wake
+ jmp 7b
+
+ /* Overflow. */
+8: subl $1, NR_READERS(%ebx)
+ movl $EAGAIN, %ecx
+ jmp 9b
+
+ /* Overflow. */
+4: subl $1, READERS_QUEUED(%ebx)
+ movl $EAGAIN, %ecx
+ jmp 9b
+
+10:
+#if MUTEX == 0
+ movl %ebx, %eax
+#else
+ leal MUTEX(%ebx), %eax
+#endif
+ call __lll_mutex_unlock_wake
+ jmp 11b
+
+12:
+#if MUTEX == 0
+ movl %ebx, %ecx
+#else
+ leal MUTEX(%ebx), %ecx
+#endif
+ call __lll_mutex_lock_wait
+ jmp 13b
+ .size __pthread_rwlock_rdlock,.-__pthread_rwlock_rdlock
+
+ .globl pthread_rwlock_rdlock
+pthread_rwlock_rdlock = __pthread_rwlock_rdlock
+
+ .globl __pthread_rwlock_rdlock_internal
+__pthread_rwlock_rdlock_internal = __pthread_rwlock_rdlock
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S
new file mode 100644
index 000000000..eb5665b43
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S
@@ -0,0 +1,215 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <lowlevelrwlock.h>
+#include <pthread-errnos.h>
+
+
+#define SYS_gettimeofday __NR_gettimeofday
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+#ifndef UP
+# define LOCK lock
+#else
+# define LOCK
+#endif
+
+
+ .text
+
+ .globl pthread_rwlock_timedrdlock
+ .type pthread_rwlock_timedrdlock,@function
+ .align 16
+pthread_rwlock_timedrdlock:
+ pushl %esi
+ pushl %edi
+ pushl %ebx
+ pushl %ebp
+ subl $8, %esp
+
+ movl 28(%esp), %ebp
+ movl 32(%esp), %edi
+
+ /* Get the lock. */
+ movl $1, %edx
+ xorl %eax, %eax
+ LOCK
+#if MUTEX == 0
+ cmpxchgl %edx, (%ebp)
+#else
+ cmpxchgl %edx, MUTEX(%ebp)
+#endif
+ jnz 1f
+
+2: movl WRITER(%ebp), %eax
+ testl %eax, %eax
+ jne 14f
+ cmpl $0, WRITERS_QUEUED(%ebp)
+ je 5f
+ cmpl $0, FLAGS(%ebp)
+ je 5f
+
+ /* Check the value of the timeout parameter. */
+3: cmpl $1000000000, 4(%edi)
+ jae 19f
+
+ addl $1, READERS_QUEUED(%ebp)
+ je 4f
+
+ movl READERS_WAKEUP(%ebp), %esi
+
+ LOCK
+#if MUTEX == 0
+ subl $1, (%ebp)
+#else
+ subl $1, MUTEX(%ebp)
+#endif
+ jne 10f
+
+ /* Get current time. */
+11: movl %esp, %ebx
+ xorl %ecx, %ecx
+ movl $SYS_gettimeofday, %eax
+ ENTER_KERNEL
+
+ /* Compute relative timeout. */
+ movl 4(%esp), %eax
+ movl $1000, %edx
+ mul %edx /* Milli seconds to nano seconds. */
+ movl (%edi), %ecx
+ movl 4(%edi), %edx
+ subl (%esp), %ecx
+ subl %eax, %edx
+ jns 15f
+ addl $1000000000, %edx
+ subl $1, %ecx
+15: testl %ecx, %ecx
+ js 16f /* Time is already up. */
+
+ /* Futex call. */
+ movl %ecx, (%esp) /* Store relative timeout. */
+ movl %edx, 4(%esp)
+ movl %esi, %edx
+ xorl %ecx, %ecx /* movl $FUTEX_WAIT, %ecx */
+ movl %esp, %esi
+ leal READERS_WAKEUP(%ebp), %ebx
+ movl $SYS_futex, %eax
+ ENTER_KERNEL
+ movl %eax, %ecx
+17:
+
+ /* Reget the lock. */
+ movl $1, %edx
+ xorl %eax, %eax
+ LOCK
+#if MUTEX == 0
+ cmpxchgl %edx, (%ebp)
+#else
+ cmpxchgl %edx, MUTEX(%ebp)
+#endif
+ jnz 12f
+
+13: subl $1, READERS_QUEUED(%ebp)
+ cmpl $-ETIMEDOUT, %ecx
+ jne 2b
+
+18: movl $ETIMEDOUT, %ecx
+ jmp 9f
+
+
+5: xorl %ecx, %ecx
+ addl $1, NR_READERS(%ebp)
+ je 8f
+9: LOCK
+#if MUTEX == 0
+ subl $1, (%ebp)
+#else
+ subl $1, MUTEX(%ebp)
+#endif
+ jne 6f
+
+7: movl %ecx, %eax
+
+ addl $8, %esp
+ popl %ebp
+ popl %ebx
+ popl %edi
+ popl %esi
+ ret
+
+1:
+#if MUTEX == 0
+ movl %ebp, %ecx
+#else
+ leal MUTEX(%ebp), %ecx
+#endif
+ call __lll_mutex_lock_wait
+ jmp 2b
+
+14: cmpl %gs:TID, %eax
+ jne 3b
+ movl $EDEADLK, %ecx
+ jmp 9b
+
+6:
+#if MUTEX == 0
+ movl %ebp, %eax
+#else
+ leal MUTEX(%ebp), %eax
+#endif
+ call __lll_mutex_unlock_wake
+ jmp 7b
+
+ /* Overflow. */
+8: subl $1, NR_READERS(%ebp)
+ movl $EAGAIN, %ecx
+ jmp 9b
+
+ /* Overflow. */
+4: subl $1, READERS_QUEUED(%ebp)
+ movl $EAGAIN, %ecx
+ jmp 9b
+
+10:
+#if MUTEX == 0
+ movl %ebp, %eax
+#else
+ leal MUTEX(%ebp), %eax
+#endif
+ call __lll_mutex_unlock_wake
+ jmp 11b
+
+12:
+#if MUTEX == 0
+ movl %ebp, %ecx
+#else
+ leal MUTEX(%ebp), %ecx
+#endif
+ call __lll_mutex_lock_wait
+ jmp 13b
+
+16: movl $-ETIMEDOUT, %ecx
+ jmp 17b
+
+19: movl $EINVAL, %ecx
+ jmp 9b
+ .size pthread_rwlock_timedrdlock,.-pthread_rwlock_timedrdlock
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S
new file mode 100644
index 000000000..d9db77ba0
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S
@@ -0,0 +1,208 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <lowlevelrwlock.h>
+#include <pthread-errnos.h>
+
+
+#define SYS_gettimeofday __NR_gettimeofday
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+#ifndef UP
+# define LOCK lock
+#else
+# define LOCK
+#endif
+
+
+ .text
+
+ .globl pthread_rwlock_timedwrlock
+ .type pthread_rwlock_timedwrlock,@function
+ .align 16
+pthread_rwlock_timedwrlock:
+ pushl %esi
+ pushl %edi
+ pushl %ebx
+ pushl %ebp
+ subl $8, %esp
+
+ movl 28(%esp), %ebp
+ movl 32(%esp), %edi
+
+ /* Get the lock. */
+ movl $1, %edx
+ xorl %eax, %eax
+ LOCK
+#if MUTEX == 0
+ cmpxchgl %edx, (%ebp)
+#else
+ cmpxchgl %edx, MUTEX(%ebp)
+#endif
+ jnz 1f
+
+2: movl WRITER(%ebp), %eax
+ testl %eax, %eax
+ jne 14f
+ cmpl $0, NR_READERS(%ebp)
+ je 5f
+
+ /* Check the value of the timeout parameter. */
+3: cmpl $1000000000, 4(%edi)
+ jae 19f
+
+ addl $1, WRITERS_QUEUED(%ebp)
+ je 4f
+
+ movl WRITERS_WAKEUP(%ebp), %esi
+
+ LOCK
+#if MUTEX == 0
+ subl $1, (%ebp)
+#else
+ subl $1, MUTEX(%ebp)
+#endif
+ jne 10f
+
+ /* Get current time. */
+11: movl %esp, %ebx
+ xorl %ecx, %ecx
+ movl $SYS_gettimeofday, %eax
+ ENTER_KERNEL
+
+ /* Compute relative timeout. */
+ movl 4(%esp), %eax
+ movl $1000, %edx
+ mul %edx /* Milli seconds to nano seconds. */
+ movl (%edi), %ecx
+ movl 4(%edi), %edx
+ subl (%esp), %ecx
+ subl %eax, %edx
+ jns 15f
+ addl $1000000000, %edx
+ subl $1, %ecx
+15: testl %ecx, %ecx
+ js 16f /* Time is already up. */
+
+ /* Futex call. */
+ movl %ecx, (%esp) /* Store relative timeout. */
+ movl %edx, 4(%esp)
+ movl %esi, %edx
+ xorl %ecx, %ecx /* movl $FUTEX_WAIT, %ecx */
+ movl %esp, %esi
+ leal WRITERS_WAKEUP(%ebp), %ebx
+ movl $SYS_futex, %eax
+ ENTER_KERNEL
+ movl %eax, %ecx
+17:
+
+ /* Reget the lock. */
+ movl $1, %edx
+ xorl %eax, %eax
+ LOCK
+#if MUTEX == 0
+ cmpxchgl %edx, (%ebp)
+#else
+ cmpxchgl %edx, MUTEX(%ebp)
+#endif
+ jnz 12f
+
+13: subl $1, WRITERS_QUEUED(%ebp)
+ cmpl $-ETIMEDOUT, %ecx
+ jne 2b
+
+18: movl $ETIMEDOUT, %ecx
+ jmp 9f
+
+
+5: xorl %ecx, %ecx
+ movl %gs:TID, %eax
+ movl %eax, WRITER(%ebp)
+9: LOCK
+#if MUTEX == 0
+ subl $1, (%ebp)
+#else
+ subl $1, MUTEX(%ebp)
+#endif
+ jne 6f
+
+7: movl %ecx, %eax
+
+ addl $8, %esp
+ popl %ebp
+ popl %ebx
+ popl %edi
+ popl %esi
+ ret
+
+1:
+#if MUTEX == 0
+ movl %ebp, %ecx
+#else
+ leal MUTEX(%ebp), %ecx
+#endif
+ call __lll_mutex_lock_wait
+ jmp 2b
+
+14: cmpl %gs:TID, %eax
+ jne 3b
+20: movl $EDEADLK, %ecx
+ jmp 9b
+
+6:
+#if MUTEX == 0
+ movl %ebp, %eax
+#else
+ leal MUTEX(%ebp), %eax
+#endif
+ call __lll_mutex_unlock_wake
+ jmp 7b
+
+ /* Overflow. */
+4: subl $1, WRITERS_QUEUED(%ebp)
+ movl $EAGAIN, %ecx
+ jmp 9b
+
+10:
+#if MUTEX == 0
+ movl %ebp, %eax
+#else
+ leal MUTEX(%ebp), %eax
+#endif
+ call __lll_mutex_unlock_wake
+ jmp 11b
+
+12:
+#if MUTEX == 0
+ movl %ebp, %ecx
+#else
+ leal MUTEX(%ebp), %ecx
+#endif
+ call __lll_mutex_lock_wait
+ jmp 13b
+
+16: movl $-ETIMEDOUT, %ecx
+ jmp 17b
+
+19: movl $EINVAL, %ecx
+ jmp 9b
+ .size pthread_rwlock_timedwrlock,.-pthread_rwlock_timedwrlock
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_unlock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_unlock.S
new file mode 100644
index 000000000..64aac3255
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_unlock.S
@@ -0,0 +1,141 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <lowlevelrwlock.h>
+
+
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+#ifndef UP
+# define LOCK lock
+#else
+# define LOCK
+#endif
+
+
+ .text
+
+ .globl __pthread_rwlock_unlock
+ .type __pthread_rwlock_unlock,@function
+ .align 16
+__pthread_rwlock_unlock:
+ pushl %ebx
+ pushl %edi
+
+ movl 12(%esp), %edi
+
+ /* Get the lock. */
+ movl $1, %edx
+ xorl %eax, %eax
+ LOCK
+#if MUTEX == 0
+ cmpxchgl %edx, (%edi)
+#else
+ cmpxchgl %edx, MUTEX(%edi)
+#endif
+ jnz 1f
+
+2: cmpl $0, WRITER(%edi)
+ jne 5f
+ subl $1, NR_READERS(%edi)
+ jnz 6f
+
+5: movl $0, WRITER(%edi)
+
+ movl $1, %ecx
+ leal WRITERS_WAKEUP(%edi), %ebx
+ movl %ecx, %edx
+ cmpl $0, WRITERS_QUEUED(%edi)
+ jne 0f
+
+ /* If also no readers waiting nothing to do. */
+ cmpl $0, READERS_QUEUED(%edi)
+ je 6f
+
+ movl $0x7fffffff, %edx
+ leal READERS_WAKEUP(%edi), %ebx
+
+0: addl $1, (%ebx)
+ LOCK
+#if MUTEX == 0
+ subl $1, (%edi)
+#else
+ subl $1, MUTEX(%edi)
+#endif
+ jne 7f
+
+8: movl $SYS_futex, %eax
+ ENTER_KERNEL
+
+ xorl %eax, %eax
+ popl %edi
+ popl %ebx
+ ret
+
+ .align 16
+6: LOCK
+#if MUTEX == 0
+ subl $1, (%edi)
+#else
+ subl $1, MUTEX(%edi)
+#endif
+ jne 3f
+
+4: xorl %eax, %eax
+ popl %edi
+ popl %ebx
+ ret
+
+1:
+#if MUTEX == 0
+ movl %edi, %ecx
+#else
+ leal MUTEX(%edx), %ecx
+#endif
+ call __lll_mutex_lock_wait
+ jmp 2b
+
+3:
+#if MUTEX == 0
+ movl %edi, %eax
+#else
+ leal MUTEX(%edx), %eax
+#endif
+ call __lll_mutex_unlock_wake
+ jmp 4b
+
+7:
+#if MUTEX == 0
+ movl %edi, %eax
+#else
+ leal MUTEX(%edx), %eax
+#endif
+ call __lll_mutex_unlock_wake
+ jmp 8b
+
+ .size __pthread_rwlock_unlock,.-__pthread_rwlock_unlock
+
+ .globl pthread_rwlock_unlock
+pthread_rwlock_unlock = __pthread_rwlock_unlock
+
+ .globl __pthread_rwlock_unlock_internal
+__pthread_rwlock_unlock_internal = __pthread_rwlock_unlock
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_wrlock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_wrlock.S
new file mode 100644
index 000000000..ea9cc170d
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_wrlock.S
@@ -0,0 +1,166 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <lowlevelrwlock.h>
+#include <pthread-errnos.h>
+
+
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+#ifndef UP
+# define LOCK lock
+#else
+# define LOCK
+#endif
+
+
+ .text
+
+ .globl __pthread_rwlock_wrlock
+ .type __pthread_rwlock_wrlock,@function
+ .align 16
+__pthread_rwlock_wrlock:
+ pushl %esi
+ pushl %ebx
+
+ xorl %esi, %esi
+ movl 12(%esp), %ebx
+
+ /* Get the lock. */
+ movl $1, %edx
+ xorl %eax, %eax
+ LOCK
+#if MUTEX == 0
+ cmpxchgl %edx, (%ebx)
+#else
+ cmpxchgl %edx, MUTEX(%ebx)
+#endif
+ jnz 1f
+
+2: movl WRITER(%ebx), %eax
+ testl %eax, %eax
+ jne 14f
+ cmpl $0, NR_READERS(%ebx)
+ je 5f
+
+3: addl $1, WRITERS_QUEUED(%ebx)
+ je 4f
+
+ movl WRITERS_WAKEUP(%ebx), %edx
+
+ LOCK
+#if MUTEX == 0
+ subl $1, (%ebx)
+#else
+ subl $1, MUTEX(%ebx)
+#endif
+ jne 10f
+
+11: addl $WRITERS_WAKEUP, %ebx
+ movl %esi, %ecx /* movl $FUTEX_WAIT, %ecx */
+ movl $SYS_futex, %eax
+ ENTER_KERNEL
+
+ subl $WRITERS_WAKEUP, %ebx
+
+ /* Reget the lock. */
+ movl $1, %edx
+ xorl %eax, %eax
+ LOCK
+#if MUTEX == 0
+ cmpxchgl %edx, (%ebx)
+#else
+ cmpxchgl %edx, MUTEX(%ebx)
+#endif
+ jnz 12f
+
+13: subl $1, WRITERS_QUEUED(%ebx)
+ jmp 2b
+
+5: xorl %ecx, %ecx
+ movl %gs:TID, %eax
+ movl %eax, WRITER(%ebx)
+9: LOCK
+#if MUTEX == 0
+ subl $1, (%ebx)
+#else
+ subl $1, MUTEX(%ebx)
+#endif
+ jne 6f
+7:
+
+ movl %ecx, %eax
+ popl %ebx
+ popl %esi
+ ret
+
+1:
+#if MUTEX == 0
+ movl %ebx, %ecx
+#else
+ leal MUTEX(%ebx), %ecx
+#endif
+ call __lll_mutex_lock_wait
+ jmp 2b
+
+14: cmpl %gs:TID , %eax
+ jne 3b
+ movl $EDEADLK, %ecx
+ jmp 9b
+
+6:
+#if MUTEX == 0
+ movl %ebx, %eax
+#else
+ leal MUTEX(%ebx), %eax
+#endif
+ call __lll_mutex_unlock_wake
+ jmp 7b
+
+4: subl $1, WRITERS_QUEUED(%ebx)
+ movl $EAGAIN, %ecx
+ jmp 9b
+
+10:
+#if MUTEX == 0
+ movl %ebx, %eax
+#else
+ leal MUTEX(%ebx), %eax
+#endif
+ call __lll_mutex_unlock_wake
+ jmp 11b
+
+12:
+#if MUTEX == 0
+ movl %ebx, %ecx
+#else
+ leal MUTEX(%ebx), %ecx
+#endif
+ call __lll_mutex_lock_wait
+ jmp 13b
+ .size __pthread_rwlock_wrlock,.-__pthread_rwlock_wrlock
+
+ .globl pthread_rwlock_wrlock
+pthread_rwlock_wrlock = __pthread_rwlock_wrlock
+
+ .globl __pthread_rwlock_wrlock_internal
+__pthread_rwlock_wrlock_internal = __pthread_rwlock_wrlock
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_post.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_post.S
new file mode 100644
index 000000000..71e96d222
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_post.S
@@ -0,0 +1,102 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <pthread-errnos.h>
+
+#ifndef UP
+# define LOCK lock
+#else
+# define
+#endif
+
+#define SYS_futex 240
+#define FUTEX_WAKE 1
+
+
+ .text
+
+ .globl __new_sem_post
+ .type __new_sem_post,@function
+ .align 16
+__new_sem_post:
+ pushl %ebx
+
+ movl 8(%esp), %ebx
+ movl $1, %edx
+ LOCK
+ xaddl %edx, (%ebx)
+
+ movl $SYS_futex, %eax
+ movl $FUTEX_WAKE, %ecx
+ addl $1, %edx
+ ENTER_KERNEL
+
+ testl %eax, %eax
+ js 1f
+
+ xorl %eax, %eax
+ popl %ebx
+ ret
+
+1:
+#ifdef PIC
+ call __i686.get_pc_thunk.bx
+#else
+ movl $4f, %ebx
+4:
+#endif
+ addl $_GLOBAL_OFFSET_TABLE_, %ebx
+#if USE___THREAD
+# ifdef NO_TLS_DIRECT_SEG_REFS
+ movl errno@gotntpoff(%ebx), %edx
+ addl %gs:0, %edx
+ movl $EINVAL, (%edx)
+# else
+ movl errno@gotntpoff(%ebx), %edx
+ movl $EINVAL, %gs:(%edx)
+# endif
+#else
+ call __errno_location@plt
+ movl $EINVAL, (%eax)
+#endif
+
+ orl $-1, %eax
+ popl %ebx
+ ret
+ .size __new_sem_post,.-__new_sem_post
+ versioned_symbol(libpthread, __new_sem_post, sem_post, GLIBC_2_1)
+#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1)
+ .global __old_sem_post
+__old_sem_post = __new_sem_post
+ compat_symbol(libpthread, __old_sem_post, sem_post, GLIBC_2_0)
+#endif
+
+
+#ifdef PIC
+ .section .gnu.linkonce.t.__i686.get_pc_thunk.bx,"ax",@progbits
+ .globl __i686.get_pc_thunk.bx
+ .hidden __i686.get_pc_thunk.bx
+ .type __i686.get_pc_thunk.bx,@function
+__i686.get_pc_thunk.bx:
+ movl (%esp), %ebx;
+ ret
+ .size __i686.get_pc_thunk.bx,.-__i686.get_pc_thunk.bx
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_timedwait.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_timedwait.S
new file mode 100644
index 000000000..aa1f9f41c
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_timedwait.S
@@ -0,0 +1,195 @@
+/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <pthread-errnos.h>
+
+#ifndef UP
+# define LOCK lock
+#else
+# define
+#endif
+
+#define SYS_gettimeofday __NR_gettimeofday
+#define SYS_futex 240
+#define FUTEX_WAKE 1
+
+
+ .text
+
+ .globl sem_timedwait
+ .type sem_timedwait,@function
+ .align 16
+ cfi_startproc
+sem_timedwait:
+ /* First check for cancellation. */
+ movl %gs:CANCELHANDLING, %eax
+ andl $0xfffffff9, %eax
+ cmpl $8, %eax
+ je 10f
+
+ movl 4(%esp), %ecx
+
+ movl (%ecx), %eax
+2: testl %eax, %eax
+ je 1f
+
+ leal -1(%eax), %edx
+ LOCK
+ cmpxchgl %edx, (%ecx)
+ jne 2b
+
+ xorl %eax, %eax
+ ret
+
+ /* Check whether the timeout value is valid. */
+1: pushl %esi
+ cfi_adjust_cfa_offset(4)
+ pushl %edi
+ cfi_adjust_cfa_offset(4)
+ pushl %ebx
+ cfi_adjust_cfa_offset(4)
+ subl $12, %esp
+ cfi_adjust_cfa_offset(12)
+
+ movl 32(%esp), %edi
+ cfi_offset(7, -12) /* %edi */
+
+ /* Check for invalid nanosecond field. */
+ cmpl $1000000000, 4(%edi)
+ movl $EINVAL, %esi
+ cfi_offset(6, -8) /* %esi */
+ jae 6f
+
+ cfi_offset(3, -16) /* %ebx */
+7: call __pthread_enable_asynccancel
+ movl %eax, 8(%esp)
+
+ xorl %ecx, %ecx
+ movl %esp, %ebx
+ movl %ecx, %edx
+ movl $SYS_gettimeofday, %eax
+ ENTER_KERNEL
+
+ /* Compute relative timeout. */
+ movl 4(%esp), %eax
+ movl $1000, %edx
+ mul %edx /* Milli seconds to nano seconds. */
+ movl (%edi), %ecx
+ movl 4(%edi), %edx
+ subl (%esp), %ecx
+ subl %eax, %edx
+ jns 5f
+ addl $1000000000, %edx
+ subl $1, %ecx
+5: testl %ecx, %ecx
+ movl $ETIMEDOUT, %esi
+ js 6f /* Time is already up. */
+
+ movl %ecx, (%esp) /* Store relative timeout. */
+ movl %edx, 4(%esp)
+ movl 28(%esp), %ebx
+ xorl %ecx, %ecx
+ movl %esp, %esi
+ movl $SYS_futex, %eax
+ xorl %edx, %edx
+ ENTER_KERNEL
+ movl %eax, %esi
+
+ movl 8(%esp), %eax
+ call __pthread_disable_asynccancel
+
+ testl %esi, %esi
+ je 9f
+ cmpl $-EWOULDBLOCK, %esi
+ jne 3f
+
+9: movl (%ebx), %eax
+8: testl %eax, %eax
+ je 7b
+
+ leal -1(%eax), %ecx
+ LOCK
+ cmpxchgl %ecx, (%ebx)
+ jne 8b
+
+ addl $12, %esp
+ cfi_adjust_cfa_offset(-12)
+ xorl %eax, %eax
+ popl %ebx
+ cfi_adjust_cfa_offset(-4)
+ cfi_restore(3)
+ popl %edi
+ cfi_adjust_cfa_offset(-4)
+ cfi_restore(7)
+ popl %esi
+ cfi_adjust_cfa_offset(-4)
+ cfi_restore(6)
+ ret
+
+ cfi_adjust_cfa_offset(24)
+ cfi_offset(6, -8) /* %esi */
+ cfi_offset(7, -12) /* %edi */
+ cfi_offset(3, -16) /* %ebx */
+3: negl %esi
+6:
+#ifdef PIC
+ call __i686.get_pc_thunk.bx
+#else
+ movl $4f, %ebx
+4:
+#endif
+ addl $_GLOBAL_OFFSET_TABLE_, %ebx
+#if USE___THREAD
+# ifdef NO_TLS_DIRECT_SEG_REFS
+ movl errno@gotntpoff(%ebx), %edx
+ addl %gs:0, %edx
+ movl %esi, (%edx)
+# else
+ movl errno@gotntpoff(%ebx), %edx
+ movl %esi, %gs:(%edx)
+# endif
+#else
+ call __errno_location@plt
+ movl %esi, (%eax)
+#endif
+
+ addl $12, %esp
+ cfi_adjust_cfa_offset(-12)
+ orl $-1, %eax
+ popl %ebx
+ cfi_adjust_cfa_offset(-4)
+ cfi_restore(3)
+ popl %edi
+ cfi_adjust_cfa_offset(-4)
+ cfi_restore(7)
+ popl %esi
+ cfi_adjust_cfa_offset(-4)
+ cfi_restore(6)
+ ret
+
+10: /* Canceled. */
+ movl $0xffffffff, %gs:RESULT
+ LOCK
+ orl $0x10, %gs:CANCELHANDLING
+ movl %gs:CLEANUP_JMP_BUF, %eax
+ jmp HIDDEN_JUMPTARGET (__pthread_unwind)
+ cfi_endproc
+ .size sem_timedwait,.-sem_timedwait
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_trywait.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_trywait.S
new file mode 100644
index 000000000..fbc3b3c93
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_trywait.S
@@ -0,0 +1,90 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <pthread-errnos.h>
+
+#ifndef UP
+# define LOCK lock
+#else
+# define
+#endif
+
+ .text
+
+ .globl __new_sem_trywait
+ .type __new_sem_trywait,@function
+ .align 16
+__new_sem_trywait:
+ movl 4(%esp), %ecx
+
+ movl (%ecx), %eax
+2: testl %eax, %eax
+ jz 1f
+
+ leal -1(%eax), %edx
+ LOCK
+ cmpxchgl %edx, (%ecx)
+ jne 2b
+ xorl %eax, %eax
+ ret
+
+1:
+#ifdef PIC
+ call __i686.get_pc_thunk.cx
+#else
+ movl $3f, %ecx
+3:
+#endif
+ addl $_GLOBAL_OFFSET_TABLE_, %ecx
+#if USE___THREAD
+# ifdef NO_TLS_DIRECT_SEG_REFS
+ movl errno@gotntpoff(%ecx), %edx
+ addl %gs:0, %edx
+ movl $EAGAIN, (%edx)
+# else
+ movl errno@gotntpoff(%ecx), %edx
+ movl $EAGAIN, %gs:(%edx)
+# endif
+#else
+ call __errno_location@plt
+ movl $EAGAIN, (%eax)
+#endif
+ orl $-1, %eax
+ ret
+ .size __new_sem_trywait,.-__new_sem_trywait
+ versioned_symbol(libpthread, __new_sem_trywait, sem_trywait, GLIBC_2_1)
+#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1)
+ .global __old_sem_trywait
+__old_sem_trywait = __new_sem_trywait
+ compat_symbol(libpthread, __old_sem_trywait, sem_trywait, GLIBC_2_0)
+#endif
+
+
+#ifdef PIC
+ .section .gnu.linkonce.t.__i686.get_pc_thunk.cx,"ax",@progbits
+ .globl __i686.get_pc_thunk.cx
+ .hidden __i686.get_pc_thunk.cx
+ .type __i686.get_pc_thunk.cx,@function
+__i686.get_pc_thunk.cx:
+ movl (%esp), %ecx;
+ ret
+ .size __i686.get_pc_thunk.cx,.-__i686.get_pc_thunk.cx
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_wait.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_wait.S
new file mode 100644
index 000000000..b1296275d
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i486/sem_wait.S
@@ -0,0 +1,139 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <pthread-errnos.h>
+
+#ifndef UP
+# define LOCK lock
+#else
+# define
+#endif
+
+#define SYS_futex 240
+#define FUTEX_WAKE 1
+
+
+ .text
+
+ .globl __new_sem_wait
+ .type __new_sem_wait,@function
+ .align 16
+ cfi_startproc
+__new_sem_wait:
+ /* First check for cancellation. */
+ movl %gs:CANCELHANDLING, %eax
+ andl $0xfffffff9, %eax
+ cmpl $8, %eax
+ je 5f
+
+ pushl %ebx
+ cfi_adjust_cfa_offset(4)
+ pushl %esi
+ cfi_adjust_cfa_offset(4)
+ subl $4, %esp
+ cfi_adjust_cfa_offset(4)
+
+ movl 16(%esp), %ebx
+ cfi_offset(3, -8) /* %ebx */
+
+ cfi_offset(6, -12) /* %esi */
+3: movl (%ebx), %eax
+2: testl %eax, %eax
+ je 1f
+
+ leal -1(%eax), %edx
+ LOCK
+ cmpxchgl %edx, (%ebx)
+ jne 2b
+ xorl %eax, %eax
+
+ movl 4(%esp), %esi
+ cfi_restore(6)
+ movl 8(%esp), %ebx
+ cfi_restore(3)
+ addl $12, %esp
+ cfi_adjust_cfa_offset(-12)
+ ret
+
+ cfi_adjust_cfa_offset(12)
+ cfi_offset(3, -8) /* %ebx */
+ cfi_offset(6, -12) /* %esi */
+1: call __pthread_enable_asynccancel
+ movl %eax, (%esp)
+
+ xorl %esi, %esi
+ movl $SYS_futex, %eax
+ movl %esi, %ecx
+ movl %esi, %edx
+ ENTER_KERNEL
+ movl %eax, %esi
+
+ movl (%esp), %eax
+ call __pthread_disable_asynccancel
+
+ testl %esi, %esi
+ je 3b
+ cmpl $-EWOULDBLOCK, %esi
+ je 3b
+ negl %esi
+#ifdef PIC
+ call __i686.get_pc_thunk.bx
+#else
+ movl $4f, %ebx
+4:
+#endif
+ addl $_GLOBAL_OFFSET_TABLE_, %ebx
+#if USE___THREAD
+# ifdef NO_TLS_DIRECT_SEG_REFS
+ movl errno@gotntpoff(%ebx), %edx
+ addl %gs:0, %edx
+ movl %esi, (%edx)
+# else
+ movl errno@gotntpoff(%ebx), %edx
+ movl %esi, %gs:(%edx)
+# endif
+#else
+ call __errno_location@plt
+ movl %esi, (%eax)
+#endif
+ orl $-1, %eax
+ movl 4(%esp), %esi
+ cfi_restore(6)
+ movl 8(%esp), %ebx
+ cfi_restore(3)
+ addl $12, %esp
+ cfi_adjust_cfa_offset(-12)
+ ret
+
+5: /* Canceled. */
+ movl $0xffffffff, %gs:RESULT
+ LOCK
+ orl $0x10, %gs:CANCELHANDLING
+ movl %gs:CLEANUP_JMP_BUF, %eax
+ jmp HIDDEN_JUMPTARGET (__pthread_unwind)
+ cfi_endproc
+ .size __new_sem_wait,.-__new_sem_wait
+ versioned_symbol(libpthread, __new_sem_wait, sem_wait, GLIBC_2_1)
+#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1)
+ .global __old_sem_wait
+__old_sem_wait = __new_sem_wait
+ compat_symbol(libpthread, __old_sem_wait, sem_wait, GLIBC_2_0)
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/libc-lowlevellock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/libc-lowlevellock.S
new file mode 100644
index 000000000..f567c1d6d
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/libc-lowlevellock.S
@@ -0,0 +1 @@
+#include "../i486/libc-lowlevellock.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/lowlevellock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/lowlevellock.S
new file mode 100644
index 000000000..e60dea89e
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/lowlevellock.S
@@ -0,0 +1,20 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "../i486/lowlevellock.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/lowlevelrobustlock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/lowlevelrobustlock.S
new file mode 100644
index 000000000..f768e16a7
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/lowlevelrobustlock.S
@@ -0,0 +1,20 @@
+/* Copyright (C) 2002, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "../i486/lowlevelrobustlock.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_barrier_wait.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_barrier_wait.S
new file mode 100644
index 000000000..6d20b9a95
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_barrier_wait.S
@@ -0,0 +1,20 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "../i486/pthread_barrier_wait.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_broadcast.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_broadcast.S
new file mode 100644
index 000000000..5e1024eab
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_broadcast.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/pthread_cond_broadcast.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_signal.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_signal.S
new file mode 100644
index 000000000..da4e8cbab
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_signal.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/pthread_cond_signal.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_timedwait.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_timedwait.S
new file mode 100644
index 000000000..c0131555b
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_timedwait.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/pthread_cond_timedwait.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_wait.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_wait.S
new file mode 100644
index 000000000..9b57fbaca
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_wait.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/pthread_cond_wait.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_rdlock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_rdlock.S
new file mode 100644
index 000000000..da2bc4704
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_rdlock.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/pthread_rwlock_rdlock.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_timedrdlock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_timedrdlock.S
new file mode 100644
index 000000000..0f2ec168b
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_timedrdlock.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/pthread_rwlock_timedrdlock.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_timedwrlock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_timedwrlock.S
new file mode 100644
index 000000000..26501590a
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_timedwrlock.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/pthread_rwlock_timedwrlock.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_unlock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_unlock.S
new file mode 100644
index 000000000..5515e4895
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_unlock.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/pthread_rwlock_unlock.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_wrlock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_wrlock.S
new file mode 100644
index 000000000..04ac275f6
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/pthread_rwlock_wrlock.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/pthread_rwlock_wrlock.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/sem_post.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/sem_post.S
new file mode 100644
index 000000000..7317e1582
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/sem_post.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/sem_post.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/sem_timedwait.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/sem_timedwait.S
new file mode 100644
index 000000000..f34539d56
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/sem_timedwait.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/sem_timedwait.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/sem_trywait.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/sem_trywait.S
new file mode 100644
index 000000000..64145c2e3
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/sem_trywait.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/sem_trywait.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/sem_wait.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/sem_wait.S
new file mode 100644
index 000000000..b3d462125
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i586/sem_wait.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/sem_wait.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/dl-sysdep.h b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/dl-sysdep.h
new file mode 100644
index 000000000..b7771318a
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/dl-sysdep.h
@@ -0,0 +1,61 @@
+/* System-specific settings for dynamic linker code. IA-32 version.
+ Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+#ifndef _DL_SYSDEP_H
+#define _DL_SYSDEP_H 1
+
+/* This macro must be defined to either 0 or 1.
+
+ If 1, then an errno global variable hidden in ld.so will work right with
+ all the errno-using libc code compiled for ld.so, and there is never a
+ need to share the errno location with libc. This is appropriate only if
+ all the libc functions that ld.so uses are called without PLT and always
+ get the versions linked into ld.so rather than the libc ones. */
+
+#ifdef IS_IN_rtld
+# define RTLD_PRIVATE_ERRNO 1
+#else
+# define RTLD_PRIVATE_ERRNO 0
+#endif
+
+/* Traditionally system calls have been made using int $0x80. A
+ second method was introduced which, if possible, will use the
+ sysenter/syscall instructions. To signal the presence and where to
+ find the code the kernel passes an AT_SYSINFO value in the
+ auxiliary vector to the application. */
+#define NEED_DL_SYSINFO 1
+#define USE_DL_SYSINFO 1
+
+#if defined NEED_DL_SYSINFO && !defined __ASSEMBLER__
+extern void _dl_sysinfo_int80 (void) attribute_hidden;
+# define DL_SYSINFO_DEFAULT (uintptr_t) _dl_sysinfo_int80
+# define DL_SYSINFO_IMPLEMENTATION \
+ asm (".text\n\t" \
+ ".type _dl_sysinfo_int80,@function\n\t" \
+ ".hidden _dl_sysinfo_int80\n" \
+ CFI_STARTPROC "\n" \
+ "_dl_sysinfo_int80:\n\t" \
+ "int $0x80;\n\t" \
+ "ret;\n\t" \
+ CFI_ENDPROC "\n" \
+ ".size _dl_sysinfo_int80,.-_dl_sysinfo_int80\n\t" \
+ ".previous");
+#endif
+
+#endif /* dl-sysdep.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/libc-lowlevellock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/libc-lowlevellock.S
new file mode 100644
index 000000000..f567c1d6d
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/libc-lowlevellock.S
@@ -0,0 +1 @@
+#include "../i486/libc-lowlevellock.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/lowlevellock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/lowlevellock.S
new file mode 100644
index 000000000..e60dea89e
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/lowlevellock.S
@@ -0,0 +1,20 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "../i486/lowlevellock.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/lowlevelrobustlock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/lowlevelrobustlock.S
new file mode 100644
index 000000000..f768e16a7
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/lowlevelrobustlock.S
@@ -0,0 +1,20 @@
+/* Copyright (C) 2002, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "../i486/lowlevelrobustlock.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_barrier_wait.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_barrier_wait.S
new file mode 100644
index 000000000..6d20b9a95
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_barrier_wait.S
@@ -0,0 +1,20 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 "../i486/pthread_barrier_wait.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_broadcast.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_broadcast.S
new file mode 100644
index 000000000..5e1024eab
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_broadcast.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/pthread_cond_broadcast.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_signal.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_signal.S
new file mode 100644
index 000000000..da4e8cbab
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_signal.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/pthread_cond_signal.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_timedwait.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_timedwait.S
new file mode 100644
index 000000000..07d481f37
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_timedwait.S
@@ -0,0 +1,21 @@
+/* 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. */
+
+#define HAVE_CMOV 1
+#include "../i486/pthread_cond_timedwait.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_wait.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_wait.S
new file mode 100644
index 000000000..9b57fbaca
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_wait.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/pthread_cond_wait.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_rdlock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_rdlock.S
new file mode 100644
index 000000000..da2bc4704
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_rdlock.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/pthread_rwlock_rdlock.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_timedrdlock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_timedrdlock.S
new file mode 100644
index 000000000..0f2ec168b
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_timedrdlock.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/pthread_rwlock_timedrdlock.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_timedwrlock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_timedwrlock.S
new file mode 100644
index 000000000..26501590a
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_timedwrlock.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/pthread_rwlock_timedwrlock.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_unlock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_unlock.S
new file mode 100644
index 000000000..0894f0546
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_unlock.S
@@ -0,0 +1,21 @@
+/* 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. */
+
+#define HAVE_CMOV 1
+#include "../i486/pthread_rwlock_unlock.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_wrlock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_wrlock.S
new file mode 100644
index 000000000..04ac275f6
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/pthread_rwlock_wrlock.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/pthread_rwlock_wrlock.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/sem_post.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/sem_post.S
new file mode 100644
index 000000000..7317e1582
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/sem_post.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/sem_post.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/sem_timedwait.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/sem_timedwait.S
new file mode 100644
index 000000000..f34539d56
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/sem_timedwait.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/sem_timedwait.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/sem_trywait.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/sem_trywait.S
new file mode 100644
index 000000000..64145c2e3
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/sem_trywait.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/sem_trywait.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/sem_wait.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/sem_wait.S
new file mode 100644
index 000000000..b3d462125
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/i686/sem_wait.S
@@ -0,0 +1,20 @@
+/* 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 "../i486/sem_wait.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/lowlevellock.h b/libc/nptl/sysdeps/unix/sysv/linux/i386/lowlevellock.h
new file mode 100644
index 000000000..ac788ebe5
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/lowlevellock.h
@@ -0,0 +1,512 @@
+/* Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+#ifndef _LOWLEVELLOCK_H
+#define _LOWLEVELLOCK_H 1
+
+#include <time.h>
+#include <sys/param.h>
+#include <bits/pthreadtypes.h>
+
+#ifndef LOCK_INSTR
+# ifdef UP
+# define LOCK_INSTR /* nothing */
+# else
+# define LOCK_INSTR "lock;"
+# endif
+#endif
+
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+#define FUTEX_LOCK_PI 6
+#define FUTEX_UNLOCK_PI 7
+#define FUTEX_TRYLOCK_PI 8
+
+
+/* Initializer for compatibility lock. */
+#define LLL_MUTEX_LOCK_INITIALIZER (0)
+#define LLL_MUTEX_LOCK_INITIALIZER_LOCKED (1)
+#define LLL_MUTEX_LOCK_INITIALIZER_WAITERS (2)
+
+
+#ifdef PIC
+# define LLL_EBX_LOAD "xchgl %2, %%ebx\n"
+# define LLL_EBX_REG "D"
+#else
+# define LLL_EBX_LOAD
+# define LLL_EBX_REG "b"
+#endif
+
+#ifdef I386_USE_SYSENTER
+# ifdef SHARED
+# define LLL_ENTER_KERNEL "call *%%gs:%P6\n\t"
+# else
+# define LLL_ENTER_KERNEL "call *_dl_sysinfo\n\t"
+# endif
+#else
+# define LLL_ENTER_KERNEL "int $0x80\n\t"
+#endif
+
+/* Delay in spinlock loop. */
+#define BUSY_WAIT_NOP asm ("rep; nop")
+
+
+#define lll_futex_wait(futex, val) \
+ ({ \
+ int __status; \
+ register __typeof (val) _val asm ("edx") = (val); \
+ __asm __volatile (LLL_EBX_LOAD \
+ LLL_ENTER_KERNEL \
+ LLL_EBX_LOAD \
+ : "=a" (__status) \
+ : "0" (SYS_futex), LLL_EBX_REG (futex), "S" (0), \
+ "c" (FUTEX_WAIT), "d" (_val), \
+ "i" (offsetof (tcbhead_t, sysinfo)) \
+ : "memory"); \
+ __status; \
+ })
+
+
+#define lll_futex_timed_wait(futex, val, timeout) \
+ ({ \
+ int __status; \
+ register __typeof (val) _val asm ("edx") = (val); \
+ __asm __volatile (LLL_EBX_LOAD \
+ LLL_ENTER_KERNEL \
+ LLL_EBX_LOAD \
+ : "=a" (__status) \
+ : "0" (SYS_futex), LLL_EBX_REG (futex), "S" (timeout), \
+ "c" (FUTEX_WAIT), "d" (_val), \
+ "i" (offsetof (tcbhead_t, sysinfo)) \
+ : "memory"); \
+ __status; \
+ })
+
+
+#define lll_futex_wake(futex, nr) \
+ do { \
+ int __ignore; \
+ register __typeof (nr) _nr asm ("edx") = (nr); \
+ __asm __volatile (LLL_EBX_LOAD \
+ LLL_ENTER_KERNEL \
+ LLL_EBX_LOAD \
+ : "=a" (__ignore) \
+ : "0" (SYS_futex), LLL_EBX_REG (futex), \
+ "c" (FUTEX_WAKE), "d" (_nr), \
+ "i" (0) /* phony, to align next arg's number */, \
+ "i" (offsetof (tcbhead_t, sysinfo))); \
+ } while (0)
+
+
+/* Does not preserve %eax and %ecx. */
+extern int __lll_mutex_lock_wait (int val, int *__futex)
+ __attribute ((regparm (2))) attribute_hidden;
+/* Does not preserve %eax, %ecx, and %edx. */
+extern int __lll_mutex_timedlock_wait (int val, int *__futex,
+ const struct timespec *abstime)
+ __attribute ((regparm (3))) attribute_hidden;
+/* Preserves all registers but %eax. */
+extern int __lll_mutex_unlock_wake (int *__futex)
+ __attribute ((regparm (1))) attribute_hidden;
+
+
+/* NB: in the lll_mutex_trylock macro we simply return the value in %eax
+ after the cmpxchg instruction. In case the operation succeded this
+ value is zero. In case the operation failed, the cmpxchg instruction
+ has loaded the current value of the memory work which is guaranteed
+ to be nonzero. */
+#define lll_mutex_trylock(futex) \
+ ({ int ret; \
+ __asm __volatile (LOCK_INSTR "cmpxchgl %2, %1" \
+ : "=a" (ret), "=m" (futex) \
+ : "r" (LLL_MUTEX_LOCK_INITIALIZER_LOCKED), "m" (futex),\
+ "0" (LLL_MUTEX_LOCK_INITIALIZER) \
+ : "memory"); \
+ ret; })
+
+
+#define lll_robust_mutex_trylock(futex, id) \
+ ({ int ret; \
+ __asm __volatile (LOCK_INSTR "cmpxchgl %2, %1" \
+ : "=a" (ret), "=m" (futex) \
+ : "r" (id), "m" (futex), \
+ "0" (LLL_MUTEX_LOCK_INITIALIZER) \
+ : "memory"); \
+ ret; })
+
+
+#define lll_mutex_cond_trylock(futex) \
+ ({ int ret; \
+ __asm __volatile (LOCK_INSTR "cmpxchgl %2, %1" \
+ : "=a" (ret), "=m" (futex) \
+ : "r" (LLL_MUTEX_LOCK_INITIALIZER_WAITERS), \
+ "m" (futex), "0" (LLL_MUTEX_LOCK_INITIALIZER) \
+ : "memory"); \
+ ret; })
+
+
+#define lll_mutex_lock(futex) \
+ (void) ({ int ignore1, ignore2; \
+ __asm __volatile (LOCK_INSTR "cmpxchgl %1, %2\n\t" \
+ "jnz _L_mutex_lock_%=\n\t" \
+ ".subsection 1\n\t" \
+ ".type _L_mutex_lock_%=,@function\n" \
+ "_L_mutex_lock_%=:\n\t" \
+ "leal %2, %%ecx\n\t" \
+ "call __lll_mutex_lock_wait\n\t" \
+ "jmp 1f\n\t" \
+ ".size _L_mutex_lock_%=,.-_L_mutex_lock_%=\n" \
+ ".previous\n" \
+ "1:" \
+ : "=a" (ignore1), "=c" (ignore2), "=m" (futex) \
+ : "0" (0), "1" (1), "m" (futex) \
+ : "memory"); })
+
+
+#define lll_robust_mutex_lock(futex, id) \
+ ({ int result, ignore; \
+ __asm __volatile (LOCK_INSTR "cmpxchgl %1, %2\n\t" \
+ "jnz _L_mutex_lock_%=\n\t" \
+ ".subsection 1\n\t" \
+ ".type _L_mutex_lock_%=,@function\n" \
+ "_L_mutex_lock_%=:\n\t" \
+ "leal %2, %%ecx\n\t" \
+ "call __lll_robust_mutex_lock_wait\n\t" \
+ "jmp 1f\n\t" \
+ ".size _L_mutex_lock_%=,.-_L_mutex_lock_%=\n" \
+ ".previous\n" \
+ "1:" \
+ : "=a" (result), "=c" (ignore), "=m" (futex) \
+ : "0" (0), "1" (id), "m" (futex) \
+ : "memory"); \
+ result; })
+
+
+/* Special version of lll_mutex_lock which causes the unlock function to
+ always wakeup waiters. */
+#define lll_mutex_cond_lock(futex) \
+ (void) ({ int ignore1, ignore2; \
+ __asm __volatile (LOCK_INSTR "cmpxchgl %1, %2\n\t" \
+ "jnz _L_mutex_cond_lock_%=\n\t" \
+ ".subsection 1\n\t" \
+ ".type _L_mutex_cond_lock_%=,@function\n" \
+ "_L_mutex_cond_lock_%=:\n\t" \
+ "leal %2, %%ecx\n\t" \
+ "call __lll_mutex_lock_wait\n\t" \
+ "jmp 1f\n\t" \
+ ".size _L_mutex_cond_lock_%=,.-_L_mutex_cond_lock_%=\n" \
+ ".previous\n" \
+ "1:" \
+ : "=a" (ignore1), "=c" (ignore2), "=m" (futex) \
+ : "0" (0), "1" (2), "m" (futex) \
+ : "memory"); })
+
+
+#define lll_robust_mutex_cond_lock(futex, id) \
+ ({ int result, ignore; \
+ __asm __volatile (LOCK_INSTR "cmpxchgl %1, %2\n\t" \
+ "jnz _L_mutex_cond_lock_%=\n\t" \
+ ".subsection 1\n\t" \
+ ".type _L_mutex_cond_lock_%=,@function\n" \
+ "_L_mutex_cond_lock_%=:\n\t" \
+ "leal %2, %%ecx\n\t" \
+ "call __lll_robust_mutex_lock_wait\n\t" \
+ "jmp 1f\n\t" \
+ ".size _L_mutex_cond_lock_%=,.-_L_mutex_cond_lock_%=\n"\
+ ".previous\n" \
+ "1:" \
+ : "=a" (result), "=c" (ignore), "=m" (futex) \
+ : "0" (0), "1" (id | FUTEX_WAITERS), "m" (futex) \
+ : "memory"); \
+ result; })
+
+
+#define lll_mutex_timedlock(futex, timeout) \
+ ({ int result, ignore1, ignore2; \
+ __asm __volatile (LOCK_INSTR "cmpxchgl %1, %3\n\t" \
+ "jnz _L_mutex_timedlock_%=\n\t" \
+ ".subsection 1\n\t" \
+ ".type _L_mutex_timedlock_%=,@function\n" \
+ "_L_mutex_timedlock_%=:\n\t" \
+ "leal %3, %%ecx\n\t" \
+ "movl %7, %%edx\n\t" \
+ "call __lll_mutex_timedlock_wait\n\t" \
+ "jmp 1f\n\t" \
+ ".size _L_mutex_timedlock_%=,.-_L_mutex_timedlock_%=\n"\
+ ".previous\n" \
+ "1:" \
+ : "=a" (result), "=c" (ignore1), "=&d" (ignore2), \
+ "=m" (futex) \
+ : "0" (0), "1" (1), "m" (futex), "m" (timeout) \
+ : "memory"); \
+ result; })
+
+
+#define lll_robust_mutex_timedlock(futex, timeout, id) \
+ ({ int result, ignore1, ignore2; \
+ __asm __volatile (LOCK_INSTR "cmpxchgl %1, %3\n\t" \
+ "jnz _L_mutex_timedlock_%=\n\t" \
+ ".subsection 1\n\t" \
+ ".type _L_mutex_timedlock_%=,@function\n" \
+ "_L_mutex_timedlock_%=:\n\t" \
+ "leal %3, %%ecx\n\t" \
+ "movl %7, %%edx\n\t" \
+ "call __lll_robust_mutex_timedlock_wait\n\t" \
+ "jmp 1f\n\t" \
+ ".size _L_mutex_timedlock_%=,.-_L_mutex_timedlock_%=\n"\
+ ".previous\n" \
+ "1:" \
+ : "=a" (result), "=c" (ignore1), "=&d" (ignore2), \
+ "=m" (futex) \
+ : "0" (0), "1" (id), "m" (futex), "m" (timeout) \
+ : "memory"); \
+ result; })
+
+
+#define lll_mutex_unlock(futex) \
+ (void) ({ int ignore; \
+ __asm __volatile (LOCK_INSTR "subl $1, %0\n\t" \
+ "jne _L_mutex_unlock_%=\n\t" \
+ ".subsection 1\n\t" \
+ ".type _L_mutex_unlock_%=,@function\n" \
+ "_L_mutex_unlock_%=:\n\t" \
+ "leal %0, %%eax\n\t" \
+ "call __lll_mutex_unlock_wake\n\t" \
+ "jmp 1f\n\t" \
+ ".size _L_mutex_unlock_%=,.-_L_mutex_unlock_%=\n" \
+ ".previous\n" \
+ "1:" \
+ : "=m" (futex), "=&a" (ignore) \
+ : "m" (futex) \
+ : "memory"); })
+
+
+#define lll_robust_mutex_unlock(futex) \
+ (void) ({ int ignore; \
+ __asm __volatile (LOCK_INSTR "andl %2, %0\n\t" \
+ "jne _L_mutex_unlock_%=\n\t" \
+ ".subsection 1\n\t" \
+ ".type _L_mutex_unlock_%=,@function\n" \
+ "_L_mutex_unlock_%=:\n\t" \
+ "leal %0, %%eax\n\t" \
+ "call __lll_mutex_unlock_wake\n\t" \
+ "jmp 1f\n\t" \
+ ".size _L_mutex_unlock_%=,.-_L_mutex_unlock_%=\n" \
+ ".previous\n" \
+ "1:" \
+ : "=m" (futex), "=&a" (ignore) \
+ : "i" (FUTEX_WAITERS), "m" (futex) \
+ : "memory"); })
+
+
+#define lll_robust_mutex_dead(futex) \
+ (void) ({ int __ignore; \
+ register int _nr asm ("edx") = 1; \
+ __asm __volatile (LOCK_INSTR "orl %5, (%2)\n\t" \
+ LLL_EBX_LOAD \
+ LLL_ENTER_KERNEL \
+ LLL_EBX_LOAD \
+ : "=a" (__ignore) \
+ : "0" (SYS_futex), LLL_EBX_REG (&(futex)), \
+ "c" (FUTEX_WAKE), "d" (_nr), \
+ "i" (FUTEX_OWNER_DIED), \
+ "i" (offsetof (tcbhead_t, sysinfo))); })
+
+
+#define lll_futex_wake(futex, nr) \
+ do { \
+ int __ignore; \
+ register __typeof (nr) _nr asm ("edx") = (nr); \
+ __asm __volatile (LLL_EBX_LOAD \
+ LLL_ENTER_KERNEL \
+ LLL_EBX_LOAD \
+ : "=a" (__ignore) \
+ : "0" (SYS_futex), LLL_EBX_REG (futex), \
+ "c" (FUTEX_WAKE), "d" (_nr), \
+ "i" (0) /* phony, to align next arg's number */, \
+ "i" (offsetof (tcbhead_t, sysinfo))); \
+ } while (0)
+
+
+#define lll_mutex_islocked(futex) \
+ (futex != 0)
+
+
+/* We have a separate internal lock implementation which is not tied
+ to binary compatibility. */
+
+/* Type for lock object. */
+typedef int lll_lock_t;
+
+/* Initializers for lock. */
+#define LLL_LOCK_INITIALIZER (0)
+#define LLL_LOCK_INITIALIZER_LOCKED (1)
+
+
+extern int __lll_lock_wait (int val, int *__futex)
+ __attribute ((regparm (2))) attribute_hidden;
+extern int __lll_unlock_wake (int *__futex)
+ __attribute ((regparm (1))) attribute_hidden;
+extern int lll_unlock_wake_cb (int *__futex) attribute_hidden;
+
+
+/* The states of a lock are:
+ 0 - untaken
+ 1 - taken by one user
+ 2 - taken by more users */
+
+
+#if defined NOT_IN_libc || defined UP
+# define lll_trylock(futex) lll_mutex_trylock (futex)
+# define lll_lock(futex) lll_mutex_lock (futex)
+# define lll_unlock(futex) lll_mutex_unlock (futex)
+#else
+/* Special versions of the macros for use in libc itself. They avoid
+ the lock prefix when the thread library is not used.
+
+ XXX In future we might even want to avoid it on UP machines. */
+# include <tls.h>
+
+# define lll_trylock(futex) \
+ ({ unsigned char ret; \
+ __asm __volatile ("cmpl $0, %%gs:%P5\n\t" \
+ "je 0f\n\t" \
+ "lock\n" \
+ "0:\tcmpxchgl %2, %1; setne %0" \
+ : "=a" (ret), "=m" (futex) \
+ : "r" (LLL_MUTEX_LOCK_INITIALIZER_LOCKED), "m" (futex),\
+ "0" (LLL_MUTEX_LOCK_INITIALIZER), \
+ "i" (offsetof (tcbhead_t, multiple_threads)) \
+ : "memory"); \
+ ret; })
+
+
+# define lll_lock(futex) \
+ (void) ({ int ignore1, ignore2; \
+ __asm __volatile ("cmpl $0, %%gs:%P6\n\t" \
+ "je 0f\n\t" \
+ "lock\n" \
+ "0:\tcmpxchgl %1, %2\n\t" \
+ "jnz _L_mutex_lock_%=\n\t" \
+ ".subsection 1\n\t" \
+ ".type _L_mutex_lock_%=,@function\n" \
+ "_L_mutex_lock_%=:\n\t" \
+ "leal %2, %%ecx\n\t" \
+ "call __lll_mutex_lock_wait\n\t" \
+ "jmp 1f\n\t" \
+ ".size _L_mutex_lock_%=,.-_L_mutex_lock_%=\n" \
+ ".previous\n" \
+ "1:" \
+ : "=a" (ignore1), "=c" (ignore2), "=m" (futex) \
+ : "0" (0), "1" (1), "m" (futex), \
+ "i" (offsetof (tcbhead_t, multiple_threads)) \
+ : "memory"); })
+
+
+# define lll_unlock(futex) \
+ (void) ({ int ignore; \
+ __asm __volatile ("cmpl $0, %%gs:%P3\n\t" \
+ "je 0f\n\t" \
+ "lock\n" \
+ "0:\tsubl $1,%0\n\t" \
+ "jne _L_mutex_unlock_%=\n\t" \
+ ".subsection 1\n\t" \
+ ".type _L_mutex_unlock_%=,@function\n" \
+ "_L_mutex_unlock_%=:\n\t" \
+ "leal %0, %%eax\n\t" \
+ "call __lll_mutex_unlock_wake\n\t" \
+ "jmp 1f\n\t" \
+ ".size _L_mutex_unlock_%=,.-_L_mutex_unlock_%=\n" \
+ ".previous\n" \
+ "1:" \
+ : "=m" (futex), "=&a" (ignore) \
+ : "m" (futex), \
+ "i" (offsetof (tcbhead_t, multiple_threads)) \
+ : "memory"); })
+#endif
+
+
+#define lll_islocked(futex) \
+ (futex != LLL_LOCK_INITIALIZER)
+
+
+/* The kernel notifies a process with uses CLONE_CLEARTID via futex
+ wakeup when the clone terminates. The memory location contains the
+ thread ID while the clone is running and is reset to zero
+ afterwards.
+
+ The macro parameter must not have any side effect. */
+#define lll_wait_tid(tid) \
+ do { \
+ int __ignore; \
+ register __typeof (tid) _tid asm ("edx") = (tid); \
+ if (_tid != 0) \
+ __asm __volatile (LLL_EBX_LOAD \
+ "1:\tmovl %1, %%eax\n\t" \
+ LLL_ENTER_KERNEL \
+ "cmpl $0, (%%ebx)\n\t" \
+ "jne 1b\n\t" \
+ LLL_EBX_LOAD \
+ : "=&a" (__ignore) \
+ : "i" (SYS_futex), LLL_EBX_REG (&tid), "S" (0), \
+ "c" (FUTEX_WAIT), "d" (_tid), \
+ "i" (offsetof (tcbhead_t, sysinfo)) \
+ : "memory"); \
+ } while (0)
+
+extern int __lll_timedwait_tid (int *tid, const struct timespec *abstime)
+ __attribute__ ((regparm (2))) attribute_hidden;
+#define lll_timedwait_tid(tid, abstime) \
+ ({ \
+ int __result = 0; \
+ if (tid != 0) \
+ { \
+ if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) \
+ __result = EINVAL; \
+ else \
+ __result = __lll_timedwait_tid (&tid, abstime); \
+ } \
+ __result; })
+
+
+/* Conditional variable handling. */
+
+extern void __lll_cond_wait (pthread_cond_t *cond)
+ __attribute ((regparm (1))) attribute_hidden;
+extern int __lll_cond_timedwait (pthread_cond_t *cond,
+ const struct timespec *abstime)
+ __attribute ((regparm (2))) attribute_hidden;
+extern void __lll_cond_wake (pthread_cond_t *cond)
+ __attribute ((regparm (1))) attribute_hidden;
+extern void __lll_cond_broadcast (pthread_cond_t *cond)
+ __attribute ((regparm (1))) attribute_hidden;
+
+
+#define lll_cond_wait(cond) \
+ __lll_cond_wait (cond)
+#define lll_cond_timedwait(cond, abstime) \
+ __lll_cond_timedwait (cond, abstime)
+#define lll_cond_wake(cond) \
+ __lll_cond_wake (cond)
+#define lll_cond_broadcast(cond) \
+ __lll_cond_broadcast (cond)
+
+
+#endif /* lowlevellock.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/not-cancel.h b/libc/nptl/sysdeps/unix/sysv/linux/i386/not-cancel.h
new file mode 100644
index 000000000..6557359b4
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/not-cancel.h
@@ -0,0 +1,105 @@
+/* Uncancelable versions of cancelable interfaces. Linux/NPTL version.
+ Copyright (C) 2003, 2006 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 <sysdep.h>
+
+#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
+extern int __open_nocancel (const char *, int, ...) attribute_hidden;
+extern int __close_nocancel (int) attribute_hidden;
+extern int __read_nocancel (int, void *, size_t) attribute_hidden;
+extern int __write_nocancel (int, const void *, size_t) attribute_hidden;
+extern pid_t __waitpid_nocancel (pid_t, int *, int) attribute_hidden;
+extern int __openat_nocancel (int fd, const char *fname, int oflag,
+ mode_t mode) attribute_hidden;
+extern int __openat64_nocancel (int fd, const char *fname, int oflag,
+ mode_t mode) attribute_hidden;
+#else
+# define __open_nocancel(name, ...) __open (name, __VA_ARGS__)
+# define __close_nocancel(fd) __close (fd)
+# define __read_nocancel(fd, buf, len) __read (fd, buf, len)
+# define __write_nocancel(fd, buf, len) __write (fd, buf, len)
+# define __waitpid_nocancel(pid, stat_loc, options) \
+ __waitpid (pid, stat_loc, options)
+# define __openat_nocancel(fd, fname, oflag, mode) \
+ openat (fd, fname, oflag, mode)
+# define __openat64_nocancel(fd, fname, oflag, mode) \
+ openat64 (fd, fname, oflag, mode)
+#endif
+
+/* Uncancelable open. */
+#define open_not_cancel(name, flags, mode) \
+ __open_nocancel (name, flags, mode)
+#define open_not_cancel_2(name, flags) \
+ __open_nocancel (name, flags)
+
+/* Uncancelable openat. */
+#define openat_not_cancel(fd, fname, oflag, mode) \
+ __openat_nocancel (fd, fname, oflag, mode)
+#define openat_not_cancel_3(fd, fname, oflag) \
+ __openat_nocancel (fd, fname, oflag, 0)
+#define openat64_not_cancel(fd, fname, oflag, mode) \
+ __openat64_nocancel (fd, fname, oflag, mode)
+#define openat64_not_cancel_3(fd, fname, oflag) \
+ __openat64_nocancel (fd, fname, oflag, 0)
+
+/* Uncancelable close. */
+#define close_not_cancel(fd) \
+ __close_nocancel (fd)
+#define close_not_cancel_no_status(fd) \
+ (void) ({ INTERNAL_SYSCALL_DECL (err); \
+ INTERNAL_SYSCALL (close, err, 1, (fd)); })
+
+/* Uncancelable read. */
+#define read_not_cancel(fd, buf, n) \
+ __read_nocancel (fd, buf, n)
+
+/* Uncancelable write. */
+#define write_not_cancel(fd, buf, n) \
+ __write_nocancel (fd, buf, n)
+
+/* Uncancelable writev. */
+#define writev_not_cancel_no_status(fd, iov, n) \
+ (void) ({ INTERNAL_SYSCALL_DECL (err); \
+ INTERNAL_SYSCALL (writev, err, 3, (fd), (iov), (n)); })
+
+/* Uncancelable fcntl. */
+#define fcntl_not_cancel(fd, cmd, val) \
+ __fcntl_nocancel (fd, cmd, val)
+
+/* Uncancelable waitpid. */
+#ifdef __NR_waitpid
+# define waitpid_not_cancel(pid, stat_loc, options) \
+ __waitpid_nocancel (pid, stat_loc, options)
+#else
+# define waitpid_not_cancel(pid, stat_loc, options) \
+ INLINE_SYSCALL (wait4, 4, pid, stat_loc, options, NULL)
+#endif
+
+/* Uncancelable pause. */
+#define pause_not_cancel() \
+ __pause_nocancel ()
+
+/* Uncancelable nanosleep. */
+#define nanosleep_not_cancel(requested_time, remaining) \
+ __nanosleep_nocancel (requested_time, remaining)
+
+/* Uncancelable sigsuspend. */
+#define sigsuspend_not_cancel(set) \
+ __sigsuspend_nocancel (set)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/pt-vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/pt-vfork.S
new file mode 100644
index 000000000..24f5a1d29
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/pt-vfork.S
@@ -0,0 +1,68 @@
+/* Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Andreas Schwab <schwab@gnu.org>.
+
+ 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 <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <kernel-features.h>
+#include <tcb-offsets.h>
+
+/* Save the PID value. */
+#define SAVE_PID \
+ movl %gs:PID, %edx; \
+ movl %edx, %eax; \
+ negl %eax; \
+ movl %eax, %gs:PID
+
+/* Restore the old PID value in the parent. */
+#define RESTORE_PID \
+ testl %eax, %eax; \
+ je 1f; \
+ movl %edx, %gs:PID; \
+1:
+
+/* Clone the calling process, but without copying the whole address space.
+ The calling process is suspended until the new process exits or is
+ replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
+ and the process ID of the new process to the old process. */
+
+ENTRY (__vfork)
+ /* Pop the return PC value into ECX. */
+ popl %ecx
+
+ SAVE_PID
+
+ /* Stuff the syscall number in EAX and enter into the kernel. */
+ movl $SYS_ify (vfork), %eax
+ int $0x80
+
+ RESTORE_PID
+
+ /* Jump to the return PC. Don't jump directly since this
+ disturbs the branch target cache. Instead push the return
+ address back on the stack. */
+ pushl %ecx
+
+ cmpl $-4095, %eax
+ jae SYSCALL_ERROR_LABEL /* Branch forward if it failed. */
+.Lpseudo_end:
+ ret
+PSEUDO_END (__vfork)
+
+weak_alias (__vfork, vfork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/pthread_once.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/pthread_once.S
new file mode 100644
index 000000000..312933c5e
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/pthread_once.S
@@ -0,0 +1,182 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <unwindbuf.h>
+#include <sysdep.h>
+
+#ifndef UP
+# define LOCK lock
+#else
+# define LOCK
+#endif
+
+#define SYS_futex 240
+#define FUTEX_WAKE 1
+
+ .comm __fork_generation, 4, 4
+
+ .text
+
+
+ .globl __pthread_once
+ .type __pthread_once,@function
+ .align 16
+ cfi_startproc
+__pthread_once:
+ movl 4(%esp), %ecx
+ testl $2, (%ecx)
+ jz 1f
+ xorl %eax, %eax
+ 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
+
+ /* Not yet initialized or initialization in progress.
+ Get the fork generation counter now. */
+6: movl (%ebx), %eax
+#ifdef PIC
+ call __i686.get_pc_thunk.cx
+ addl $_GLOBAL_OFFSET_TABLE_, %ecx
+#endif
+
+5: movl %eax, %edx
+
+ testl $2, %eax
+ jnz 4f
+
+ andl $3, %edx
+#ifdef PIC
+ orl __fork_generation@GOTOFF(%ecx), %edx
+#else
+ orl __fork_generation, %edx
+#endif
+ orl $1, %edx
+
+ LOCK
+ cmpxchgl %edx, (%ebx)
+ jnz 5b
+
+ /* Check whether another thread already runs the initializer. */
+ testl $1, %eax
+ jz 3f /* No -> do it. */
+
+ /* Check whether the initializer execution was interrupted
+ by a fork. */
+ xorl %edx, %eax
+ testl $0xfffffffc, %eax
+ jnz 3f /* Different for generation -> run initializer. */
+
+ /* Somebody else got here first. Wait. */
+ movl %esi, %ecx /* movl $FUTEX_WAIT, %ecx */
+ movl $SYS_futex, %eax
+ ENTER_KERNEL
+ jmp 6b
+
+3: /* Call the initializer function after setting up the
+ 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)
+ movl %eax, (%esp)
+ call __sigsetjmp@PLT
+ testl %eax, %eax
+ jne 7f
+
+ leal 8(%esp), %eax
+ call HIDDEN_JUMPTARGET(__pthread_register_cancel)
+
+ /* Call the user-provided initialization function. */
+ call *24+UNWINDBUFSIZE(%esp)
+
+ /* Pop the cleanup handler. */
+ leal 8(%esp), %eax
+ call HIDDEN_JUMPTARGET(__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)
+
+ /* Wake up all other threads. */
+ movl $0x7fffffff, %edx
+ movl $FUTEX_WAKE, %ecx
+ movl $SYS_futex, %eax
+ 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
+
+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
+ movl $FUTEX_WAKE, %ecx
+ movl $SYS_futex, %eax
+ ENTER_KERNEL
+
+ leal 8(%esp), %eax
+ call HIDDEN_JUMPTARGET (__pthread_unwind_next)
+ /* 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
+ .section .gnu.linkonce.t.__i686.get_pc_thunk.cx,"ax",@progbits
+ .globl __i686.get_pc_thunk.cx
+ .hidden __i686.get_pc_thunk.cx
+ .type __i686.get_pc_thunk.cx,@function
+__i686.get_pc_thunk.cx:
+ movl (%esp), %ecx;
+ ret
+ .size __i686.get_pc_thunk.cx,.-__i686.get_pc_thunk.cx
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/pthread_spin_init.c b/libc/nptl/sysdeps/unix/sysv/linux/i386/pthread_spin_init.c
new file mode 100644
index 000000000..80c0b5216
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/pthread_spin_init.c
@@ -0,0 +1 @@
+#include <nptl/sysdeps/i386/pthread_spin_init.c>
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/pthread_spin_unlock.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/pthread_spin_unlock.S
new file mode 100644
index 000000000..41c71f348
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/pthread_spin_unlock.S
@@ -0,0 +1 @@
+#include <nptl/sysdeps/i386/pthread_spin_unlock.S>
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/smp.h b/libc/nptl/sysdeps/unix/sysv/linux/i386/smp.h
new file mode 100644
index 000000000..f68a0c075
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/smp.h
@@ -0,0 +1,56 @@
+/* Determine whether the host has multiple processors. Linux version.
+ Copyright (C) 1996, 2002, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <sys/utsname.h>
+#include <not-cancel.h>
+
+/* Test whether the machine has more than one processor. This is not the
+ best test but good enough. More complicated tests would require `malloc'
+ which is not available at that time. */
+static inline int
+is_smp_system (void)
+{
+ union
+ {
+ struct utsname uts;
+ char buf[512];
+ } u;
+ char *cp;
+
+ /* Try reading the number using `sysctl' first. */
+ if (uname (&u.uts) == 0)
+ cp = u.uts.version;
+ else
+ {
+ /* This was not successful. Now try reading the /proc filesystem. */
+ int fd = open_not_cancel_2 ("/proc/sys/kernel/version", O_RDONLY);
+ if (__builtin_expect (fd, 0) == -1
+ || read_not_cancel (fd, u.buf, sizeof (u.buf)) <= 0)
+ /* This also didn't work. We give up and say it's a UP machine. */
+ u.buf[0] = '\0';
+
+ close_not_cancel_no_status (fd);
+ cp = u.buf;
+ }
+
+ return strstr (cp, "SMP") != NULL;
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h b/libc/nptl/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h
new file mode 100644
index 000000000..147f5c847
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h
@@ -0,0 +1,139 @@
+/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <tls.h>
+#ifndef __ASSEMBLER__
+# include <nptl/pthreadP.h>
+#endif
+
+#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
+
+# undef PSEUDO
+# define PSEUDO(name, syscall_name, args) \
+ .text; \
+ ENTRY (name) \
+ cmpl $0, %gs:MULTIPLE_THREADS_OFFSET; \
+ jne L(pseudo_cancel); \
+ .type __##syscall_name##_nocancel,@function; \
+ .globl __##syscall_name##_nocancel; \
+ __##syscall_name##_nocancel: \
+ DO_CALL (syscall_name, args); \
+ cmpl $-4095, %eax; \
+ jae SYSCALL_ERROR_LABEL; \
+ ret; \
+ .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
+ L(pseudo_cancel): \
+ CENABLE \
+ SAVE_OLDTYPE_##args \
+ PUSHCARGS_##args \
+ DOCARGS_##args \
+ movl $SYS_ify (syscall_name), %eax; \
+ ENTER_KERNEL; \
+ POPCARGS_##args; \
+ POPSTATE_##args \
+ cmpl $-4095, %eax; \
+ jae SYSCALL_ERROR_LABEL; \
+ L(pseudo_end):
+
+# define SAVE_OLDTYPE_0 movl %eax, %ecx;
+# define SAVE_OLDTYPE_1 SAVE_OLDTYPE_0
+# define SAVE_OLDTYPE_2 pushl %eax; cfi_adjust_cfa_offset (4);
+# define SAVE_OLDTYPE_3 SAVE_OLDTYPE_2
+# define SAVE_OLDTYPE_4 SAVE_OLDTYPE_2
+# define SAVE_OLDTYPE_5 SAVE_OLDTYPE_2
+
+# define PUSHCARGS_0 /* No arguments to push. */
+# define DOCARGS_0 /* No arguments to frob. */
+# define POPCARGS_0 /* No arguments to pop. */
+# define _PUSHCARGS_0 /* No arguments to push. */
+# define _POPCARGS_0 /* No arguments to pop. */
+
+# define PUSHCARGS_1 movl %ebx, %edx; cfi_register (ebx, edx); PUSHCARGS_0
+# define DOCARGS_1 _DOARGS_1 (4)
+# define POPCARGS_1 POPCARGS_0; movl %edx, %ebx; cfi_restore (ebx);
+# define _PUSHCARGS_1 pushl %ebx; cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (ebx, 0); _PUSHCARGS_0
+# define _POPCARGS_1 _POPCARGS_0; popl %ebx; \
+ cfi_adjust_cfa_offset (-4); cfi_restore (ebx);
+
+# define PUSHCARGS_2 PUSHCARGS_1
+# define DOCARGS_2 _DOARGS_2 (12)
+# define POPCARGS_2 POPCARGS_1
+# define _PUSHCARGS_2 _PUSHCARGS_1
+# define _POPCARGS_2 _POPCARGS_1
+
+# define PUSHCARGS_3 _PUSHCARGS_2
+# define DOCARGS_3 _DOARGS_3 (20)
+# define POPCARGS_3 _POPCARGS_3
+# define _PUSHCARGS_3 _PUSHCARGS_2
+# define _POPCARGS_3 _POPCARGS_2
+
+# define PUSHCARGS_4 _PUSHCARGS_4
+# define DOCARGS_4 _DOARGS_4 (28)
+# define POPCARGS_4 _POPCARGS_4
+# define _PUSHCARGS_4 pushl %esi; cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (esi, 0); _PUSHCARGS_3
+# define _POPCARGS_4 _POPCARGS_3; popl %esi; \
+ cfi_adjust_cfa_offset (-4); cfi_restore (esi);
+
+# define PUSHCARGS_5 _PUSHCARGS_5
+# define DOCARGS_5 _DOARGS_5 (36)
+# define POPCARGS_5 _POPCARGS_5
+# define _PUSHCARGS_5 pushl %edi; cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (edi, 0); _PUSHCARGS_4
+# define _POPCARGS_5 _POPCARGS_4; popl %edi; \
+ cfi_adjust_cfa_offset (-4); cfi_restore (edi);
+
+# ifdef IS_IN_libpthread
+# define CENABLE call __pthread_enable_asynccancel;
+# define CDISABLE call __pthread_disable_asynccancel
+# elif !defined NOT_IN_libc
+# define CENABLE call __libc_enable_asynccancel;
+# define CDISABLE call __libc_disable_asynccancel
+# elif defined IS_IN_librt
+# define CENABLE call __librt_enable_asynccancel;
+# define CDISABLE call __librt_disable_asynccancel
+# else
+# error Unsupported library
+# endif
+# define POPSTATE_0 \
+ pushl %eax; cfi_adjust_cfa_offset (4); movl %ecx, %eax; \
+ CDISABLE; popl %eax; cfi_adjust_cfa_offset (-4);
+# define POPSTATE_1 POPSTATE_0
+# define POPSTATE_2 xchgl (%esp), %eax; CDISABLE; popl %eax; \
+ cfi_adjust_cfa_offset (-4);
+# define POPSTATE_3 POPSTATE_2
+# define POPSTATE_4 POPSTATE_3
+# define POPSTATE_5 POPSTATE_4
+
+# ifndef __ASSEMBLER__
+# define SINGLE_THREAD_P \
+ __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+ header.multiple_threads) == 0, 1)
+# else
+# define SINGLE_THREAD_P cmpl $0, %gs:MULTIPLE_THREADS_OFFSET
+# endif
+
+#elif !defined __ASSEMBLER__
+
+# define SINGLE_THREAD_P (1)
+# define NO_CANCELLATION 1
+
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/i386/vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/i386/vfork.S
new file mode 100644
index 000000000..37f084205
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/i386/vfork.S
@@ -0,0 +1,45 @@
+/* Copyright (C) 1999,2002,2004,2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+/* We want an #include_next, but we are the main source file.
+ So, #include ourselves and in that incarnation we can use #include_next. */
+#ifndef INCLUDED_SELF
+# define INCLUDED_SELF
+# include <vfork.S>
+#else
+
+# include <tcb-offsets.h>
+
+/* Save the PID value. */
+# define SAVE_PID \
+ movl %gs:PID, %edx; \
+ movl %edx, %eax; \
+ negl %eax; \
+ jne 1f; \
+ movl $0x80000000, %eax; \
+1: movl %eax, %gs:PID
+
+/* Restore the old PID value in the parent. */
+# define RESTORE_PID \
+ testl %eax, %eax; \
+ je 1f; \
+ movl %edx, %gs:PID; \
+1:
+
+# include_next <vfork.S>
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/Makefile b/libc/nptl/sysdeps/unix/sysv/linux/ia64/Makefile
new file mode 100644
index 000000000..ff98f1a49
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/Makefile
@@ -0,0 +1,3 @@
+ifeq ($(subdir),nptl)
+libpthread-sysdep_routines += __ia64_longjmp unwind_longjmp __sigstack_longjmp
+endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/Versions b/libc/nptl/sysdeps/unix/sysv/linux/ia64/Versions
new file mode 100644
index 000000000..437c4da28
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/Versions
@@ -0,0 +1,13 @@
+libpthread {
+ GLIBC_2.3.3 {
+ # Changed PTHREAD_STACK_MIN.
+ pthread_attr_setstack; pthread_attr_setstacksize;
+ }
+}
+librt {
+ GLIBC_2.3.3 {
+ # Changed timer_t.
+ timer_create; timer_delete; timer_getoverrun; timer_gettime;
+ timer_settime;
+ }
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/__ia64_longjmp.S b/libc/nptl/sysdeps/unix/sysv/linux/ia64/__ia64_longjmp.S
new file mode 100644
index 000000000..a1120d4d7
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/__ia64_longjmp.S
@@ -0,0 +1,159 @@
+/* Copyright (C) 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
+
+ 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 <sysdep.h>
+#include <features.h>
+
+LEAF(__ia64_flush_rbs)
+ flushrs
+ mov r9 = ar.rsc // 12 cyc latency
+ ;;
+ mov r8 = ar.bsp // 12 cyc latency
+ ;;
+ and r16 = ~0x3, r9 // clear ar.rsc.mode
+ ;;
+ mov ar.rsc = r16 // put RSE into enforced-lazy mode
+ ;;
+ mov r10 = ar.rnat // 5 cyc latency
+ ret
+END(__ia64_flush_rbs)
+
+
+# define pPos p6 /* is rotate count positive? */
+# define pNeg p7 /* is rotate count negative? */
+
+/* __ia64_longjmp(__jmp_buf buf, int val, long rnat, long rsc) */
+
+
+LEAF(__ia64_longjmp)
+ alloc r8=ar.pfs,4,0,0,0
+ add r2=0x98,in0 // r2 <- &jmpbuf.orig_jmp_buf_addr
+ add r3=0x88,in0 // r3 <- &jmpbuf.ar_bsp
+ ;;
+ ld8 r8=[r2] // r8 <- orig_jmp_buf_addr
+ ld8 r23=[r3],8 // r23 <- jmpbuf.ar_bsp
+ mov r2=in0
+ ;;
+ //
+ // Note: we need to redo the "flushrs" here even though it's
+ // already been done by __ia64_flush_rbs. It is needed to
+ // ensure that ar.bspstore == ar.bsp.
+ //
+ flushrs // flush dirty regs to backing store
+ ld8 r25=[r3] // r25 <- jmpbuf.ar_unat
+ sub r8=r8,in0 // r8 <- &orig_jmpbuf - &jmpbuf
+ ;;
+ add r3=8,in0 // r3 <- &jmpbuf.r1
+ extr.u r8=r8,3,6 // r8 <- (&orig_jmpbuf - &jmpbuf)/8 & 0x3f
+ ;;
+ cmp.lt pNeg,pPos=r8,r0
+ ;;
+(pPos) mov r16=r8
+(pNeg) add r16=64,r8
+(pPos) sub r17=64,r8
+(pNeg) sub r17=r0,r8
+ ;;
+ shr.u r8=r25,r16
+ shl r9=r25,r17
+ ;;
+ or r25=r8,r9
+ ;;
+ mov ar.unat=r25 // setup ar.unat (NaT bits for r1, r4-r7, and r12)
+ ;;
+ ld8.fill.nta sp=[r2],16 // r12 (sp)
+ ld8.fill.nta gp=[r3],16 // r1 (gp)
+ dep r11=-1,r23,3,6 // r11 <- ia64_rse_rnat_addr(jmpbuf.ar_bsp)
+ ;;
+ ld8.nta r16=[r2],16 // caller's unat
+ ld8.nta r17=[r3],16 // fpsr
+ ;;
+ ld8.fill.nta r4=[r2],16 // r4
+ ld8.fill.nta r5=[r3],16 // r5 (gp)
+ ;;
+ ld8.fill.nta r6=[r2],16 // r6
+ ld8.fill.nta r7=[r3],16 // r7
+ ;;
+ mov ar.unat=r16 // restore caller's unat
+ mov ar.fpsr=r17 // restore fpsr
+ ;;
+ ld8.nta r16=[r2],16 // b0
+ ld8.nta r17=[r3],16 // b1
+ ;;
+ mov ar.bspstore=r23 // restore ar.bspstore
+ ld8.nta r18=[r2],16 // b2
+ ;;
+ mov ar.rnat=in2 // restore ar.rnat
+ ld8.nta r19=[r3],16 // b3
+ ;;
+ ld8.nta r20=[r2],16 // b4
+ ld8.nta r21=[r3],16 // b5
+#ifdef PTR_DEMANGLE
+ PTR_DEMANGLE (r16, r24)
+#endif
+ ;;
+ ld8.nta r11=[r2],16 // ar.pfs
+ ld8.nta r22=[r3],56 // ar.lc
+ ;;
+ ld8.nta r24=[r2],32 // pr
+ mov ar.rsc=in3 // restore ar.rsc
+ mov b0=r16
+ ;;
+ ldf.fill.nta f2=[r2],32
+ ldf.fill.nta f3=[r3],32
+ mov b1=r17
+ ;;
+ ldf.fill.nta f4=[r2],32
+ ldf.fill.nta f5=[r3],32
+ mov b2=r18
+ ;;
+ ldf.fill.nta f16=[r2],32
+ ldf.fill.nta f17=[r3],32
+ mov b3=r19
+ ;;
+ ldf.fill.nta f18=[r2],32
+ ldf.fill.nta f19=[r3],32
+ mov b4=r20
+ ;;
+ ldf.fill.nta f20=[r2],32
+ ldf.fill.nta f21=[r3],32
+ mov b5=r21
+ ;;
+ ldf.fill.nta f22=[r2],32
+ ldf.fill.nta f23=[r3],32
+ mov ar.lc=r22
+ ;;
+ ldf.fill.nta f24=[r2],32
+ ldf.fill.nta f25=[r3],32
+ cmp.eq p8,p9=0,in1
+ ;;
+ ldf.fill.nta f26=[r2],32
+ ldf.fill.nta f27=[r3],32
+ mov ar.pfs=r11
+ ;;
+ ldf.fill.nta f28=[r2],32
+ ldf.fill.nta f29=[r3],32
+(p8) mov r8=1
+ ;;
+ ldf.fill.nta f30=[r2]
+ ldf.fill.nta f31=[r3]
+(p9) mov r8=in1
+
+ invala // virt. -> phys. regnum mapping may change
+ mov pr=r24,-1
+ ret
+END(__ia64_longjmp)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/__sigstack_longjmp.c b/libc/nptl/sysdeps/unix/sysv/linux/ia64/__sigstack_longjmp.c
new file mode 100644
index 000000000..8f552eaad
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/__sigstack_longjmp.c
@@ -0,0 +1,168 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
+
+ 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. */
+
+/* The public __longjmp() implementation is limited to jumping within
+ the same stack. That is, in general it is not possible to use this
+ __longjmp() implementation to cross from one stack to another.
+ In constrast, the __sigstack_longjmp() implemented here allows
+ crossing from the alternate signal stack to the normal stack
+ as a special case. */
+
+#include <assert.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include <sysdep.h>
+#include <sys/rse.h>
+
+#define JB_SP 0
+#define JB_BSP 17
+
+struct rbs_flush_values
+ {
+ unsigned long bsp;
+ unsigned long rsc;
+ unsigned long rnat;
+ };
+
+extern struct rbs_flush_values __ia64_flush_rbs (void);
+extern void __ia64_longjmp (__jmp_buf buf, int val, long rnat, long rsc)
+ __attribute__ ((__noreturn__));
+
+static void
+copy_rbs (unsigned long *dst, unsigned long *dst_end, unsigned long dst_rnat,
+ unsigned long *src, unsigned long *src_end,
+ unsigned long current_rnat)
+{
+ unsigned long dst_slot, src_rnat = 0, src_slot, *src_rnat_addr, nat_bit;
+ int first_time = 1;
+
+ while (dst < dst_end)
+ {
+ dst_slot = ia64_rse_slot_num (dst);
+ if (dst_slot == 63)
+ {
+ *dst++ = dst_rnat;
+ dst_rnat = 0;
+ }
+ else
+ {
+ /* read source value, including NaT bit: */
+ src_slot = ia64_rse_slot_num (src);
+ if (src_slot == 63)
+ {
+ /* skip src RNaT slot */
+ ++src;
+ src_slot = 0;
+ }
+ if (first_time || src_slot == 0)
+ {
+ first_time = 0;
+ src_rnat_addr = ia64_rse_rnat_addr (src);
+ if (src_rnat_addr < src_end)
+ src_rnat = *src_rnat_addr;
+ else
+ src_rnat = current_rnat;
+ }
+ nat_bit = (src_rnat >> src_slot) & 1;
+
+ assert (src < src_end);
+
+ *dst++ = *src++;
+ if (nat_bit)
+ dst_rnat |= (1UL << dst_slot);
+ else
+ dst_rnat &= ~(1UL << dst_slot);
+ }
+ }
+ dst_slot = ia64_rse_slot_num (dst);
+ if (dst_slot > 0)
+ *ia64_rse_rnat_addr (dst) = dst_rnat;
+}
+
+void
+__sigstack_longjmp (__jmp_buf buf, int val)
+{
+ unsigned long *rbs_base, *bsp, *bspstore, *jb_bsp, jb_sp, ss_sp;
+ unsigned long ndirty, rnat, load_rnat, *jb_rnat_addr;
+ struct sigcontext *sc;
+ stack_t stk;
+ struct rbs_flush_values c;
+
+ /* put RSE into enforced-lazy mode and return current bsp/rsc/rnat: */
+ c = __ia64_flush_rbs ();
+
+ jb_sp = ((unsigned long *) buf)[JB_SP];
+ jb_bsp = ((unsigned long **) buf)[JB_BSP];
+
+ INTERNAL_SYSCALL_DECL (err);
+ (void) INTERNAL_SYSCALL (sigaltstack, err, 2, NULL, &stk);
+
+ ss_sp = (unsigned long) stk.ss_sp;
+ jb_rnat_addr = ia64_rse_rnat_addr (jb_bsp);
+
+ if ((stk.ss_flags & SS_ONSTACK) == 0 || jb_sp - ss_sp < stk.ss_size)
+ /* Normal non-stack-crossing longjmp; if the RNaT slot for the bsp
+ saved in the jump-buffer is the same as the one for the current
+ BSP, use the current AR.RNAT value, otherwise, load it from the
+ jump-buffer's RNaT-slot. */
+ load_rnat = (ia64_rse_rnat_addr ((unsigned long *) c.bsp) != jb_rnat_addr);
+ else
+ {
+ /* If we are on the alternate signal-stack and the jump-buffer
+ lies outside the signal-stack, we may need to copy back the
+ dirty partition which was torn off and saved on the
+ signal-stack when the signal was delivered.
+
+ Caveat: we assume that the top of the alternate signal-stack
+ stores the sigcontext structure of the signal that
+ caused the switch to the signal-stack. This should
+ be a fairly safe assumption but the kernel _could_
+ do things differently.. */
+ sc = ((struct sigcontext *) ((ss_sp + stk.ss_size) & -16) - 1);
+
+ /* As a sanity-check, verify that the register-backing-store base
+ of the alternate signal-stack is where we expect it. */
+ rbs_base = (unsigned long *)
+ ((ss_sp + sizeof (long) - 1) & -sizeof (long));
+
+ assert ((unsigned long) rbs_base == sc->sc_rbs_base);
+
+ ndirty = ia64_rse_num_regs (rbs_base, rbs_base + (sc->sc_loadrs >> 19));
+ bsp = (unsigned long *) sc->sc_ar_bsp;
+ bspstore = ia64_rse_skip_regs (bsp, -ndirty);
+
+ if (bspstore < jb_bsp)
+ /* AR.BSPSTORE at the time of the signal was below the value
+ of AR.BSP saved in the jump-buffer => copy the missing
+ portion from the torn off dirty partition which got saved
+ on the alternate signal-stack. */
+ copy_rbs (bspstore, jb_bsp, sc->sc_ar_rnat,
+ rbs_base, (unsigned long *) c.bsp, c.rnat);
+
+ load_rnat = 1;
+ }
+ if (load_rnat)
+ rnat = *jb_rnat_addr;
+ else
+ rnat = c.rnat;
+ __ia64_longjmp (buf, val, rnat, c.rsc);
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/bits/local_lim.h b/libc/nptl/sysdeps/unix/sysv/linux/ia64/bits/local_lim.h
new file mode 100644
index 000000000..f837250b9
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/bits/local_lim.h
@@ -0,0 +1,89 @@
+/* Minimum guaranteed maximum values for system limits. Linux/IA-64 version.
+ Copyright (C) 1993-1998,2000,2002,2003,2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* The kernel header pollutes the namespace with the NR_OPEN symbol
+ and defines LINK_MAX although filesystems have different maxima. A
+ similar thing is true for OPEN_MAX: the limit can be changed at
+ runtime and therefore the macro must not be defined. Remove this
+ after including the header if necessary. */
+#ifndef NR_OPEN
+# define __undef_NR_OPEN
+#endif
+#ifndef LINK_MAX
+# define __undef_LINK_MAX
+#endif
+#ifndef OPEN_MAX
+# define __undef_OPEN_MAX
+#endif
+
+/* The kernel sources contain a file with all the needed information. */
+#include <linux/limits.h>
+
+/* Have to remove NR_OPEN? */
+#ifdef __undef_NR_OPEN
+# undef NR_OPEN
+# undef __undef_NR_OPEN
+#endif
+/* Have to remove LINK_MAX? */
+#ifdef __undef_LINK_MAX
+# undef LINK_MAX
+# undef __undef_LINK_MAX
+#endif
+/* Have to remove OPEN_MAX? */
+#ifdef __undef_OPEN_MAX
+# undef OPEN_MAX
+# undef __undef_OPEN_MAX
+#endif
+
+/* The number of data keys per process. */
+#define _POSIX_THREAD_KEYS_MAX 128
+/* This is the value this implementation supports. */
+#define PTHREAD_KEYS_MAX 1024
+
+/* Controlling the iterations of destructors for thread-specific data. */
+#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
+/* Number of iterations this implementation does. */
+#define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS
+
+/* The number of threads per process. */
+#define _POSIX_THREAD_THREADS_MAX 64
+/* We have no predefined limit on the number of threads. */
+#undef PTHREAD_THREADS_MAX
+
+/* Maximum amount by which a process can descrease its asynchronous I/O
+ priority level. */
+#define AIO_PRIO_DELTA_MAX 20
+
+/* Minimum size for a thread. We are free to choose a reasonable value. */
+#define PTHREAD_STACK_MIN 196608
+
+/* Maximum number of timer expiration overruns. */
+#define DELAYTIMER_MAX 2147483647
+
+/* Maximum tty name length. */
+#define TTY_NAME_MAX 32
+
+/* Maximum login name length. This is arbitrary. */
+#define LOGIN_NAME_MAX 256
+
+/* Maximum host name length. */
+#define HOST_NAME_MAX 64
+
+/* Maximum message queue priority level. */
+#define MQ_PRIO_MAX 32768
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h b/libc/nptl/sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h
new file mode 100644
index 000000000..892769dca
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/bits/pthreadtypes.h
@@ -0,0 +1,169 @@
+/* Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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. */
+
+#ifndef _BITS_PTHREADTYPES_H
+#define _BITS_PTHREADTYPES_H 1
+
+#define __SIZEOF_PTHREAD_ATTR_T 56
+#define __SIZEOF_PTHREAD_MUTEX_T 40
+#define __SIZEOF_PTHREAD_MUTEXATTR_T 4
+#define __SIZEOF_PTHREAD_COND_T 48
+#define __SIZEOF_PTHREAD_CONDATTR_T 4
+#define __SIZEOF_PTHREAD_RWLOCK_T 56
+#define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
+#define __SIZEOF_PTHREAD_BARRIER_T 32
+#define __SIZEOF_PTHREAD_BARRIERATTR_T 4
+
+
+/* Thread identifiers. The structure of the attribute type is not
+ exposed on purpose. */
+typedef unsigned long int pthread_t;
+
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_ATTR_T];
+ long int __align;
+} pthread_attr_t;
+
+
+typedef struct __pthread_internal_list
+{
+ struct __pthread_internal_list *__prev;
+ struct __pthread_internal_list *__next;
+} __pthread_list_t;
+
+
+/* Data structures for mutex handling. The structure of the attribute
+ type is not exposed on purpose. */
+typedef union
+{
+ struct __pthread_mutex_s
+ {
+ int __lock;
+ unsigned int __count;
+ int __owner;
+ unsigned int __nusers;
+ /* KIND must stay at this position in the structure to maintain
+ binary compatibility. */
+ int __kind;
+ int __spins;
+ __pthread_list_t __list;
+#define __PTHREAD_MUTEX_HAVE_PREV 1
+ } __data;
+ char __size[__SIZEOF_PTHREAD_MUTEX_T];
+ long int __align;
+} pthread_mutex_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_MUTEXATTR_T];
+ int __align;
+} pthread_mutexattr_t;
+
+
+/* Data structure for conditional variable handling. The structure of
+ the attribute type is not exposed on purpose. */
+typedef union
+{
+ struct
+ {
+ int __lock;
+ unsigned int __futex;
+ __extension__ unsigned long long int __total_seq;
+ __extension__ unsigned long long int __wakeup_seq;
+ __extension__ unsigned long long int __woken_seq;
+ void *__mutex;
+ unsigned int __nwaiters;
+ unsigned int __broadcast_seq;
+ } __data;
+ char __size[__SIZEOF_PTHREAD_COND_T];
+ long int __align;
+} pthread_cond_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_CONDATTR_T];
+ int __align;
+} pthread_condattr_t;
+
+
+/* Keys for thread-specific data */
+typedef unsigned int pthread_key_t;
+
+
+/* Once-only execution */
+typedef int pthread_once_t;
+
+
+#if defined __USE_UNIX98 || defined __USE_XOPEN2K
+/* Data structure for read-write lock variable handling. The
+ structure of the attribute type is not exposed on purpose. */
+typedef union
+{
+ struct
+ {
+ int __lock;
+ unsigned int __nr_readers;
+ unsigned int __readers_wakeup;
+ unsigned int __writer_wakeup;
+ unsigned int __nr_readers_queued;
+ unsigned int __nr_writers_queued;
+ int __writer;
+ int __pad1;
+ unsigned long int __pad2;
+ unsigned long int __pad3;
+ /* FLAGS must stay at this position in the structure to maintain
+ binary compatibility. */
+ unsigned int __flags;
+ } __data;
+ char __size[__SIZEOF_PTHREAD_RWLOCK_T];
+ long int __align;
+} pthread_rwlock_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_RWLOCKATTR_T];
+ long int __align;
+} pthread_rwlockattr_t;
+#endif
+
+
+#ifdef __USE_XOPEN2K
+/* POSIX spinlock data type. */
+typedef volatile int pthread_spinlock_t;
+
+
+/* POSIX barriers data type. The structure of the type is
+ deliberately not exposed. */
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_BARRIER_T];
+ long int __align;
+} pthread_barrier_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_BARRIERATTR_T];
+ int __align;
+} pthread_barrierattr_t;
+#endif
+
+
+#endif /* bits/pthreadtypes.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/bits/semaphore.h b/libc/nptl/sysdeps/unix/sysv/linux/ia64/bits/semaphore.h
new file mode 100644
index 000000000..2329e9866
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/bits/semaphore.h
@@ -0,0 +1,39 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+#ifndef _SEMAPHORE_H
+# error "Never use <bits/semaphore.h> directly; include <semaphore.h> instead."
+#endif
+
+
+#define __SIZEOF_SEM_T 32
+
+
+/* Value returned if `sem_open' failed. */
+#define SEM_FAILED ((sem_t *) 0)
+
+/* Maximum value the semaphore can have. */
+#define SEM_VALUE_MAX (2147483647)
+
+
+typedef union
+{
+ char __size[__SIZEOF_SEM_T];
+ long int __align;
+} sem_t;
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/clone2.S b/libc/nptl/sysdeps/unix/sysv/linux/ia64/clone2.S
new file mode 100644
index 000000000..91f28bab3
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/clone2.S
@@ -0,0 +1,9 @@
+/* We want an #include_next, but we are the main source file.
+ So, #include ourselves and in that incarnation we can use #include_next. */
+#ifndef INCLUDED_SELF
+# define INCLUDED_SELF
+# include <clone2.S>
+#else
+# define RESET_PID
+# include_next <clone2.S>
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/createthread.c b/libc/nptl/sysdeps/unix/sysv/linux/ia64/createthread.c
new file mode 100644
index 000000000..cd5f8137d
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/createthread.c
@@ -0,0 +1,26 @@
+/* Copyright (C) 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>.
+
+ 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. */
+
+/* Value passed to 'clone' for initialization of the thread register. */
+#define TLS_VALUE ((char *) pd + TLS_PRE_TCB_SIZE)
+
+#define ARCH_CLONE __clone2
+
+/* Get the real implementation. */
+#include <nptl/sysdeps/pthread/createthread.c>
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/dl-sysdep.h b/libc/nptl/sysdeps/unix/sysv/linux/ia64/dl-sysdep.h
new file mode 100644
index 000000000..525b622a6
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/dl-sysdep.h
@@ -0,0 +1,68 @@
+/* System-specific settings for dynamic linker code. IA-64 version.
+ Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+#ifndef _DL_SYSDEP_H
+#define _DL_SYSDEP_H 1
+
+/* This macro must be defined to either 0 or 1.
+
+ If 1, then an errno global variable hidden in ld.so will work right with
+ all the errno-using libc code compiled for ld.so, and there is never a
+ need to share the errno location with libc. This is appropriate only if
+ all the libc functions that ld.so uses are called without PLT and always
+ get the versions linked into ld.so rather than the libc ones. */
+
+#ifdef IS_IN_rtld
+# define RTLD_PRIVATE_ERRNO 1
+#else
+# define RTLD_PRIVATE_ERRNO 0
+#endif
+
+/* Traditionally system calls have been made using break 0x100000. A
+ second method was introduced which, if possible, will use the EPC
+ instruction. To signal the presence and where to find the code the
+ kernel passes an AT_SYSINFO_EHDR pointer in the auxiliary vector to
+ the application. */
+#define NEED_DL_SYSINFO 1
+#define USE_DL_SYSINFO 1
+
+#if defined NEED_DL_SYSINFO && !defined __ASSEMBLER__
+/* Don't declare this as a function---we want it's entry-point, not
+ it's function descriptor... */
+extern int _dl_sysinfo_break attribute_hidden;
+# define DL_SYSINFO_DEFAULT ((uintptr_t) &_dl_sysinfo_break)
+# define DL_SYSINFO_IMPLEMENTATION \
+ asm (".text\n\t" \
+ ".hidden _dl_sysinfo_break\n\t" \
+ ".proc _dl_sysinfo_break\n\t" \
+ "_dl_sysinfo_break:\n\t" \
+ ".prologue\n\t" \
+ ".altrp b6\n\t" \
+ ".body\n\t" \
+ "break 0x100000;\n\t" \
+ "br.ret.sptk.many b6;\n\t" \
+ ".endp _dl_sysinfo_break\n\t" \
+ ".previous");
+#endif
+
+/* _dl_argv cannot be attribute_relro, because _dl_start_user
+ might write into it after _dl_start returns. */
+#define DL_ARGV_NOT_RELRO 1
+
+#endif /* dl-sysdep.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/fork.c b/libc/nptl/sysdeps/unix/sysv/linux/ia64/fork.c
new file mode 100644
index 000000000..1502310f1
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/fork.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 <sched.h>
+#include <signal.h>
+#include <sysdep.h>
+#include <tls.h>
+
+
+#define ARCH_FORK() \
+ INLINE_SYSCALL (clone2, 6, \
+ CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, \
+ NULL, 0, NULL, &THREAD_SELF->tid, NULL)
+
+#include "../fork.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/lowlevellock.h b/libc/nptl/sysdeps/unix/sysv/linux/ia64/lowlevellock.h
new file mode 100644
index 000000000..8df997a26
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/lowlevellock.h
@@ -0,0 +1,287 @@
+/* Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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. */
+
+#ifndef _LOWLEVELLOCK_H
+#define _LOWLEVELLOCK_H 1
+
+#include <time.h>
+#include <sys/param.h>
+#include <bits/pthreadtypes.h>
+#include <ia64intrin.h>
+#include <atomic.h>
+
+#define __NR_futex 1230
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+#define FUTEX_REQUEUE 3
+#define FUTEX_CMP_REQUEUE 4
+#define FUTEX_WAKE_OP 5
+#define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE ((4 << 24) | 1)
+#define FUTEX_LOCK_PI 6
+#define FUTEX_UNLOCK_PI 7
+#define FUTEX_TRYLOCK_PI 8
+
+/* Delay in spinlock loop. */
+#define BUSY_WAIT_NOP asm ("hint @pause")
+
+/* Initializer for compatibility lock. */
+#define LLL_MUTEX_LOCK_INITIALIZER (0)
+
+#define lll_futex_wait(futex, val) lll_futex_timed_wait (futex, val, 0)
+
+#define lll_futex_timed_wait(ftx, val, timespec) \
+({ \
+ DO_INLINE_SYSCALL(futex, 4, (long) (ftx), FUTEX_WAIT, (int) (val), \
+ (long) (timespec)); \
+ _r10 == -1 ? -_retval : _retval; \
+})
+
+#define lll_futex_wake(ftx, nr) \
+({ \
+ DO_INLINE_SYSCALL(futex, 3, (long) (ftx), FUTEX_WAKE, (int) (nr)); \
+ _r10 == -1 ? -_retval : _retval; \
+})
+
+#define lll_robust_mutex_dead(futexv) \
+do \
+ { \
+ int *__futexp = &(futexv); \
+ atomic_or (__futexp, FUTEX_OWNER_DIED); \
+ DO_INLINE_SYSCALL(futex, 3, (long) __futexp, FUTEX_WAKE, 1); \
+ } \
+while (0)
+
+/* Returns non-zero if error happened, zero if success. */
+#define lll_futex_requeue(ftx, nr_wake, nr_move, mutex, val) \
+({ \
+ DO_INLINE_SYSCALL(futex, 6, (long) (ftx), FUTEX_CMP_REQUEUE, \
+ (int) (nr_wake), (int) (nr_move), (long) (mutex), \
+ (int) val); \
+ _r10 == -1; \
+})
+
+/* Returns non-zero if error happened, zero if success. */
+#define lll_futex_wake_unlock(ftx, nr_wake, nr_wake2, ftx2) \
+({ \
+ DO_INLINE_SYSCALL(futex, 6, (long) (ftx), FUTEX_WAKE_OP, \
+ (int) (nr_wake), (int) (nr_wake2), (long) (ftx2), \
+ FUTEX_OP_CLEAR_WAKE_IF_GT_ONE); \
+ _r10 == -1; \
+})
+
+
+#define __lll_mutex_trylock(futex) \
+ (atomic_compare_and_exchange_val_acq (futex, 1, 0) != 0)
+#define lll_mutex_trylock(futex) __lll_mutex_trylock (&(futex))
+
+
+#define __lll_robust_mutex_trylock(futex, id) \
+ (atomic_compare_and_exchange_val_acq (futex, id, 0) != 0)
+#define lll_robust_mutex_trylock(futex, id) \
+ __lll_robust_mutex_trylock (&(futex), id)
+
+
+#define __lll_mutex_cond_trylock(futex) \
+ (atomic_compare_and_exchange_val_acq (futex, 2, 0) != 0)
+#define lll_mutex_cond_trylock(futex) __lll_mutex_cond_trylock (&(futex))
+
+
+extern void __lll_lock_wait (int *futex) attribute_hidden;
+extern int __lll_robust_lock_wait (int *futex) attribute_hidden;
+
+
+#define __lll_mutex_lock(futex) \
+ ((void) ({ \
+ int *__futex = (futex); \
+ if (atomic_compare_and_exchange_bool_acq (__futex, 1, 0) != 0) \
+ __lll_lock_wait (__futex); \
+ }))
+#define lll_mutex_lock(futex) __lll_mutex_lock (&(futex))
+
+
+#define __lll_robust_mutex_lock(futex, id) \
+ ({ \
+ int *__futex = (futex); \
+ int __val = 0; \
+ \
+ if (atomic_compare_and_exchange_bool_acq (__futex, id, 0) != 0) \
+ __val = __lll_robust_lock_wait (__futex); \
+ __val; \
+ })
+#define lll_robust_mutex_lock(futex, id) __lll_robust_mutex_lock (&(futex), id)
+
+
+#define __lll_mutex_cond_lock(futex) \
+ ((void) ({ \
+ int *__futex = (futex); \
+ if (atomic_compare_and_exchange_bool_acq (__futex, 2, 0) != 0) \
+ __lll_lock_wait (__futex); \
+ }))
+#define lll_mutex_cond_lock(futex) __lll_mutex_cond_lock (&(futex))
+
+
+#define __lll_robust_mutex_cond_lock(futex, id) \
+ ({ \
+ int *__futex = (futex); \
+ int __val = 0; \
+ int __id = (id) | FUTEX_WAITERS; \
+ \
+ if (atomic_compare_and_exchange_bool_acq (__futex, __id, 0) != 0) \
+ __val = __lll_robust_lock_wait (__futex); \
+ __val; \
+ })
+#define lll_robust_mutex_cond_lock(futex, id) \
+ __lll_robust_mutex_cond_lock (&(futex), id)
+
+
+extern int __lll_timedlock_wait (int *futex, const struct timespec *)
+ attribute_hidden;
+extern int __lll_robust_timedlock_wait (int *futex, const struct timespec *)
+ attribute_hidden;
+
+
+#define __lll_mutex_timedlock(futex, abstime) \
+ ({ \
+ int *__futex = (futex); \
+ int __val = 0; \
+ \
+ if (atomic_compare_and_exchange_bool_acq (__futex, 1, 0) != 0) \
+ __val = __lll_timedlock_wait (__futex, abstime); \
+ __val; \
+ })
+#define lll_mutex_timedlock(futex, abstime) \
+ __lll_mutex_timedlock (&(futex), abstime)
+
+
+#define __lll_robust_mutex_timedlock(futex, abstime, id) \
+ ({ \
+ int *__futex = (futex); \
+ int __val = 0; \
+ \
+ if (atomic_compare_and_exchange_bool_acq (__futex, id, 0) != 0) \
+ __val = __lll_robust_timedlock_wait (__futex, abstime); \
+ __val; \
+ })
+#define lll_robust_mutex_timedlock(futex, abstime, id) \
+ __lll_robust_mutex_timedlock (&(futex), abstime, id)
+
+
+#define __lll_mutex_unlock(futex) \
+ ((void) ({ \
+ int *__futex = (futex); \
+ int __val = atomic_exchange_rel (__futex, 0); \
+ \
+ if (__builtin_expect (__val > 1, 0)) \
+ lll_futex_wake (__futex, 1); \
+ }))
+#define lll_mutex_unlock(futex) \
+ __lll_mutex_unlock(&(futex))
+
+
+#define __lll_robust_mutex_unlock(futex) \
+ ((void) ({ \
+ int *__futex = (futex); \
+ int __val = atomic_exchange_rel (__futex, 0); \
+ \
+ if (__builtin_expect (__val & FUTEX_WAITERS, 0)) \
+ lll_futex_wake (__futex, 1); \
+ }))
+#define lll_robust_mutex_unlock(futex) \
+ __lll_robust_mutex_unlock(&(futex))
+
+
+#define __lll_mutex_unlock_force(futex) \
+ ((void) ({ \
+ int *__futex = (futex); \
+ (void) atomic_exchange_rel (__futex, 0); \
+ lll_futex_wake (__futex, 1); \
+ }))
+#define lll_mutex_unlock_force(futex) \
+ __lll_mutex_unlock_force(&(futex))
+
+
+#define lll_mutex_islocked(futex) \
+ (futex != 0)
+
+
+/* We have a separate internal lock implementation which is not tied
+ to binary compatibility. We can use the lll_mutex_*. */
+
+/* Type for lock object. */
+typedef int lll_lock_t;
+
+extern int lll_unlock_wake_cb (int *__futex) attribute_hidden;
+
+/* Initializers for lock. */
+#define LLL_LOCK_INITIALIZER (0)
+#define LLL_LOCK_INITIALIZER_LOCKED (1)
+
+#define lll_trylock(futex) lll_mutex_trylock (futex)
+#define lll_lock(futex) lll_mutex_lock (futex)
+#define lll_unlock(futex) lll_mutex_unlock (futex)
+#define lll_islocked(futex) lll_mutex_islocked (futex)
+
+
+/* The kernel notifies a process with uses CLONE_CLEARTID via futex
+ wakeup when the clone terminates. The memory location contains the
+ thread ID while the clone is running and is reset to zero
+ afterwards. */
+#define lll_wait_tid(tid) \
+ do \
+ { \
+ __typeof (tid) __tid; \
+ while ((__tid = (tid)) != 0) \
+ lll_futex_wait (&(tid), __tid); \
+ } \
+ while (0)
+
+extern int __lll_timedwait_tid (int *, const struct timespec *)
+ attribute_hidden;
+
+#define lll_timedwait_tid(tid, abstime) \
+ ({ \
+ int __res = 0; \
+ if ((tid) != 0) \
+ __res = __lll_timedwait_tid (&(tid), (abstime)); \
+ __res; \
+ })
+
+
+/* Conditional variable handling. */
+
+extern void __lll_cond_wait (pthread_cond_t *cond)
+ attribute_hidden;
+extern int __lll_cond_timedwait (pthread_cond_t *cond,
+ const struct timespec *abstime)
+ attribute_hidden;
+extern void __lll_cond_wake (pthread_cond_t *cond)
+ attribute_hidden;
+extern void __lll_cond_broadcast (pthread_cond_t *cond)
+ attribute_hidden;
+
+#define lll_cond_wait(cond) \
+ __lll_cond_wait (cond)
+#define lll_cond_timedwait(cond, abstime) \
+ __lll_cond_timedwait (cond, abstime)
+#define lll_cond_wake(cond) \
+ __lll_cond_wake (cond)
+#define lll_cond_broadcast(cond) \
+ __lll_cond_broadcast (cond)
+
+#endif /* lowlevellock.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/pt-initfini.c b/libc/nptl/sysdeps/unix/sysv/linux/ia64/pt-initfini.c
new file mode 100644
index 000000000..b6d2cec0d
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/pt-initfini.c
@@ -0,0 +1,50 @@
+/* Special .init and .fini section support for ia64. NPTL version.
+ Copyright (C) 2000, 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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.
+
+ In addition to the permissions in the GNU Lesser General Public
+ License, the Free Software Foundation gives you unlimited
+ permission to link the compiled version of this file with other
+ programs, and to distribute those programs without any restriction
+ coming from the use of this file. (The Lesser General Public
+ License restrictions do apply in other respects; for example, they
+ cover modification of the file, and distribution when not linked
+ into another program.)
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* This file is compiled into assembly code which is then munged by a sed
+ script into two files: crti.s and crtn.s.
+
+ * crti.s puts a function prologue at the beginning of the
+ .init and .fini sections and defines global symbols for
+ those addresses, so they can be called as functions.
+
+ * crtn.s puts the corresponding function epilogues
+ in the .init and .fini sections. */
+
+#include <stddef.h>
+
+
+__asm__ ("\n\
+#include \"defs.h\"\n\
+\n\
+/*@HEADER_ENDS*/\n\
+\n\
+/*@_init_PROLOG_BEGINS*/\n\
+ .xdata8 \".init_array\",@fptr(__pthread_initialize_minimal_internal)\n\
+/*@_init_PROLOG_ENDS*/\n\
+");
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/pt-vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/ia64/pt-vfork.S
new file mode 100644
index 000000000..a28528003
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/pt-vfork.S
@@ -0,0 +1,60 @@
+/* Copyright (C) 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#define _SIGNAL_H
+#include <bits/signum.h>
+#include <tcb-offsets.h>
+
+/* The following are defined in linux/sched.h, which unfortunately */
+/* is not safe for inclusion in an assembly file. */
+#define CLONE_VM 0x00000100 /* set if VM shared between processes */
+#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
+
+/* pid_t vfork(void); */
+/* Implemented as __clone_syscall(CLONE_VFORK | CLONE_VM | SIGCHLD, 0) */
+
+ENTRY(__vfork)
+ .prologue // work around a GAS bug which triggers if
+ .body // first .prologue is not at the beginning of proc.
+ alloc r2=ar.pfs,0,0,2,0
+ adds r14=PID,r13
+ ;;
+ ld4 r16=[r14]
+ ;;
+ sub r15=0,r16
+ mov out0=CLONE_VM+CLONE_VFORK+SIGCHLD
+ mov out1=0 /* Standard sp value. */
+ ;;
+ st4 [r14]=r15
+ DO_CALL (SYS_ify (clone))
+ cmp.eq p0,p7=0,r8
+ adds r14=PID,r13
+ ;;
+(p7) ld4 r16=[r14]
+ cmp.eq p6,p0=-1,r10
+ ;;
+(p7) sub r15=0,r16
+ ;;
+(p7) st4 [r14]=r15
+(p6) br.cond.spnt.few __syscall_error
+ ret
+PSEUDO_END(__vfork)
+
+weak_alias (__vfork, vfork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/pthread_once.c b/libc/nptl/sysdeps/unix/sysv/linux/ia64/pthread_once.c
new file mode 100644
index 000000000..3b07cc127
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/pthread_once.c
@@ -0,0 +1,94 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 "pthreadP.h"
+#include <lowlevellock.h>
+
+
+unsigned long int __fork_generation attribute_hidden;
+
+
+static void
+clear_once_control (void *arg)
+{
+ pthread_once_t *once_control = (pthread_once_t *) arg;
+
+ *once_control = 0;
+ lll_futex_wake (once_control, INT_MAX);
+}
+
+
+int
+__pthread_once (once_control, init_routine)
+ pthread_once_t *once_control;
+ void (*init_routine) (void);
+{
+ while (1)
+ {
+ int oldval, val, newval;
+
+ val = *once_control;
+ do
+ {
+ /* Check if the initialized has already been done. */
+ if ((val & 2) != 0)
+ return 0;
+
+ oldval = val;
+ newval = (oldval & 3) | __fork_generation | 1;
+ val = atomic_compare_and_exchange_val_acq (once_control, newval,
+ oldval);
+ }
+ while (__builtin_expect (val != oldval, 0));
+
+ /* Check if another thread already runs the initializer. */
+ if ((oldval & 1) != 0)
+ {
+ /* Check whether the initializer execution was interrupted
+ by a fork. */
+ if (((oldval ^ newval) & -4) == 0)
+ {
+ /* Same generation, some other thread was faster. Wait. */
+ lll_futex_wait (once_control, newval);
+ continue;
+ }
+ }
+
+ /* This thread is the first here. Do the initialization.
+ Register a cleanup handler so that in case the thread gets
+ interrupted the initialization can be restarted. */
+ pthread_cleanup_push (clear_once_control, once_control);
+
+ init_routine ();
+
+ pthread_cleanup_pop (0);
+
+
+ /* Add one to *once_control. */
+ atomic_increment (once_control);
+
+ /* Wake up all other threads. */
+ lll_futex_wake (once_control, INT_MAX);
+ break;
+ }
+
+ return 0;
+}
+weak_alias (__pthread_once, pthread_once)
+strong_alias (__pthread_once, __pthread_once_internal)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h b/libc/nptl/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h
new file mode 100644
index 000000000..63aaa96eb
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h
@@ -0,0 +1,222 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <tls.h>
+#ifndef __ASSEMBLER__
+# include <nptl/pthreadP.h>
+#endif
+
+#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
+
+# undef PSEUDO
+
+# if USE___THREAD
+# ifndef NOT_IN_libc
+# define SYSDEP_CANCEL_ERRNO __libc_errno
+# else
+# define SYSDEP_CANCEL_ERRNO errno
+# endif
+# define SYSDEP_CANCEL_ERROR(args) \
+.section .gnu.linkonce.t.__syscall_error_##args, "ax"; \
+ .align 32; \
+ .proc __syscall_error_##args; \
+ .global __syscall_error_##args; \
+ .hidden __syscall_error_##args; \
+ .size __syscall_error_##args, 64; \
+__syscall_error_##args: \
+ .prologue; \
+ .regstk args, 5, args, 0; \
+ .save ar.pfs, loc0; \
+ .save rp, loc1; \
+ .body; \
+ addl loc4 = @ltoff(@tprel(SYSDEP_CANCEL_ERRNO)), gp;; \
+ ld8 loc4 = [loc4]; \
+ mov rp = loc1;; \
+ mov r8 = -1; \
+ add loc4 = loc4, r13;; \
+ st4 [loc4] = loc3; \
+ mov ar.pfs = loc0
+# else
+# define SYSDEP_CANCEL_ERROR(args) \
+.section .gnu.linkonce.t.__syscall_error_##args, "ax"; \
+ .align 32; \
+ .proc __syscall_error_##args; \
+ .global __syscall_error_##args; \
+ .hidden __syscall_error_##args; \
+ .size __syscall_error_##args, 64; \
+__syscall_error_##args: \
+ .prologue; \
+ .regstk args, 5, args, 0; \
+ .save ar.pfs, loc0; \
+ .save rp, loc1; \
+ .body; \
+ mov loc4 = r1;; \
+ br.call.sptk.many b0 = __errno_location;; \
+ st4 [r8] = loc3; \
+ mov r1 = loc4; \
+ mov rp = loc1; \
+ mov r8 = -1; \
+ mov ar.pfs = loc0
+# endif
+
+# ifndef USE_DL_SYSINFO
+
+# define PSEUDO(name, syscall_name, args) \
+.text; \
+ENTRY (name) \
+ adds r14 = MULTIPLE_THREADS_OFFSET, r13;; \
+ ld4 r14 = [r14]; \
+ mov r15 = SYS_ify(syscall_name);; \
+ cmp4.ne p6, p7 = 0, r14; \
+(p6) br.cond.spnt .Lpseudo_cancel;; \
+ break __BREAK_SYSCALL;; \
+ cmp.eq p6,p0=-1,r10; \
+(p6) br.cond.spnt.few __syscall_error; \
+ ret;; \
+ .endp name; \
+ .proc __GC_##name; \
+ .globl __GC_##name; \
+ .hidden __GC_##name; \
+__GC_##name: \
+.Lpseudo_cancel: \
+ .prologue; \
+ .regstk args, 5, args, 0; \
+ .save ar.pfs, loc0; \
+ alloc loc0 = ar.pfs, args, 5, args, 0; \
+ .save rp, loc1; \
+ mov loc1 = rp;; \
+ .body; \
+ CENABLE;; \
+ mov loc2 = r8; \
+ COPY_ARGS_##args \
+ mov r15 = SYS_ify(syscall_name); \
+ break __BREAK_SYSCALL;; \
+ mov loc3 = r8; \
+ mov loc4 = r10; \
+ mov out0 = loc2; \
+ CDISABLE;; \
+ cmp.eq p6,p0=-1,loc4; \
+(p6) br.cond.spnt.few __syscall_error_##args; \
+ mov r8 = loc3; \
+ mov rp = loc1; \
+ mov ar.pfs = loc0; \
+.Lpseudo_end: \
+ ret; \
+ .endp __GC_##name; \
+ SYSDEP_CANCEL_ERROR(args)
+
+# else /* USE_DL_SYSINFO */
+
+# define PSEUDO(name, syscall_name, args) \
+.text; \
+ENTRY (name) \
+ .prologue; \
+ adds r2 = SYSINFO_OFFSET, r13; \
+ adds r14 = MULTIPLE_THREADS_OFFSET, r13; \
+ .save ar.pfs, r11; \
+ mov r11 = ar.pfs;; \
+ .body; \
+ ld4 r14 = [r14]; \
+ ld8 r2 = [r2]; \
+ mov r15 = SYS_ify(syscall_name);; \
+ cmp4.ne p6, p7 = 0, r14; \
+ mov b7 = r2; \
+(p6) br.cond.spnt .Lpseudo_cancel; \
+ br.call.sptk.many b6 = b7;; \
+ mov ar.pfs = r11; \
+ cmp.eq p6,p0 = -1, r10; \
+(p6) br.cond.spnt.few __syscall_error; \
+ ret;; \
+ .endp name; \
+ .proc __GC_##name; \
+ .globl __GC_##name; \
+ .hidden __GC_##name; \
+__GC_##name: \
+.Lpseudo_cancel: \
+ .prologue; \
+ .regstk args, 5, args, 0; \
+ .save ar.pfs, loc0; \
+ alloc loc0 = ar.pfs, args, 5, args, 0; \
+ adds loc4 = SYSINFO_OFFSET, r13; \
+ .save rp, loc1; \
+ mov loc1 = rp;; \
+ .body; \
+ ld8 loc4 = [loc4]; \
+ CENABLE;; \
+ mov loc2 = r8; \
+ mov b7 = loc4; \
+ COPY_ARGS_##args \
+ mov r15 = SYS_ify(syscall_name); \
+ br.call.sptk.many b6 = b7;; \
+ mov loc3 = r8; \
+ mov loc4 = r10; \
+ mov out0 = loc2; \
+ CDISABLE;; \
+ cmp.eq p6,p0=-1,loc4; \
+(p6) br.cond.spnt.few __syscall_error_##args; \
+ mov r8 = loc3; \
+ mov rp = loc1; \
+ mov ar.pfs = loc0; \
+.Lpseudo_end: \
+ ret; \
+ .endp __GC_##name; \
+ SYSDEP_CANCEL_ERROR(args)
+
+# endif /* USE_DL_SYSINFO */
+
+# undef PSEUDO_END
+# define PSEUDO_END(name) .endp
+
+# ifdef IS_IN_libpthread
+# define CENABLE br.call.sptk.many b0 = __pthread_enable_asynccancel
+# define CDISABLE br.call.sptk.many b0 = __pthread_disable_asynccancel
+# 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
+# elif defined IS_IN_librt
+# define CENABLE br.call.sptk.many b0 = __librt_enable_asynccancel
+# define CDISABLE br.call.sptk.many b0 = __librt_disable_asynccancel
+# else
+# error Unsupported library
+# endif
+
+# define COPY_ARGS_0 /* Nothing */
+# define COPY_ARGS_1 COPY_ARGS_0 mov out0 = in0;
+# define COPY_ARGS_2 COPY_ARGS_1 mov out1 = in1;
+# define COPY_ARGS_3 COPY_ARGS_2 mov out2 = in2;
+# define COPY_ARGS_4 COPY_ARGS_3 mov out3 = in3;
+# define COPY_ARGS_5 COPY_ARGS_4 mov out4 = in4;
+# define COPY_ARGS_6 COPY_ARGS_5 mov out5 = in5;
+# define COPY_ARGS_7 COPY_ARGS_6 mov out6 = in6;
+
+# ifndef __ASSEMBLER__
+# define SINGLE_THREAD_P \
+ __builtin_expect (THREAD_GETMEM (THREAD_SELF, header.multiple_threads) == 0, 1)
+# else
+# define SINGLE_THREAD_P \
+ adds r14 = MULTIPLE_THREADS_OFFSET, r13 ;; ld4 r14 = [r14] ;; cmp4.ne p6, p7 = 0, r14
+# endif
+
+#elif !defined __ASSEMBLER__
+
+# define SINGLE_THREAD_P (1)
+# define NO_CANCELLATION 1
+
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/timer_create.c b/libc/nptl/sysdeps/unix/sysv/linux/ia64/timer_create.c
new file mode 100644
index 000000000..172223af3
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/timer_create.c
@@ -0,0 +1 @@
+#include "../x86_64/timer_create.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/timer_delete.c b/libc/nptl/sysdeps/unix/sysv/linux/ia64/timer_delete.c
new file mode 100644
index 000000000..537516e0a
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/timer_delete.c
@@ -0,0 +1 @@
+#include "../x86_64/timer_delete.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/timer_getoverr.c b/libc/nptl/sysdeps/unix/sysv/linux/ia64/timer_getoverr.c
new file mode 100644
index 000000000..3f21a73c9
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/timer_getoverr.c
@@ -0,0 +1 @@
+#include "../x86_64/timer_getoverr.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/timer_gettime.c b/libc/nptl/sysdeps/unix/sysv/linux/ia64/timer_gettime.c
new file mode 100644
index 000000000..a50143adc
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/timer_gettime.c
@@ -0,0 +1 @@
+#include "../x86_64/timer_gettime.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/timer_settime.c b/libc/nptl/sysdeps/unix/sysv/linux/ia64/timer_settime.c
new file mode 100644
index 000000000..37baeffac
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/timer_settime.c
@@ -0,0 +1 @@
+#include "../x86_64/timer_settime.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/unwind-forcedunwind.c b/libc/nptl/sysdeps/unix/sysv/linux/ia64/unwind-forcedunwind.c
new file mode 100644
index 000000000..d0c77a62e
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/unwind-forcedunwind.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <dlfcn.h>
+#include <stdio.h>
+#include <unwind.h>
+#include <pthreadP.h>
+
+static _Unwind_Word (*libgcc_s_getbsp) (struct _Unwind_Context *);
+
+#define ARCH_CANCEL_INIT(handle) \
+ ((libgcc_s_getbsp = __libc_dlsym (handle, "_Unwind_GetBSP")) == NULL)
+
+#include <sysdeps/pthread/unwind-forcedunwind.c>
+
+_Unwind_Word
+_Unwind_GetBSP (struct _Unwind_Context *context)
+{
+ if (__builtin_expect (libgcc_s_getbsp == NULL, 0))
+ pthread_cancel_init ();
+
+ return libgcc_s_getbsp (context);
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/unwind_longjmp.c b/libc/nptl/sysdeps/unix/sysv/linux/ia64/unwind_longjmp.c
new file mode 100644
index 000000000..7976ff8f1
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/unwind_longjmp.c
@@ -0,0 +1,44 @@
+/* Copyright (C) 1991,92,94,95,97,98,2000,02,04 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <stddef.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <pthreadP.h>
+#include <jmpbuf-unwind.h>
+
+extern void __sigstack_longjmp (__jmp_buf, int)
+ __attribute__ ((noreturn));
+
+/* Like __libc_siglongjmp(), but safe for crossing from alternate
+ signal stack to normal stack. Needed by NPTL. */
+void
+__libc_unwind_longjmp (sigjmp_buf env, int val)
+{
+ /* Perform any cleanups needed by the frames being unwound. */
+ __pthread_cleanup_upto (env->__jmpbuf, CURRENT_STACK_FRAME);
+
+ if (env[0].__mask_was_saved)
+ /* Restore the saved signal mask. */
+ (void) __sigprocmask (SIG_SETMASK, &env[0].__saved_mask,
+ (sigset_t *) NULL);
+
+ /* Call the machine-dependent function to restore machine state. */
+ __sigstack_longjmp (env[0].__jmpbuf, val ?: 1);
+}
+hidden_def (__libc_unwind_longjmp)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/ia64/vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/ia64/vfork.S
new file mode 100644
index 000000000..3bd721f14
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/ia64/vfork.S
@@ -0,0 +1,69 @@
+/* Copyright (C) 2000, 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#define _SIGNAL_H
+#include <bits/signum.h>
+#include <tcb-offsets.h>
+
+/* The following are defined in linux/sched.h, which unfortunately */
+/* is not safe for inclusion in an assembly file. */
+#define CLONE_VM 0x00000100 /* set if VM shared between processes */
+#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
+
+/* pid_t vfork(void); */
+/* Implemented as __clone_syscall(CLONE_VFORK | CLONE_VM | SIGCHLD, 0) */
+
+ENTRY(__vfork)
+ .prologue // work around a GAS bug which triggers if
+ .body // first .prologue is not at the beginning of proc.
+ alloc r2=ar.pfs,0,0,2,0
+ adds r14=PID,r13
+ ;;
+ ld4 r16=[r14]
+ ;;
+ sub r15=0,r16
+ cmp.eq p6,p0=0,r16
+ ;;
+(p6) movl r15=0x80000000
+ mov out0=CLONE_VM+CLONE_VFORK+SIGCHLD
+ mov out1=0 /* Standard sp value. */
+ ;;
+ st4 [r14]=r15
+ DO_CALL (SYS_ify (clone))
+ cmp.eq p6,p0=0,r8
+ adds r14=PID,r13
+(p6) br.cond.dptk 1f
+ ;;
+ ld4 r15=[r14]
+ ;;
+ extr.u r16=r15,0,31
+ ;;
+ cmp.eq p0,p6=0,r16
+ ;;
+(p6) sub r16=0,r15
+ ;;
+ st4 [r14]=r16
+1:
+ cmp.eq p6,p0=-1,r10
+(p6) br.cond.spnt.few __syscall_error
+ ret
+PSEUDO_END(__vfork)
+libc_hidden_def (__vfork)
+weak_alias (__vfork, vfork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/internaltypes.h b/libc/nptl/sysdeps/unix/sysv/linux/internaltypes.h
new file mode 100644
index 000000000..1dec19e57
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/internaltypes.h
@@ -0,0 +1,152 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+#ifndef _INTERNALTYPES_H
+#define _INTERNALTYPES_H 1
+
+#include <stdint.h>
+
+
+struct pthread_attr
+{
+ /* Scheduler parameters and priority. */
+ struct sched_param schedparam;
+ int schedpolicy;
+ /* Various flags like detachstate, scope, etc. */
+ int flags;
+ /* Size of guard area. */
+ size_t guardsize;
+ /* Stack handling. */
+ void *stackaddr;
+ size_t stacksize;
+ /* Affinity map. */
+ cpu_set_t *cpuset;
+ size_t cpusetsize;
+};
+
+#define ATTR_FLAG_DETACHSTATE 0x0001
+#define ATTR_FLAG_NOTINHERITSCHED 0x0002
+#define ATTR_FLAG_SCOPEPROCESS 0x0004
+#define ATTR_FLAG_STACKADDR 0x0008
+#define ATTR_FLAG_OLDATTR 0x0010
+#define ATTR_FLAG_SCHED_SET 0x0020
+#define ATTR_FLAG_POLICY_SET 0x0040
+
+
+/* Mutex attribute data structure. */
+struct pthread_mutexattr
+{
+ /* Identifier for the kind of mutex.
+
+ Bit 31 is set if the mutex is to be shared between processes.
+
+ Bit 0 to 30 contain one of the PTHREAD_MUTEX_ values to identify
+ the type of the mutex. */
+ int mutexkind;
+};
+
+
+/* Conditional variable attribute data structure. */
+struct pthread_condattr
+{
+ /* Combination of values:
+
+ Bit 0 : flag whether coditional variable will be shareable between
+ processes.
+
+ Bit 1-7: clock ID. */
+ int value;
+};
+
+
+/* The __NWAITERS field is used as a counter and to house the number
+ of bits which represent the clock. COND_CLOCK_BITS is the number
+ of bits reserved for the clock. */
+#define COND_CLOCK_BITS 1
+
+
+/* Read-write lock variable attribute data structure. */
+struct pthread_rwlockattr
+{
+ int lockkind;
+ int pshared;
+};
+
+
+/* Barrier data structure. */
+struct pthread_barrier
+{
+ unsigned int curr_event;
+ int lock;
+ unsigned int left;
+ unsigned int init_count;
+};
+
+
+/* Barrier variable attribute data structure. */
+struct pthread_barrierattr
+{
+ int pshared;
+};
+
+
+/* Thread-local data handling. */
+struct pthread_key_struct
+{
+ /* Sequence numbers. Even numbers indicated vacant entries. Note
+ that zero is even. We use uintptr_t to not require padding on
+ 32- and 64-bit machines. On 64-bit machines it helps to avoid
+ wrapping, too. */
+ uintptr_t seq;
+
+ /* Destructor for the data. */
+ void (*destr) (void *);
+};
+
+/* Check whether an entry is unused. */
+#define KEY_UNUSED(p) (((p) & 1) == 0)
+/* Check whether a key is usable. We cannot reuse an allocated key if
+ the sequence counter would overflow after the next destroy call.
+ This would mean that we potentially free memory for a key with the
+ same sequence. This is *very* unlikely to happen, A program would
+ have to create and destroy a key 2^31 times (on 32-bit platforms,
+ on 64-bit platforms that would be 2^63). If it should happen we
+ simply don't use this specific key anymore. */
+#define KEY_USABLE(p) (((uintptr_t) (p)) < ((uintptr_t) ((p) + 2)))
+
+
+/* Handling of read-write lock data. */
+// XXX For now there is only one flag. Maybe more in future.
+#define RWLOCK_RECURSIVE(rwlock) ((rwlock)->__data.__flags != 0)
+
+
+/* Semaphore variable structure. */
+struct sem
+{
+ unsigned int count;
+};
+
+
+/* Compatibility type for old conditional variable interfaces. */
+typedef struct
+{
+ pthread_cond_t *cond;
+} pthread_cond_2_0_t;
+
+#endif /* internaltypes.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/jmp-unwind.c b/libc/nptl/sysdeps/unix/sysv/linux/jmp-unwind.c
new file mode 100644
index 000000000..c435eff30
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/jmp-unwind.c
@@ -0,0 +1,39 @@
+/* Clean up stack frames unwound by longjmp. Linux version.
+ Copyright (C) 1995, 1997, 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <setjmp.h>
+#include <stddef.h>
+#include <pthreadP.h>
+
+extern void __pthread_cleanup_upto (__jmp_buf env, char *targetframe);
+#pragma weak __pthread_cleanup_upto
+
+
+void
+_longjmp_unwind (jmp_buf env, int val)
+{
+#ifdef SHARED
+# define fptr __libc_pthread_functions.ptr___pthread_cleanup_upto
+#else
+# define fptr __pthread_cleanup_upto
+#endif
+
+ if (fptr != NULL)
+ fptr (env->__jmpbuf, CURRENT_STACK_FRAME);
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/kernel-posix-timers.h b/libc/nptl/sysdeps/unix/sysv/linux/kernel-posix-timers.h
new file mode 100644
index 000000000..3ff4cda3f
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/kernel-posix-timers.h
@@ -0,0 +1,60 @@
+/* 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <sys/types.h>
+
+
+/* Nonzero if the system calls are not available. */
+extern int __no_posix_timers attribute_hidden;
+
+/* Callback to start helper thread. */
+extern void __start_helper_thread (void) attribute_hidden;
+
+/* Control variable for helper thread creation. */
+extern pthread_once_t __helper_once attribute_hidden;
+
+/* TID of the helper thread. */
+extern pid_t __helper_tid attribute_hidden;
+
+
+/* Type of timers in the kernel. */
+typedef int kernel_timer_t;
+
+
+/* Internal representation of timer. */
+struct timer
+{
+ /* Notification mechanism. */
+ int sigev_notify;
+
+ /* Timer ID returned by the kernel. */
+ kernel_timer_t ktimerid;
+
+ /* All new elements must be added after ktimerid. And if the thrfunc
+ element is not the third element anymore the memory allocation in
+ timer_create needs to be changed. */
+
+ /* Parameters for the thread to be started for SIGEV_THREAD. */
+ void (*thrfunc) (sigval_t);
+ sigval_t sival;
+ pthread_attr_t attr;
+};
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/libc-lowlevellock.c b/libc/nptl/sysdeps/unix/sysv/linux/libc-lowlevellock.c
new file mode 100644
index 000000000..b19282281
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/libc-lowlevellock.c
@@ -0,0 +1,21 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus@au.ibm.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. */
+
+/* No difference to lowlevellock.c, except we lose a couple of functions. */
+#include "lowlevellock.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/libc_multiple_threads.c b/libc/nptl/sysdeps/unix/sysv/linux/libc_multiple_threads.c
new file mode 100644
index 000000000..a96f17490
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/libc_multiple_threads.c
@@ -0,0 +1,26 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <pthreadP.h>
+
+#ifndef NOT_IN_libc
+# ifndef TLS_MULTIPLE_THREADS_IN_TCB
+int __libc_multiple_threads attribute_hidden;
+# endif
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/libc_pthread_init.c b/libc/nptl/sysdeps/unix/sysv/linux/libc_pthread_init.c
new file mode 100644
index 000000000..4e60596f7
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/libc_pthread_init.c
@@ -0,0 +1,59 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <unistd.h>
+#include <list.h>
+#include <fork.h>
+#include <dl-sysdep.h>
+#include <tls.h>
+#include <string.h>
+#include <pthreadP.h>
+#include <bits/libc-lock.h>
+
+
+#ifdef TLS_MULTIPLE_THREADS_IN_TCB
+void
+#else
+extern int __libc_multiple_threads attribute_hidden;
+
+int *
+#endif
+__libc_pthread_init (ptr, reclaim, functions)
+ unsigned long int *ptr;
+ void (*reclaim) (void);
+ const struct pthread_functions *functions;
+{
+ /* Remember the pointer to the generation counter in libpthread. */
+ __fork_generation_pointer = ptr;
+
+ /* Called by a child after fork. */
+ __register_atfork (NULL, NULL, reclaim, NULL);
+
+#ifdef SHARED
+ /* We copy the content of the variable pointed to by the FUNCTIONS
+ parameter to one in libc.so since this means access to the array
+ can be done with one memory access instead of two. */
+ memcpy (&__libc_pthread_functions, functions,
+ sizeof (__libc_pthread_functions));
+#endif
+
+#ifndef TLS_MULTIPLE_THREADS_IN_TCB
+ return &__libc_multiple_threads;
+#endif
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/lowlevelbarrier.sym b/libc/nptl/sysdeps/unix/sysv/linux/lowlevelbarrier.sym
new file mode 100644
index 000000000..36e28eb2a
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/lowlevelbarrier.sym
@@ -0,0 +1,11 @@
+#include <stddef.h>
+#include <sched.h>
+#include <bits/pthreadtypes.h>
+#include "internaltypes.h"
+
+--
+
+CURR_EVENT offsetof (struct pthread_barrier, curr_event)
+MUTEX offsetof (struct pthread_barrier, lock)
+LEFT offsetof (struct pthread_barrier, left)
+INIT_COUNT offsetof (struct pthread_barrier, init_count)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/lowlevelcond.sym b/libc/nptl/sysdeps/unix/sysv/linux/lowlevelcond.sym
new file mode 100644
index 000000000..c5e797806
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/lowlevelcond.sym
@@ -0,0 +1,16 @@
+#include <stddef.h>
+#include <sched.h>
+#include <bits/pthreadtypes.h>
+#include <internaltypes.h>
+
+--
+
+cond_lock offsetof (pthread_cond_t, __data.__lock)
+cond_futex offsetof (pthread_cond_t, __data.__futex)
+cond_nwaiters offsetof (pthread_cond_t, __data.__nwaiters)
+total_seq offsetof (pthread_cond_t, __data.__total_seq)
+wakeup_seq offsetof (pthread_cond_t, __data.__wakeup_seq)
+woken_seq offsetof (pthread_cond_t, __data.__woken_seq)
+dep_mutex offsetof (pthread_cond_t, __data.__mutex)
+broadcast_seq offsetof (pthread_cond_t, __data.__broadcast_seq)
+clock_bits COND_CLOCK_BITS
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/lowlevellock.c b/libc/nptl/sysdeps/unix/sysv/linux/lowlevellock.c
new file mode 100644
index 000000000..932e27300
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/lowlevellock.c
@@ -0,0 +1,131 @@
+/* low level locking for pthread library. Generic futex-using version.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus@au.ibm.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 <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <sys/time.h>
+
+
+void
+__lll_lock_wait (int *futex)
+{
+ do
+ {
+ int oldval = atomic_compare_and_exchange_val_acq (futex, 2, 1);
+ if (oldval != 0)
+ lll_futex_wait (futex, 2);
+ }
+ while (atomic_compare_and_exchange_bool_acq (futex, 2, 0) != 0);
+}
+
+
+int
+__lll_timedlock_wait (int *futex, const struct timespec *abstime)
+{
+ /* Reject invalid timeouts. */
+ if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)
+ return EINVAL;
+
+ do
+ {
+ struct timeval tv;
+ struct timespec rt;
+
+ /* Get the current time. */
+ (void) __gettimeofday (&tv, NULL);
+
+ /* Compute relative timeout. */
+ rt.tv_sec = abstime->tv_sec - tv.tv_sec;
+ rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
+ if (rt.tv_nsec < 0)
+ {
+ rt.tv_nsec += 1000000000;
+ --rt.tv_sec;
+ }
+
+ /* Already timed out? */
+ if (rt.tv_sec < 0)
+ return ETIMEDOUT;
+
+ /* Wait. */
+ int oldval = atomic_compare_and_exchange_val_acq (futex, 2, 1);
+ if (oldval != 0)
+ lll_futex_timed_wait (futex, 2, &rt);
+ }
+ while (atomic_compare_and_exchange_bool_acq (futex, 2, 0) != 0);
+
+ return 0;
+}
+
+
+/* These don't get included in libc.so */
+#ifdef IS_IN_libpthread
+int
+lll_unlock_wake_cb (int *futex)
+{
+ int val = atomic_exchange_rel (futex, 0);
+
+ if (__builtin_expect (val > 1, 0))
+ lll_futex_wake (futex, 1);
+
+ return 0;
+}
+
+
+int
+__lll_timedwait_tid (int *tidp, const struct timespec *abstime)
+{
+ int tid;
+
+ if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)
+ return EINVAL;
+
+ /* Repeat until thread terminated. */
+ while ((tid = *tidp) != 0)
+ {
+ struct timeval tv;
+ struct timespec rt;
+
+ /* Get the current time. */
+ (void) __gettimeofday (&tv, NULL);
+
+ /* Compute relative timeout. */
+ rt.tv_sec = abstime->tv_sec - tv.tv_sec;
+ rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
+ if (rt.tv_nsec < 0)
+ {
+ rt.tv_nsec += 1000000000;
+ --rt.tv_sec;
+ }
+
+ /* Already timed out? */
+ if (rt.tv_sec < 0)
+ return ETIMEDOUT;
+
+ /* Wait until thread terminates. */
+ if (lll_futex_timed_wait (tidp, tid, &rt) == -ETIMEDOUT)
+ return ETIMEDOUT;
+ }
+
+ return 0;
+}
+
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.c b/libc/nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.c
new file mode 100644
index 000000000..3e88ee186
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.c
@@ -0,0 +1,97 @@
+/* Copyright (C) 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2006.
+
+ 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 <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <sys/time.h>
+#include <pthreadP.h>
+
+
+int
+__lll_robust_lock_wait (int *futex)
+{
+ int oldval = *futex;
+ int tid = THREAD_GETMEM (THREAD_SELF, tid);
+
+ do
+ {
+ if (__builtin_expect (oldval & FUTEX_OWNER_DIED, 0))
+ return oldval;
+
+ int newval = oldval | FUTEX_WAITERS;
+ if (oldval != newval
+ && atomic_compare_and_exchange_bool_acq (futex, newval, oldval))
+ continue;
+
+ lll_futex_wait (futex, newval);
+ }
+ while ((oldval = atomic_compare_and_exchange_val_acq (futex,
+ tid | FUTEX_WAITERS,
+ 0)) != 0);
+ return 0;
+}
+
+
+int
+__lll_robust_timedlock_wait (int *futex, const struct timespec *abstime)
+{
+ /* Reject invalid timeouts. */
+ if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)
+ return EINVAL;
+
+ int tid = THREAD_GETMEM (THREAD_SELF, tid);
+
+ do
+ {
+ struct timeval tv;
+ struct timespec rt;
+
+ /* Get the current time. */
+ (void) __gettimeofday (&tv, NULL);
+
+ /* Compute relative timeout. */
+ rt.tv_sec = abstime->tv_sec - tv.tv_sec;
+ rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
+ if (rt.tv_nsec < 0)
+ {
+ rt.tv_nsec += 1000000000;
+ --rt.tv_sec;
+ }
+
+ /* Already timed out? */
+ if (rt.tv_sec < 0)
+ return ETIMEDOUT;
+
+ /* Wait. */
+ int oldval = *futex;
+ if (__builtin_expect (oldval & FUTEX_OWNER_DIED, 0))
+ return oldval;
+
+ int newval = oldval | FUTEX_WAITERS;
+ if (oldval != newval
+ && atomic_compare_and_exchange_bool_acq (futex, newval, oldval))
+ continue;
+
+ lll_futex_timed_wait (futex, newval, &rt);
+ }
+ while (atomic_compare_and_exchange_bool_acq (futex, tid | FUTEX_WAITERS, 0));
+
+ return 0;
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.sym b/libc/nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.sym
new file mode 100644
index 000000000..2f1e9da52
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.sym
@@ -0,0 +1,6 @@
+#include <stddef.h>
+#include <pthreadP.h>
+
+--
+
+TID offsetof (struct pthread, tid)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/lowlevelrwlock.sym b/libc/nptl/sysdeps/unix/sysv/linux/lowlevelrwlock.sym
new file mode 100644
index 000000000..e82c878d3
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/lowlevelrwlock.sym
@@ -0,0 +1,14 @@
+#include <stddef.h>
+#include <stdio.h>
+#include <bits/pthreadtypes.h>
+
+--
+
+MUTEX offsetof (pthread_rwlock_t, __data.__lock)
+NR_READERS offsetof (pthread_rwlock_t, __data.__nr_readers)
+READERS_WAKEUP offsetof (pthread_rwlock_t, __data.__readers_wakeup)
+WRITERS_WAKEUP offsetof (pthread_rwlock_t, __data.__writer_wakeup)
+READERS_QUEUED offsetof (pthread_rwlock_t, __data.__nr_readers_queued)
+WRITERS_QUEUED offsetof (pthread_rwlock_t, __data.__nr_writers_queued)
+FLAGS offsetof (pthread_rwlock_t, __data.__flags)
+WRITER offsetof (pthread_rwlock_t, __data.__writer)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/mq_notify.c b/libc/nptl/sysdeps/unix/sysv/linux/mq_notify.c
new file mode 100644
index 000000000..2ec11bf68
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/mq_notify.c
@@ -0,0 +1,287 @@
+/* Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contribute by Ulrich Drepper <drepper@redhat.com>, 2004.
+
+ 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 <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <mqueue.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sysdep.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <not-cancel.h>
+
+
+#ifdef __NR_mq_notify
+
+/* Defined in the kernel headers: */
+#define NOTIFY_COOKIE_LEN 32 /* Length of the cookie used. */
+#define NOTIFY_WOKENUP 1 /* Code for notifcation. */
+#define NOTIFY_REMOVED 2 /* Code for closed message queue
+ of de-notifcation. */
+
+
+/* Data structure for the queued notification requests. */
+union notify_data
+{
+ struct
+ {
+ void (*fct) (union sigval); /* The function to run. */
+ union sigval param; /* The parameter to pass. */
+ pthread_attr_t *attr; /* Attributes to create the thread with. */
+ /* NB: on 64-bit machines the struct as a size of 24 bytes. Which means
+ byte 31 can still be used for returning the status. */
+ };
+ char raw[NOTIFY_COOKIE_LEN];
+};
+
+
+/* Keep track of the initialization. */
+static pthread_once_t once = PTHREAD_ONCE_INIT;
+
+
+/* The netlink socket. */
+static int netlink_socket = -1;
+
+
+/* Barrier used to make sure data passed to the new thread is not
+ resused by the parent. */
+static pthread_barrier_t notify_barrier;
+
+
+/* Modify the signal mask. We move this into a separate function so
+ that the stack space needed for sigset_t is not deducted from what
+ the thread can use. */
+static int
+__attribute__ ((noinline))
+change_sigmask (int how, sigset_t *oss)
+{
+ sigset_t ss;
+ sigfillset (&ss);
+ return pthread_sigmask (how, &ss, oss);
+}
+
+
+/* The function used for the notification. */
+static void *
+notification_function (void *arg)
+{
+ /* Copy the function and parameter so that the parent thread can go
+ on with its life. */
+ volatile union notify_data *data = (volatile union notify_data *) arg;
+ void (*fct) (union sigval) = data->fct;
+ union sigval param = data->param;
+
+ /* Let the parent go. */
+ (void) pthread_barrier_wait (&notify_barrier);
+
+ /* Make the thread detached. */
+ (void) pthread_detach (pthread_self ());
+
+ /* The parent thread has all signals blocked. This is probably a
+ bit surprising for this thread. So we unblock all of them. */
+ (void) change_sigmask (SIG_UNBLOCK, NULL);
+
+ /* Now run the user code. */
+ fct (param);
+
+ /* And we are done. */
+ return NULL;
+}
+
+
+/* Helper thread. */
+static void *
+helper_thread (void *arg)
+{
+ while (1)
+ {
+ union notify_data data;
+
+ ssize_t n = recv (netlink_socket, &data, sizeof (data),
+ MSG_NOSIGNAL | MSG_WAITALL);
+ if (n < NOTIFY_COOKIE_LEN)
+ continue;
+
+ if (data.raw[NOTIFY_COOKIE_LEN - 1] == NOTIFY_WOKENUP)
+ {
+ /* Just create the thread as instructed. There is no way to
+ report a problem with creating a thread. */
+ pthread_t th;
+ if (__builtin_expect (pthread_create (&th, data.attr,
+ notification_function, &data)
+ == 0, 0))
+ /* Since we passed a pointer to DATA to the new thread we have
+ to wait until it is done with it. */
+ (void) pthread_barrier_wait (&notify_barrier);
+ }
+ else if (data.raw[NOTIFY_COOKIE_LEN - 1] == NOTIFY_REMOVED)
+ /* The only state we keep is the copy of the thread attributes. */
+ free (data.attr);
+ }
+ return NULL;
+}
+
+
+static void
+reset_once (void)
+{
+ once = PTHREAD_ONCE_INIT;
+}
+
+
+static void
+init_mq_netlink (void)
+{
+ /* This code might be called a second time after fork(). The file
+ descriptor is inherited from the parent. */
+ if (netlink_socket == -1)
+ {
+ /* Just a normal netlink socket, not bound. */
+ netlink_socket = socket (AF_NETLINK, SOCK_RAW, 0);
+ /* No need to do more if we have no socket. */
+ if (netlink_socket == -1)
+ return;
+
+ /* Make sure the descriptor is closed on exec. */
+ if (fcntl (netlink_socket, F_SETFD, FD_CLOEXEC) != 0)
+ goto errout;
+ }
+
+ int err = 1;
+
+ /* Initialize the barrier. */
+ if (__builtin_expect (pthread_barrier_init (&notify_barrier, NULL, 2) == 0,
+ 0))
+ {
+ /* Create the helper thread. */
+ pthread_attr_t attr;
+ (void) pthread_attr_init (&attr);
+ (void) pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
+ /* We do not need much stack space, the bare minimum will be enough. */
+ (void) pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
+
+ /* Temporarily block all signals so that the newly created
+ thread inherits the mask. */
+ sigset_t oss;
+ int have_no_oss = change_sigmask (SIG_BLOCK, &oss);
+
+ pthread_t th;
+ err = pthread_create (&th, &attr, helper_thread, NULL);
+
+ /* Reset the signal mask. */
+ if (!have_no_oss)
+ pthread_sigmask (SIG_SETMASK, &oss, NULL);
+
+ (void) pthread_attr_destroy (&attr);
+
+ if (err == 0)
+ {
+ static int added_atfork;
+
+ if (added_atfork == 0
+ && pthread_atfork (NULL, NULL, reset_once) != 0)
+ {
+ /* The child thread will call recv() which is a
+ cancellation point. */
+ (void) pthread_cancel (th);
+ err = 1;
+ }
+ else
+ added_atfork = 1;
+ }
+ }
+
+ if (err != 0)
+ {
+ errout:
+ close_not_cancel_no_status (netlink_socket);
+ netlink_socket = -1;
+ }
+}
+
+
+/* Register notification upon message arrival to an empty message queue
+ MQDES. */
+int
+mq_notify (mqd_t mqdes, const struct sigevent *notification)
+{
+ /* Make sure the type is correctly defined. */
+ assert (sizeof (union notify_data) == NOTIFY_COOKIE_LEN);
+
+ /* Special treatment needed for SIGEV_THREAD. */
+ if (notification == NULL || notification->sigev_notify != SIGEV_THREAD)
+ return INLINE_SYSCALL (mq_notify, 2, mqdes, notification);
+
+ /* The kernel cannot directly start threads. This will have to be
+ done at userlevel. Since we cannot start threads from signal
+ handlers we have to create a dedicated thread which waits for
+ notifications for arriving messages and creates threads in
+ response. */
+
+ /* Initialize only once. */
+ pthread_once (&once, init_mq_netlink);
+
+ /* If we cannot create the netlink socket we cannot provide
+ SIGEV_THREAD support. */
+ if (__builtin_expect (netlink_socket == -1, 0))
+ {
+ __set_errno (ENOSYS);
+ return -1;
+ }
+
+ /* Create the cookie. It will hold almost all the state. */
+ union notify_data data;
+ memset (&data, '\0', sizeof (data));
+ data.fct = notification->sigev_notify_function;
+ data.param = notification->sigev_value;
+
+ if (notification->sigev_notify_attributes != NULL)
+ {
+ /* The thread attribute has to be allocated separately. */
+ data.attr = (pthread_attr_t *) malloc (sizeof (pthread_attr_t));
+ if (data.attr == NULL)
+ return -1;
+
+ memcpy (data.attr, notification->sigev_notify_attributes,
+ sizeof (pthread_attr_t));
+ }
+
+ /* Construct the new request. */
+ struct sigevent se;
+ se.sigev_notify = SIGEV_THREAD;
+ se.sigev_signo = netlink_socket;
+ se.sigev_value.sival_ptr = &data;
+
+ /* Tell the kernel. */
+ int retval = INLINE_SYSCALL (mq_notify, 2, mqdes, &se);
+
+ /* If it failed, free the allocated memory. */
+ if (__builtin_expect (retval != 0, 0))
+ free (data.attr);
+
+ return retval;
+}
+
+#else
+# include <rt/mq_notify.c>
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/Makefile b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/Makefile
new file mode 100644
index 000000000..e98c9bd86
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/Makefile
@@ -0,0 +1,2 @@
+# pull in __syscall_error routine
+libpthread-routines += sysdep
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/Versions b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/Versions
new file mode 100644
index 000000000..997784798
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/Versions
@@ -0,0 +1,5 @@
+libpthread {
+ GLIBC_2.3.4 {
+ longjmp; siglongjmp;
+ }
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h
new file mode 100644
index 000000000..a7150f6ae
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h
@@ -0,0 +1,218 @@
+/* Machine-specific pthread type layouts. PowerPC version.
+ Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus@au.ibm.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. */
+
+#ifndef _BITS_PTHREADTYPES_H
+#define _BITS_PTHREADTYPES_H 1
+
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+# define __SIZEOF_PTHREAD_ATTR_T 56
+# define __SIZEOF_PTHREAD_MUTEX_T 40
+# define __SIZEOF_PTHREAD_MUTEXATTR_T 4
+# define __SIZEOF_PTHREAD_COND_T 48
+# define __SIZEOF_PTHREAD_CONDATTR_T 4
+# define __SIZEOF_PTHREAD_RWLOCK_T 56
+# define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
+# define __SIZEOF_PTHREAD_BARRIER_T 32
+# define __SIZEOF_PTHREAD_BARRIERATTR_T 4
+#else
+# define __SIZEOF_PTHREAD_ATTR_T 36
+# define __SIZEOF_PTHREAD_MUTEX_T 24
+# define __SIZEOF_PTHREAD_MUTEXATTR_T 4
+# define __SIZEOF_PTHREAD_COND_T 48
+# define __SIZEOF_PTHREAD_CONDATTR_T 4
+# define __SIZEOF_PTHREAD_RWLOCK_T 32
+# define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
+# define __SIZEOF_PTHREAD_BARRIER_T 20
+# define __SIZEOF_PTHREAD_BARRIERATTR_T 4
+#endif
+
+
+/* Thread identifiers. The structure of the attribute type is
+ deliberately not exposed. */
+typedef unsigned long int pthread_t;
+
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_ATTR_T];
+ long int __align;
+} pthread_attr_t;
+
+
+#if __WORDSIZE == 64
+typedef struct __pthread_internal_list
+{
+ struct __pthread_internal_list *__prev;
+ struct __pthread_internal_list *__next;
+} __pthread_list_t;
+#else
+typedef struct __pthread_internal_slist
+{
+ struct __pthread_internal_slist *__next;
+} __pthread_slist_t;
+#endif
+
+
+/* Data structures for mutex handling. The structure of the attribute
+ type is deliberately not exposed. */
+typedef union
+{
+ struct __pthread_mutex_s
+ {
+ int __lock;
+ unsigned int __count;
+ int __owner;
+#if __WORDSIZE == 64
+ unsigned int __nusers;
+#endif
+ /* KIND must stay at this position in the structure to maintain
+ binary compatibility. */
+ int __kind;
+#if __WORDSIZE == 64
+ int __spins;
+ __pthread_list_t __list;
+# define __PTHREAD_MUTEX_HAVE_PREV 1
+#else
+ unsigned int __nusers;
+ __extension__ union
+ {
+ int __spins;
+ __pthread_slist_t __list;
+ };
+#endif
+ } __data;
+ char __size[__SIZEOF_PTHREAD_MUTEX_T];
+ long int __align;
+} pthread_mutex_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_MUTEXATTR_T];
+ int __align;
+} pthread_mutexattr_t;
+
+
+/* Data structure for conditional variable handling. The structure of
+ the attribute type is deliberately not exposed. */
+typedef union
+{
+ struct
+ {
+ int __lock;
+ unsigned int __futex;
+ __extension__ unsigned long long int __total_seq;
+ __extension__ unsigned long long int __wakeup_seq;
+ __extension__ unsigned long long int __woken_seq;
+ void *__mutex;
+ unsigned int __nwaiters;
+ unsigned int __broadcast_seq;
+ } __data;
+ char __size[__SIZEOF_PTHREAD_COND_T];
+ __extension__ long long int __align;
+} pthread_cond_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_CONDATTR_T];
+ int __align;
+} pthread_condattr_t;
+
+
+/* Keys for thread-specific data */
+typedef unsigned int pthread_key_t;
+
+
+/* Once-only execution */
+typedef int pthread_once_t;
+
+
+#if defined __USE_UNIX98 || defined __USE_XOPEN2K
+/* Data structure for read-write lock variable handling. The
+ structure of the attribute type is deliberately not exposed. */
+typedef union
+{
+# if __WORDSIZE == 64
+ struct
+ {
+ int __lock;
+ unsigned int __nr_readers;
+ unsigned int __readers_wakeup;
+ unsigned int __writer_wakeup;
+ unsigned int __nr_readers_queued;
+ unsigned int __nr_writers_queued;
+ int __writer;
+ int __pad1;
+ unsigned long int __pad2;
+ unsigned long int __pad3;
+ /* FLAGS must stay at this position in the structure to maintain
+ binary compatibility. */
+ unsigned int __flags;
+ } __data;
+# else
+ struct
+ {
+ int __lock;
+ unsigned int __nr_readers;
+ unsigned int __readers_wakeup;
+ unsigned int __writer_wakeup;
+ unsigned int __nr_readers_queued;
+ unsigned int __nr_writers_queued;
+ /* FLAGS must stay at this position in the structure to maintain
+ binary compatibility. */
+ unsigned int __flags;
+ int __writer;
+ } __data;
+# endif
+ char __size[__SIZEOF_PTHREAD_RWLOCK_T];
+ long int __align;
+} pthread_rwlock_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_RWLOCKATTR_T];
+ long int __align;
+} pthread_rwlockattr_t;
+#endif
+
+
+#ifdef __USE_XOPEN2K
+/* POSIX spinlock data type. */
+typedef volatile int pthread_spinlock_t;
+
+
+/* POSIX barriers data type. The structure of the type is
+ deliberately not exposed. */
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_BARRIER_T];
+ long int __align;
+} pthread_barrier_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_BARRIERATTR_T];
+ int __align;
+} pthread_barrierattr_t;
+#endif
+
+
+#endif /* bits/pthreadtypes.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/bits/semaphore.h b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/bits/semaphore.h
new file mode 100644
index 000000000..8123b418b
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/bits/semaphore.h
@@ -0,0 +1,44 @@
+/* Machine-specific POSIX semaphore type layouts. PowerPC version.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus@au.ibm.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. */
+
+#ifndef _SEMAPHORE_H
+# error "Never use <bits/semaphore.h> directly; include <semaphore.h> instead."
+#endif
+
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+# define __SIZEOF_SEM_T 32
+#else
+# define __SIZEOF_SEM_T 16
+#endif
+
+/* Value returned if `sem_open' failed. */
+#define SEM_FAILED ((sem_t *) 0)
+
+/* Maximum value the semaphore can have. */
+#define SEM_VALUE_MAX (2147483647)
+
+
+typedef union
+{
+ char __size[__SIZEOF_SEM_T];
+ long int __align;
+} sem_t;
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/createthread.c b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/createthread.c
new file mode 100644
index 000000000..e811ad74e
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/createthread.c
@@ -0,0 +1,25 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus@au.ibm.com>.
+
+ 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. */
+
+/* Value passed to 'clone' for initialization of the thread register. */
+#define TLS_VALUE ((void *) (pd) \
+ + TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE)
+
+/* Get the real implementation. */
+#include <nptl/sysdeps/pthread/createthread.c>
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/fork.c b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/fork.c
new file mode 100644
index 000000000..06b7e1c69
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/fork.c
@@ -0,0 +1 @@
+#include "../i386/fork.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h
new file mode 100644
index 000000000..0136b9759
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h
@@ -0,0 +1,321 @@
+/* Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus@au.ibm.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. */
+
+#ifndef _LOWLEVELLOCK_H
+#define _LOWLEVELLOCK_H 1
+
+#include <time.h>
+#include <sys/param.h>
+#include <bits/pthreadtypes.h>
+#include <atomic.h>
+
+
+#ifndef __NR_futex
+# define __NR_futex 221
+#endif
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+#define FUTEX_REQUEUE 3
+#define FUTEX_CMP_REQUEUE 4
+#define FUTEX_WAKE_OP 5
+#define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE ((4 << 24) | 1)
+#define FUTEX_LOCK_PI 6
+#define FUTEX_UNLOCK_PI 7
+#define FUTEX_TRYLOCK_PI 8
+
+/* Initializer for compatibility lock. */
+#define LLL_MUTEX_LOCK_INITIALIZER (0)
+
+#define lll_futex_wait(futexp, val) \
+ ({ \
+ INTERNAL_SYSCALL_DECL (__err); \
+ long int __ret; \
+ \
+ __ret = INTERNAL_SYSCALL (futex, __err, 4, \
+ (futexp), FUTEX_WAIT, (val), 0); \
+ INTERNAL_SYSCALL_ERROR_P (__ret, __err) ? -__ret : __ret; \
+ })
+
+#define lll_futex_timed_wait(futexp, val, timespec) \
+ ({ \
+ INTERNAL_SYSCALL_DECL (__err); \
+ long int __ret; \
+ \
+ __ret = INTERNAL_SYSCALL (futex, __err, 4, \
+ (futexp), FUTEX_WAIT, (val), (timespec)); \
+ INTERNAL_SYSCALL_ERROR_P (__ret, __err) ? -__ret : __ret; \
+ })
+
+#define lll_futex_wake(futexp, nr) \
+ ({ \
+ INTERNAL_SYSCALL_DECL (__err); \
+ long int __ret; \
+ \
+ __ret = INTERNAL_SYSCALL (futex, __err, 4, \
+ (futexp), FUTEX_WAKE, (nr), 0); \
+ INTERNAL_SYSCALL_ERROR_P (__ret, __err) ? -__ret : __ret; \
+ })
+
+#define lll_robust_mutex_dead(futexv) \
+ do \
+ { \
+ INTERNAL_SYSCALL_DECL (__err); \
+ int *__futexp = &(futexv); \
+ \
+ atomic_or (__futexp, FUTEX_OWNER_DIED); \
+ INTERNAL_SYSCALL (futex, __err, 4, __futexp, FUTEX_WAKE, 1, 0); \
+ } \
+ while (0)
+
+/* Returns non-zero if error happened, zero if success. */
+#define lll_futex_requeue(futexp, nr_wake, nr_move, mutex, val) \
+ ({ \
+ INTERNAL_SYSCALL_DECL (__err); \
+ long int __ret; \
+ \
+ __ret = INTERNAL_SYSCALL (futex, __err, 6, \
+ (futexp), FUTEX_CMP_REQUEUE, (nr_wake), \
+ (nr_move), (mutex), (val)); \
+ INTERNAL_SYSCALL_ERROR_P (__ret, __err); \
+ })
+
+/* Returns non-zero if error happened, zero if success. */
+#define lll_futex_wake_unlock(futexp, nr_wake, nr_wake2, futexp2) \
+ ({ \
+ INTERNAL_SYSCALL_DECL (__err); \
+ long int __ret; \
+ \
+ __ret = INTERNAL_SYSCALL (futex, __err, 6, \
+ (futexp), FUTEX_WAKE_OP, (nr_wake), \
+ (nr_wake2), (futexp2), \
+ FUTEX_OP_CLEAR_WAKE_IF_GT_ONE); \
+ INTERNAL_SYSCALL_ERROR_P (__ret, __err); \
+ })
+
+#ifdef UP
+# define __lll_acq_instr ""
+# define __lll_rel_instr ""
+#else
+# define __lll_acq_instr "isync"
+# ifdef _ARCH_PWR4
+/*
+ * Newer powerpc64 processors support the new "light weight" sync (lwsync)
+ * So if the build is using -mcpu=[power4,power5,power5+,970] we can
+ * safely use lwsync.
+ */
+# define __lll_rel_instr "lwsync"
+# else
+/*
+ * Older powerpc32 processors don't support the new "light weight"
+ * sync (lwsync). So the only safe option is to use normal sync
+ * for all powerpc32 applications.
+ */
+# define __lll_rel_instr "sync"
+# endif
+#endif
+
+/* Set *futex to ID if it is 0, atomically. Returns the old value */
+#define __lll_robust_trylock(futex, id) \
+ ({ int __val; \
+ __asm __volatile ("1: lwarx %0,0,%2\n" \
+ " cmpwi 0,%0,0\n" \
+ " bne 2f\n" \
+ " stwcx. %3,0,%2\n" \
+ " bne- 1b\n" \
+ "2: " __lll_acq_instr \
+ : "=&r" (__val), "=m" (*futex) \
+ : "r" (futex), "r" (id), "m" (*futex) \
+ : "cr0", "memory"); \
+ __val; \
+ })
+
+#define lll_robust_mutex_trylock(lock, id) __lll_robust_trylock (&(lock), id)
+
+/* Set *futex to 1 if it is 0, atomically. Returns the old value */
+#define __lll_trylock(futex) __lll_robust_trylock (futex, 1)
+
+#define lll_mutex_trylock(lock) __lll_trylock (&(lock))
+
+/* Set *futex to 2 if it is 0, atomically. Returns the old value */
+#define __lll_cond_trylock(futex) __lll_robust_trylock (futex, 2)
+
+#define lll_mutex_cond_trylock(lock) __lll_cond_trylock (&(lock))
+
+
+extern void __lll_lock_wait (int *futex) attribute_hidden;
+extern int __lll_robust_lock_wait (int *futex) attribute_hidden;
+
+#define lll_mutex_lock(lock) \
+ (void) ({ \
+ int *__futex = &(lock); \
+ if (__builtin_expect (atomic_compare_and_exchange_val_acq (__futex, 1, 0),\
+ 0) != 0) \
+ __lll_lock_wait (__futex); \
+ })
+
+#define lll_robust_mutex_lock(lock, id) \
+ ({ \
+ int *__futex = &(lock); \
+ int __val = 0; \
+ if (__builtin_expect (atomic_compare_and_exchange_bool_acq (__futex, id, \
+ 0), 0)) \
+ __val = __lll_robust_lock_wait (__futex); \
+ __val; \
+ })
+
+#define lll_mutex_cond_lock(lock) \
+ (void) ({ \
+ int *__futex = &(lock); \
+ if (__builtin_expect (atomic_compare_and_exchange_val_acq (__futex, 2, 0),\
+ 0) != 0) \
+ __lll_lock_wait (__futex); \
+ })
+
+#define lll_robust_mutex_cond_lock(lock, id) \
+ ({ \
+ int *__futex = &(lock); \
+ int __val = 0; \
+ int __id = id | FUTEX_WAITERS; \
+ if (__builtin_expect (atomic_compare_and_exchange_bool_acq (__futex, __id,\
+ 0), 0)) \
+ __val = __lll_robust_lock_wait (__futex); \
+ __val; \
+ })
+
+
+extern int __lll_timedlock_wait
+ (int *futex, const struct timespec *) attribute_hidden;
+extern int __lll_robust_timedlock_wait
+ (int *futex, const struct timespec *) attribute_hidden;
+
+#define lll_mutex_timedlock(lock, abstime) \
+ ({ \
+ int *__futex = &(lock); \
+ int __val = 0; \
+ if (__builtin_expect (atomic_compare_and_exchange_val_acq (__futex, 1, 0),\
+ 0) != 0) \
+ __val = __lll_timedlock_wait (__futex, abstime); \
+ __val; \
+ })
+
+#define lll_robust_mutex_timedlock(lock, abstime, id) \
+ ({ \
+ int *__futex = &(lock); \
+ int __val = 0; \
+ if (__builtin_expect (atomic_compare_and_exchange_bool_acq (__futex, id, \
+ 0), 0)) \
+ __val = __lll_robust_timedlock_wait (__futex, abstime); \
+ __val; \
+ })
+
+#define lll_mutex_unlock(lock) \
+ ((void) ({ \
+ int *__futex = &(lock); \
+ int __val = atomic_exchange_rel (__futex, 0); \
+ if (__builtin_expect (__val > 1, 0)) \
+ lll_futex_wake (__futex, 1); \
+ }))
+
+#define lll_robust_mutex_unlock(lock) \
+ ((void) ({ \
+ int *__futex = &(lock); \
+ int __val = atomic_exchange_rel (__futex, 0); \
+ if (__builtin_expect (__val & FUTEX_WAITERS, 0)) \
+ lll_futex_wake (__futex, 1); \
+ }))
+
+#define lll_mutex_unlock_force(lock) \
+ ((void) ({ \
+ int *__futex = &(lock); \
+ *__futex = 0; \
+ __asm __volatile (__lll_rel_instr ::: "memory"); \
+ lll_futex_wake (__futex, 1); \
+ }))
+
+#define lll_mutex_islocked(futex) \
+ (futex != 0)
+
+
+/* Our internal lock implementation is identical to the binary-compatible
+ mutex implementation. */
+
+/* Type for lock object. */
+typedef int lll_lock_t;
+
+/* Initializers for lock. */
+#define LLL_LOCK_INITIALIZER (0)
+#define LLL_LOCK_INITIALIZER_LOCKED (1)
+
+extern int lll_unlock_wake_cb (int *__futex) attribute_hidden;
+
+/* The states of a lock are:
+ 0 - untaken
+ 1 - taken by one user
+ >1 - taken by more users */
+
+#define lll_trylock(lock) lll_mutex_trylock (lock)
+#define lll_lock(lock) lll_mutex_lock (lock)
+#define lll_unlock(lock) lll_mutex_unlock (lock)
+#define lll_islocked(lock) lll_mutex_islocked (lock)
+
+/* The kernel notifies a process which uses CLONE_CLEARTID via futex
+ wakeup when the clone terminates. The memory location contains the
+ thread ID while the clone is running and is reset to zero
+ afterwards. */
+#define lll_wait_tid(tid) \
+ do { \
+ __typeof (tid) __tid; \
+ while ((__tid = (tid)) != 0) \
+ lll_futex_wait (&(tid), __tid); \
+ } while (0)
+
+extern int __lll_timedwait_tid (int *, const struct timespec *)
+ attribute_hidden;
+
+#define lll_timedwait_tid(tid, abstime) \
+ ({ \
+ int __res = 0; \
+ if ((tid) != 0) \
+ __res = __lll_timedwait_tid (&(tid), (abstime)); \
+ __res; \
+ })
+
+
+/* Conditional variable handling. */
+
+extern void __lll_cond_wait (pthread_cond_t *cond)
+ attribute_hidden;
+extern int __lll_cond_timedwait (pthread_cond_t *cond,
+ const struct timespec *abstime)
+ attribute_hidden;
+extern void __lll_cond_wake (pthread_cond_t *cond)
+ attribute_hidden;
+extern void __lll_cond_broadcast (pthread_cond_t *cond)
+ attribute_hidden;
+
+#define lll_cond_wait(cond) \
+ __lll_cond_wait (cond)
+#define lll_cond_timedwait(cond, abstime) \
+ __lll_cond_timedwait (cond, abstime)
+#define lll_cond_wake(cond) \
+ __lll_cond_wake (cond)
+#define lll_cond_broadcast(cond) \
+ __lll_cond_broadcast (cond)
+
+#endif /* lowlevellock.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/not-cancel.h b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/not-cancel.h
new file mode 100644
index 000000000..acf1a617e
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/not-cancel.h
@@ -0,0 +1 @@
+#include "../i386/not-cancel.h"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S
new file mode 100644
index 000000000..675a997e9
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S
@@ -0,0 +1,9 @@
+/* We want an #include_next, but we are the main source file.
+ So, #include ourselves and in that incarnation we can use #include_next. */
+#ifndef INCLUDED_SELF
+# define INCLUDED_SELF
+# include <clone.S>
+#else
+# define RESET_PID
+# include_next <clone.S>
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/pt-vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/pt-vfork.S
new file mode 100644
index 000000000..002af8590
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/pt-vfork.S
@@ -0,0 +1,49 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
+
+ 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 <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <kernel-features.h>
+#include <tcb-offsets.h>
+
+/* Clone the calling process, but without copying the whole address space.
+ The calling process is suspended until the new process exits or is
+ replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
+ and the process ID of the new process to the old process. */
+
+ENTRY (__vfork)
+ lwz 0,PID(2)
+ neg 0,0
+ stw 0,PID(2)
+
+ DO_CALL (SYS_ify (vfork))
+
+ cmpwi 1,3,0
+ beqlr- 1
+
+ lwz 0,PID(2)
+ neg 0,0
+ stw 0,PID(2)
+
+ PSEUDO_RET
+
+PSEUDO_END (__vfork)
+
+weak_alias (__vfork, vfork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h
new file mode 100644
index 000000000..dcbc0d652
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h
@@ -0,0 +1,130 @@
+/* Cancellable system call stubs. Linux/PowerPC version.
+ Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Franz Sirl <Franz.Sirl-kernel@lauterbach.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., 51 Franklin Street, Fifth Floor, Boston MA
+ 02110-1301 USA. */
+
+#include <sysdep.h>
+#include <tls.h>
+#ifndef __ASSEMBLER__
+# include <nptl/pthreadP.h>
+#endif
+
+#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
+
+# undef PSEUDO
+# define PSEUDO(name, syscall_name, args) \
+ .section ".text"; \
+ ENTRY (name) \
+ SINGLE_THREAD_P; \
+ bne- .Lpseudo_cancel; \
+ .type __##syscall_name##_nocancel,@function; \
+ .globl __##syscall_name##_nocancel; \
+ __##syscall_name##_nocancel: \
+ DO_CALL (SYS_ify (syscall_name)); \
+ PSEUDO_RET; \
+ .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
+ .Lpseudo_cancel: \
+ stwu 1,-48(1); \
+ cfi_adjust_cfa_offset (48); \
+ mflr 9; \
+ stw 9,52(1); \
+ cfi_offset (lr, 4); \
+ CGOTSETUP; \
+ DOCARGS_##args; /* save syscall args around CENABLE. */ \
+ CENABLE; \
+ stw 3,16(1); /* store CENABLE return value (MASK). */ \
+ UNDOCARGS_##args; /* restore syscall args. */ \
+ DO_CALL (SYS_ify (syscall_name)); \
+ mfcr 0; /* save CR/R3 around CDISABLE. */ \
+ stw 3,8(1); \
+ stw 0,12(1); \
+ lwz 3,16(1); /* pass MASK to CDISABLE. */ \
+ CDISABLE; \
+ lwz 4,52(1); \
+ lwz 0,12(1); /* restore CR/R3. */ \
+ lwz 3,8(1); \
+ CGOTRESTORE; \
+ mtlr 4; \
+ mtcr 0; \
+ addi 1,1,48;
+
+# define DOCARGS_0
+# define UNDOCARGS_0
+
+# define DOCARGS_1 stw 3,20(1); DOCARGS_0
+# define UNDOCARGS_1 lwz 3,20(1); UNDOCARGS_0
+
+# define DOCARGS_2 stw 4,24(1); DOCARGS_1
+# define UNDOCARGS_2 lwz 4,24(1); UNDOCARGS_1
+
+# define DOCARGS_3 stw 5,28(1); DOCARGS_2
+# define UNDOCARGS_3 lwz 5,28(1); UNDOCARGS_2
+
+# define DOCARGS_4 stw 6,32(1); DOCARGS_3
+# define UNDOCARGS_4 lwz 6,32(1); UNDOCARGS_3
+
+# define DOCARGS_5 stw 7,36(1); DOCARGS_4
+# define UNDOCARGS_5 lwz 7,36(1); UNDOCARGS_4
+
+# define DOCARGS_6 stw 8,40(1); DOCARGS_5
+# define UNDOCARGS_6 lwz 8,40(1); UNDOCARGS_5
+
+# define CGOTSETUP
+# define CGOTRESTORE
+
+# ifdef IS_IN_libpthread
+# define CENABLE bl __pthread_enable_asynccancel@local
+# define CDISABLE bl __pthread_disable_asynccancel@local
+# elif !defined NOT_IN_libc
+# define CENABLE bl __libc_enable_asynccancel@local
+# define CDISABLE bl __libc_disable_asynccancel@local
+# elif defined IS_IN_librt
+# define CENABLE bl JUMPTARGET(__librt_enable_asynccancel)
+# define CDISABLE bl JUMPTARGET(__librt_disable_asynccancel)
+# if defined HAVE_AS_REL16 && defined PIC
+# undef CGOTSETUP
+# define CGOTSETUP \
+ bcl 20,31,1f; \
+ 1: stw 30,44(1); \
+ mflr 30; \
+ addis 30,30,_GLOBAL_OFFSET_TABLE-1b@ha; \
+ addi 30,30,_GLOBAL_OFFSET_TABLE-1b@l
+# undef CGOTRESTORE
+# define CGOTRESTORE \
+ lwz 30,44(1)
+# endif
+# else
+# error Unsupported library
+# endif
+
+# ifndef __ASSEMBLER__
+# define SINGLE_THREAD_P \
+ __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+ header.multiple_threads) == 0, 1)
+# else
+# define SINGLE_THREAD_P \
+ lwz 10,MULTIPLE_THREADS_OFFSET(2); \
+ cmpwi 10,0
+# endif
+
+#elif !defined __ASSEMBLER__
+
+# define SINGLE_THREAD_P (1)
+# define NO_CANCELLATION 1
+
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S
new file mode 100644
index 000000000..4b035a61f
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S
@@ -0,0 +1,57 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
+
+ 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 <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <kernel-features.h>
+#include <tcb-offsets.h>
+
+/* Clone the calling process, but without copying the whole address space.
+ The calling process is suspended until the new process exits or is
+ replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
+ and the process ID of the new process to the old process. */
+
+ENTRY (__vfork)
+ lwz 0,PID(2)
+ cmpwi 0,0,0
+ neg 0,0
+ bne- 0,1f
+ lis 0,0x8000
+1: stw 0,PID(2)
+
+ DO_CALL (SYS_ify (vfork))
+
+ cmpwi 1,3,0
+ beqlr- 1
+
+ lwz 0,PID(2)
+ /* Cannot use clrlwi. here, because cr0 needs to be preserved
+ until PSEUDO_RET. */
+ clrlwi 4,0,1
+ cmpwi 1,4,0
+ beq- 1,1f
+ neg 4,0
+1: stw 4,PID(2)
+
+ PSEUDO_RET
+
+PSEUDO_END (__vfork)
+libc_hidden_def (__vfork)
+weak_alias (__vfork, vfork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/Versions b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/Versions
new file mode 100644
index 000000000..3b111ddb5
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/Versions
@@ -0,0 +1,7 @@
+librt {
+ GLIBC_2.3.3 {
+ # Changed timer_t.
+ timer_create; timer_delete; timer_getoverrun; timer_gettime;
+ timer_settime;
+ }
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S
new file mode 100644
index 000000000..675a997e9
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S
@@ -0,0 +1,9 @@
+/* We want an #include_next, but we are the main source file.
+ So, #include ourselves and in that incarnation we can use #include_next. */
+#ifndef INCLUDED_SELF
+# define INCLUDED_SELF
+# include <clone.S>
+#else
+# define RESET_PID
+# include_next <clone.S>
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/pt-vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/pt-vfork.S
new file mode 100644
index 000000000..82864c91f
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/pt-vfork.S
@@ -0,0 +1,49 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
+
+ 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 <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <kernel-features.h>
+#include <tcb-offsets.h>
+
+/* Clone the calling process, but without copying the whole address space.
+ The calling process is suspended until the new process exits or is
+ replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
+ and the process ID of the new process to the old process. */
+
+ENTRY (__vfork)
+ lwz 0,PID(13)
+ neg 0,0
+ stw 0,PID(13)
+
+ DO_CALL (SYS_ify (vfork))
+
+ cmpwi 1,3,0
+ beqlr- 1
+
+ lwz 0,PID(13)
+ neg 0,0
+ stw 0,PID(13)
+
+ PSEUDO_RET
+
+PSEUDO_END (__vfork)
+
+weak_alias (__vfork, vfork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h
new file mode 100644
index 000000000..83eb444ec
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h
@@ -0,0 +1,119 @@
+/* Cancellable system call stubs. Linux/PowerPC64 version.
+ Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Franz Sirl <Franz.Sirl-kernel@lauterbach.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., 51 Franklin Street, Fifth Floor, Boston MA
+ 02110-1301 USA. */
+
+#include <sysdep.h>
+#include <tls.h>
+#ifndef __ASSEMBLER__
+# include <nptl/pthreadP.h>
+#endif
+
+#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
+
+# ifdef HAVE_ASM_GLOBAL_DOT_NAME
+# define DASHDASHPFX(str) .__##str
+# else
+# define DASHDASHPFX(str) __##str
+# endif
+
+# undef PSEUDO
+# define PSEUDO(name, syscall_name, args) \
+ .section ".text"; \
+ ENTRY (name) \
+ SINGLE_THREAD_P; \
+ bne- .Lpseudo_cancel; \
+ .type DASHDASHPFX(syscall_name##_nocancel),@function; \
+ .globl DASHDASHPFX(syscall_name##_nocancel); \
+ DASHDASHPFX(syscall_name##_nocancel): \
+ DO_CALL (SYS_ify (syscall_name)); \
+ PSEUDO_RET; \
+ .size DASHDASHPFX(syscall_name##_nocancel),.-DASHDASHPFX(syscall_name##_nocancel); \
+ .Lpseudo_cancel: \
+ stdu 1,-128(1); \
+ cfi_adjust_cfa_offset (128); \
+ mflr 9; \
+ std 9,128+16(1); \
+ cfi_offset (lr, 16); \
+ DOCARGS_##args; /* save syscall args around CENABLE. */ \
+ CENABLE; \
+ std 3,72(1); /* store CENABLE return value (MASK). */ \
+ UNDOCARGS_##args; /* restore syscall args. */ \
+ DO_CALL (SYS_ify (syscall_name)); \
+ mfcr 0; /* save CR/R3 around CDISABLE. */ \
+ std 3,64(1); \
+ std 0,8(1); \
+ ld 3,72(1); /* pass MASK to CDISABLE. */ \
+ CDISABLE; \
+ ld 9,128+16(1); \
+ ld 0,8(1); /* restore CR/R3. */ \
+ ld 3,64(1); \
+ mtlr 9; \
+ mtcr 0; \
+ addi 1,1,128;
+
+# define DOCARGS_0
+# define UNDOCARGS_0
+
+# define DOCARGS_1 std 3,80(1); DOCARGS_0
+# define UNDOCARGS_1 ld 3,80(1); UNDOCARGS_0
+
+# define DOCARGS_2 std 4,88(1); DOCARGS_1
+# define UNDOCARGS_2 ld 4,88(1); UNDOCARGS_1
+
+# define DOCARGS_3 std 5,96(1); DOCARGS_2
+# define UNDOCARGS_3 ld 5,96(1); UNDOCARGS_2
+
+# define DOCARGS_4 std 6,104(1); DOCARGS_3
+# define UNDOCARGS_4 ld 6,104(1); UNDOCARGS_3
+
+# define DOCARGS_5 std 7,112(1); DOCARGS_4
+# define UNDOCARGS_5 ld 7,112(1); UNDOCARGS_4
+
+# define DOCARGS_6 std 8,120(1); DOCARGS_5
+# define UNDOCARGS_6 ld 8,120(1); UNDOCARGS_5
+
+# ifdef IS_IN_libpthread
+# define CENABLE bl JUMPTARGET(__pthread_enable_asynccancel)
+# define CDISABLE bl JUMPTARGET(__pthread_disable_asynccancel)
+# elif !defined NOT_IN_libc
+# define CENABLE bl JUMPTARGET(__libc_enable_asynccancel)
+# define CDISABLE bl JUMPTARGET(__libc_disable_asynccancel)
+# elif defined IS_IN_librt
+# define CENABLE bl JUMPTARGET(__librt_enable_asynccancel)
+# define CDISABLE bl JUMPTARGET(__librt_disable_asynccancel)
+# else
+# error Unsupported library
+# endif
+
+# ifndef __ASSEMBLER__
+# define SINGLE_THREAD_P \
+ __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+ header.multiple_threads) == 0, 1)
+# else
+# define SINGLE_THREAD_P \
+ lwz 10,MULTIPLE_THREADS_OFFSET(13); \
+ cmpwi 10,0
+# endif
+
+#elif !defined __ASSEMBLER__
+
+# define SINGLE_THREAD_P (1)
+# define NO_CANCELLATION 1
+
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_create.c b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_create.c
new file mode 100644
index 000000000..172223af3
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_create.c
@@ -0,0 +1 @@
+#include "../x86_64/timer_create.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_delete.c b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_delete.c
new file mode 100644
index 000000000..537516e0a
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_delete.c
@@ -0,0 +1 @@
+#include "../x86_64/timer_delete.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_getoverr.c b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_getoverr.c
new file mode 100644
index 000000000..3f21a73c9
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_getoverr.c
@@ -0,0 +1 @@
+#include "../x86_64/timer_getoverr.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_gettime.c b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_gettime.c
new file mode 100644
index 000000000..a50143adc
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_gettime.c
@@ -0,0 +1 @@
+#include "../x86_64/timer_gettime.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_settime.c b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_settime.c
new file mode 100644
index 000000000..37baeffac
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_settime.c
@@ -0,0 +1 @@
+#include "../x86_64/timer_settime.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S
new file mode 100644
index 000000000..793762270
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S
@@ -0,0 +1,55 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
+
+ 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 <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <kernel-features.h>
+#include <tcb-offsets.h>
+
+/* Clone the calling process, but without copying the whole address space.
+ The calling process is suspended until the new process exits or is
+ replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
+ and the process ID of the new process to the old process. */
+
+ENTRY (__vfork)
+ lwz 0,PID(13)
+ cmpwi 0,0,0
+ neg 0,0
+ bne- 0,1f
+ lis 0,0x8000
+1: stw 0,PID(13)
+
+ DO_CALL (SYS_ify (vfork))
+
+ cmpwi 1,3,0
+ beqlr- 1
+
+ lwz 0,PID(13)
+ clrlwi 4,0,1
+ cmpwi 1,4,0
+ beq- 1,1f
+ neg 4,0
+1: stw 4,PID(13)
+
+ PSEUDO_RET
+
+PSEUDO_END (__vfork)
+libc_hidden_def (__vfork)
+weak_alias (__vfork, vfork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/pt-longjmp.c b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/pt-longjmp.c
new file mode 100644
index 000000000..3c795e37e
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/pt-longjmp.c
@@ -0,0 +1,68 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <setjmp.h>
+#include <stdlib.h>
+#include <bits/wordsize.h>
+#include "pthreadP.h"
+#include <shlib-compat.h>
+#if defined SHARED && SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_3_4)
+
+/* These functions are not declared anywhere since they shouldn't be
+ used at another place but here. */
+extern void __novmx__libc_siglongjmp (sigjmp_buf env, int val)
+ __attribute__ ((noreturn));
+extern void __novmx__libc_longjmp (sigjmp_buf env, int val)
+ __attribute__ ((noreturn));
+
+
+void __novmx_siglongjmp (sigjmp_buf env, int val)
+{
+ __novmx__libc_siglongjmp (env, val);
+}
+
+void __novmx_longjmp (jmp_buf env, int val)
+{
+ __novmx__libc_longjmp (env, val);
+}
+
+# if __WORDSIZE == 64
+symbol_version (__novmx_longjmp,longjmp,GLIBC_2.3);
+symbol_version (__novmx_siglongjmp,siglongjmp,GLIBC_2.3);
+# else
+symbol_version (__novmx_longjmp,longjmp,GLIBC_2.0);
+symbol_version (__novmx_siglongjmp,siglongjmp,GLIBC_2.0);
+# endif
+#endif /* defined SHARED && SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3_4)) */
+
+void
+__vmx_longjmp (jmp_buf env, int val)
+{
+ __libc_longjmp (env, val);
+}
+
+void
+__vmx_siglongjmp (jmp_buf env, int val)
+{
+ __libc_siglongjmp (env, val);
+}
+
+versioned_symbol (libc, __vmx_longjmp, longjmp, GLIBC_2_3_4);
+versioned_symbol (libc, __vmx_siglongjmp, siglongjmp, GLIBC_2_3_4);
+
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/pthread_once.c b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/pthread_once.c
new file mode 100644
index 000000000..e1afff8a3
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/pthread_once.c
@@ -0,0 +1,100 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus@au.ibm.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 "pthreadP.h"
+#include <lowlevellock.h>
+
+
+unsigned long int __fork_generation attribute_hidden;
+
+
+static void
+clear_once_control (void *arg)
+{
+ pthread_once_t *once_control = (pthread_once_t *) arg;
+
+ *once_control = 0;
+ lll_futex_wake (once_control, INT_MAX);
+}
+
+
+int
+__pthread_once (pthread_once_t *once_control, void (*init_routine) (void))
+{
+ for (;;)
+ {
+ int oldval;
+ int newval;
+ int tmp;
+
+ /* Pseudo code:
+ newval = __fork_generation | 1;
+ oldval = *once_control;
+ if ((oldval & 2) == 0)
+ *once_control = newval;
+ Do this atomically.
+ */
+ newval = __fork_generation | 1;
+ __asm __volatile ("1: lwarx %0,0,%3\n"
+ " andi. %1,%0,2\n"
+ " bne 2f\n"
+ " stwcx. %4,0,%3\n"
+ " bne 1b\n"
+ "2: isync"
+ : "=&r" (oldval), "=&r" (tmp), "=m" (*once_control)
+ : "r" (once_control), "r" (newval), "m" (*once_control)
+ : "cr0");
+
+ /* Check if the initializer has already been done. */
+ if ((oldval & 2) != 0)
+ return 0;
+
+ /* Check if another thread already runs the initializer. */
+ if ((oldval & 1) == 0)
+ break;
+
+ /* Check whether the initializer execution was interrupted by a fork. */
+ if (oldval != newval)
+ break;
+
+ /* Same generation, some other thread was faster. Wait. */
+ lll_futex_wait (once_control, oldval);
+ }
+
+
+ /* This thread is the first here. Do the initialization.
+ Register a cleanup handler so that in case the thread gets
+ interrupted the initialization can be restarted. */
+ pthread_cleanup_push (clear_once_control, once_control);
+
+ init_routine ();
+
+ pthread_cleanup_pop (0);
+
+
+ /* Add one to *once_control to take the bottom 2 bits from 01 to 10. */
+ atomic_increment (once_control);
+
+ /* Wake up all other threads. */
+ lll_futex_wake (once_control, INT_MAX);
+
+ return 0;
+}
+weak_alias (__pthread_once, pthread_once)
+strong_alias (__pthread_once, __pthread_once_internal)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/powerpc/sem_post.c b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/sem_post.c
new file mode 100644
index 000000000..91b995518
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/powerpc/sem_post.c
@@ -0,0 +1,48 @@
+/* sem_post -- post to a POSIX semaphore. Powerpc version.
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus@au.ibm.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 <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <internaltypes.h>
+#include <semaphore.h>
+
+#include <shlib-compat.h>
+
+int
+__new_sem_post (sem_t *sem)
+{
+ int *futex = (int *) sem;
+
+ __asm __volatile (__lll_rel_instr ::: "memory");
+ int nr = atomic_increment_val (futex);
+ int err = lll_futex_wake (futex, nr);
+ if (__builtin_expect (err, 0) < 0)
+ {
+ __set_errno (-err);
+ return -1;
+ }
+ return 0;
+}
+versioned_symbol (libpthread, __new_sem_post, sem_post, GLIBC_2_1);
+#if SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_1)
+strong_alias (__new_sem_post, __old_sem_post)
+compat_symbol (libpthread, __old_sem_post, sem_post, GLIBC_2_0);
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/pt-fork.c b/libc/nptl/sysdeps/unix/sysv/linux/pt-fork.c
new file mode 100644
index 000000000..a1e228ee2
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/pt-fork.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <unistd.h>
+
+
+pid_t
+__fork (void)
+{
+ return __libc_fork ();
+}
+strong_alias (__fork, fork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/pt-raise.c b/libc/nptl/sysdeps/unix/sysv/linux/pt-raise.c
new file mode 100644
index 000000000..9161e29e2
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/pt-raise.c
@@ -0,0 +1,52 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <signal.h>
+#include <sysdep.h>
+#include <tls.h>
+#include <kernel-features.h>
+
+
+int
+raise (sig)
+ int sig;
+{
+#if __ASSUME_TGKILL || defined __NR_tgkill
+ /* raise is an async-safe function. It could be called while the
+ fork function temporarily invalidated the PID field. Adjust for
+ that. */
+ pid_t pid = THREAD_GETMEM (THREAD_SELF, pid);
+ if (__builtin_expect (pid < 0, 0))
+ pid = -pid;
+#endif
+
+#if __ASSUME_TGKILL
+ return INLINE_SYSCALL (tgkill, 3, pid, THREAD_GETMEM (THREAD_SELF, tid),
+ sig);
+#else
+# ifdef __NR_tgkill
+ int res = INLINE_SYSCALL (tgkill, 3, pid, THREAD_GETMEM (THREAD_SELF, tid),
+ sig);
+ if (res != -1 || errno != ENOSYS)
+ return res;
+# endif
+ return INLINE_SYSCALL (tkill, 2, THREAD_GETMEM (THREAD_SELF, tid), sig);
+#endif
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/pthread-pi-defines.sym b/libc/nptl/sysdeps/unix/sysv/linux/pthread-pi-defines.sym
new file mode 100644
index 000000000..a1b679426
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/pthread-pi-defines.sym
@@ -0,0 +1,6 @@
+#include <pthreadP.h>
+
+-- These PI macros are used by assembly code.
+
+MUTEX_KIND offsetof (pthread_mutex_t, __data.__kind)
+PI_BIT PTHREAD_MUTEX_PRIO_INHERIT_NP
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/pthread_attr_getaffinity.c b/libc/nptl/sysdeps/unix/sysv/linux/pthread_attr_getaffinity.c
new file mode 100644
index 000000000..1c92f314d
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/pthread_attr_getaffinity.c
@@ -0,0 +1,69 @@
+/* Copyright (C) 2003, 2004 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 <assert.h>
+#include <errno.h>
+#include <pthreadP.h>
+#include <string.h>
+#include <sysdep.h>
+#include <sys/types.h>
+#include <shlib-compat.h>
+
+
+int
+__pthread_attr_getaffinity_new (const pthread_attr_t *attr, size_t cpusetsize,
+ cpu_set_t *cpuset)
+{
+ const struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (const struct pthread_attr *) attr;
+
+ if (iattr->cpuset != NULL)
+ {
+ /* Check whether there are any bits set beyond the limits
+ the user requested. */
+ for (size_t cnt = cpusetsize; cnt < iattr->cpusetsize; ++cnt)
+ if (((char *) iattr->cpuset)[cnt] != 0)
+ return EINVAL;
+
+ void *p = mempcpy (cpuset, iattr->cpuset, iattr->cpusetsize);
+ if (cpusetsize > iattr->cpusetsize)
+ memset (p, '\0', cpusetsize - iattr->cpusetsize);
+ }
+ else
+ /* We have no information. */
+ memset (cpuset, -1, cpusetsize);
+
+ return 0;
+}
+versioned_symbol (libpthread, __pthread_attr_getaffinity_new,
+ pthread_attr_getaffinity_np, GLIBC_2_3_4);
+
+
+#if SHLIB_COMPAT (libpthread, GLIBC_2_3_3, GLIBC_2_3_4)
+int
+__pthread_attr_getaffinity_old (const pthread_attr_t *attr, cpu_set_t *cpuset)
+{
+ /* The old interface by default assumed a 1024 processor bitmap. */
+ return __pthread_attr_getaffinity_new (attr, 128, cpuset);
+}
+compat_symbol (libpthread, __pthread_attr_getaffinity_old,
+ pthread_attr_getaffinity_np, GLIBC_2_3_3);
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/pthread_attr_setaffinity.c b/libc/nptl/sysdeps/unix/sysv/linux/pthread_attr_setaffinity.c
new file mode 100644
index 000000000..355e695ec
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/pthread_attr_setaffinity.c
@@ -0,0 +1,95 @@
+/* Copyright (C) 2003, 2004, 2006 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 <assert.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthreadP.h>
+#include <shlib-compat.h>
+
+
+/* Defined in pthread_setaffinity.c. */
+extern size_t __kernel_cpumask_size attribute_hidden;
+extern int __determine_cpumask_size (pid_t tid);
+
+
+int
+__pthread_attr_setaffinity_new (pthread_attr_t *attr, size_t cpusetsize,
+ const cpu_set_t *cpuset)
+{
+ struct pthread_attr *iattr;
+
+ assert (sizeof (*attr) >= sizeof (struct pthread_attr));
+ iattr = (struct pthread_attr *) attr;
+
+ if (cpuset == NULL || cpusetsize == 0)
+ {
+ free (iattr->cpuset);
+ iattr->cpuset = NULL;
+ iattr->cpusetsize = 0;
+ }
+ else
+ {
+ if (__kernel_cpumask_size == 0)
+ {
+ int res = __determine_cpumask_size (THREAD_SELF->tid);
+ if (res != 0)
+ /* Some serious problem. */
+ return res;
+ }
+
+ /* Check whether the new bitmask has any bit set beyond the
+ last one the kernel accepts. */
+ for (size_t cnt = __kernel_cpumask_size; cnt < cpusetsize; ++cnt)
+ if (((char *) cpuset)[cnt] != '\0')
+ /* Found a nonzero byte. This means the user request cannot be
+ fulfilled. */
+ return EINVAL;
+
+ if (iattr->cpusetsize != cpusetsize)
+ {
+ void *newp = (cpu_set_t *) realloc (iattr->cpuset, cpusetsize);
+ if (newp == NULL)
+ return ENOMEM;
+
+ iattr->cpuset = newp;
+ iattr->cpusetsize = cpusetsize;
+ }
+
+ memcpy (iattr->cpuset, cpuset, cpusetsize);
+ }
+
+ return 0;
+}
+versioned_symbol (libpthread, __pthread_attr_setaffinity_new,
+ pthread_attr_setaffinity_np, GLIBC_2_3_4);
+
+
+#if SHLIB_COMPAT (libpthread, GLIBC_2_3_3, GLIBC_2_3_4)
+int
+__pthread_attr_setaffinity_old (pthread_attr_t *attr, cpu_set_t *cpuset)
+{
+ /* The old interface by default assumed a 1024 processor bitmap. */
+ return __pthread_attr_setaffinity_new (attr, 128, cpuset);
+}
+compat_symbol (libpthread, __pthread_attr_setaffinity_old,
+ pthread_attr_setaffinity_np, GLIBC_2_3_3);
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/pthread_getaffinity.c b/libc/nptl/sysdeps/unix/sysv/linux/pthread_getaffinity.c
new file mode 100644
index 000000000..c382ed53a
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/pthread_getaffinity.c
@@ -0,0 +1,60 @@
+/* Copyright (C) 2003, 2004 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 <errno.h>
+#include <limits.h>
+#include <pthreadP.h>
+#include <string.h>
+#include <sysdep.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <shlib-compat.h>
+
+
+int
+__pthread_getaffinity_new (pthread_t th, size_t cpusetsize, cpu_set_t *cpuset)
+{
+ const struct pthread *pd = (const struct pthread *) th;
+
+ INTERNAL_SYSCALL_DECL (err);
+ int res = INTERNAL_SYSCALL (sched_getaffinity, err, 3, pd->tid,
+ MIN (INT_MAX, cpusetsize), cpuset);
+ if (INTERNAL_SYSCALL_ERROR_P (res, err))
+ return INTERNAL_SYSCALL_ERRNO (res, err);
+
+ /* Clean the rest of the memory the kernel didn't do. */
+ memset ((char *) cpuset + res, '\0', cpusetsize - res);
+
+ return 0;
+}
+strong_alias (__pthread_getaffinity_new, __pthread_getaffinity_np)
+versioned_symbol (libpthread, __pthread_getaffinity_new,
+ pthread_getaffinity_np, GLIBC_2_3_4);
+
+
+#if SHLIB_COMPAT (libpthread, GLIBC_2_3_3, GLIBC_2_3_4)
+int
+__pthread_getaffinity_old (pthread_t th, cpu_set_t *cpuset)
+{
+ /* The old interface by default assumed a 1024 processor bitmap. */
+ return __pthread_getaffinity_new (th, 128, cpuset);
+}
+compat_symbol (libpthread, __pthread_getaffinity_old, pthread_getaffinity_np,
+ GLIBC_2_3_3);
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/pthread_getcpuclockid.c b/libc/nptl/sysdeps/unix/sysv/linux/pthread_getcpuclockid.c
new file mode 100644
index 000000000..82c2446d5
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/pthread_getcpuclockid.c
@@ -0,0 +1,111 @@
+/* pthread_getcpuclockid -- Get POSIX clockid_t for a pthread_t. Linux version
+ Copyright (C) 2000,2001,2002,2003,2004,2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <pthreadP.h>
+#include <sys/time.h>
+#include <tls.h>
+#include <kernel-features.h>
+#include <kernel-posix-cpu-timers.h>
+
+
+#if !(__ASSUME_POSIX_CPU_TIMERS > 0)
+int __libc_missing_posix_cpu_timers attribute_hidden;
+#endif
+#if !(__ASSUME_POSIX_TIMERS > 0)
+int __libc_missing_posix_timers attribute_hidden;
+#endif
+
+int
+pthread_getcpuclockid (threadid, clockid)
+ pthread_t threadid;
+ clockid_t *clockid;
+{
+ struct pthread *pd = (struct pthread *) threadid;
+
+ /* Make sure the descriptor is valid. */
+ if (INVALID_TD_P (pd))
+ /* Not a valid thread handle. */
+ return ESRCH;
+
+#ifdef __NR_clock_getres
+ /* The clockid_t value is a simple computation from the TID.
+ But we do a clock_getres call to validate it if we aren't
+ yet sure we have the kernel support. */
+
+ const clockid_t tidclock = MAKE_THREAD_CPUCLOCK (pd->tid, CPUCLOCK_SCHED);
+
+# if !(__ASSUME_POSIX_CPU_TIMERS > 0)
+# if !(__ASSUME_POSIX_TIMERS > 0)
+ if (__libc_missing_posix_timers && !__libc_missing_posix_cpu_timers)
+ __libc_missing_posix_cpu_timers = 1;
+# endif
+ if (!__libc_missing_posix_cpu_timers)
+ {
+ INTERNAL_SYSCALL_DECL (err);
+ int r = INTERNAL_SYSCALL (clock_getres, err, 2, tidclock, NULL);
+ if (!INTERNAL_SYSCALL_ERROR_P (r, err))
+# endif
+ {
+ *clockid = tidclock;
+ return 0;
+ }
+
+# if !(__ASSUME_POSIX_CPU_TIMERS > 0)
+# if !(__ASSUME_POSIX_TIMERS > 0)
+ if (INTERNAL_SYSCALL_ERRNO (r, err) == ENOSYS)
+ {
+ /* The kernel doesn't support these calls at all. */
+ __libc_missing_posix_timers = 1;
+ __libc_missing_posix_cpu_timers = 1;
+ }
+ else
+# endif
+ if (INTERNAL_SYSCALL_ERRNO (r, err) == EINVAL)
+ {
+ /* The kernel doesn't support these clocks at all. */
+ __libc_missing_posix_cpu_timers = 1;
+ }
+ else
+ return INTERNAL_SYSCALL_ERRNO (r, err);
+ }
+# endif
+#endif
+
+#ifdef CLOCK_THREAD_CPUTIME_ID
+ /* We need to store the thread ID in the CLOCKID variable together
+ with a number identifying the clock. We reserve the low 3 bits
+ for the clock ID and the rest for the thread ID. This is
+ problematic if the thread ID is too large. But 29 bits should be
+ fine.
+
+ If some day more clock IDs are needed the ID part can be
+ enlarged. The IDs are entirely internal. */
+ if (pd->tid >= 1 << (8 * sizeof (*clockid) - CLOCK_IDFIELD_SIZE))
+ return ERANGE;
+
+ /* Store the number. */
+ *clockid = CLOCK_THREAD_CPUTIME_ID | (pd->tid << CLOCK_IDFIELD_SIZE);
+
+ return 0;
+#else
+ /* We don't have a timer for that. */
+ return ENOENT;
+#endif
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/pthread_kill.c b/libc/nptl/sysdeps/unix/sysv/linux/pthread_kill.c
new file mode 100644
index 000000000..9115d6f40
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/pthread_kill.c
@@ -0,0 +1,70 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <signal.h>
+#include <pthreadP.h>
+#include <tls.h>
+#include <sysdep.h>
+#include <kernel-features.h>
+
+
+int
+__pthread_kill (threadid, signo)
+ pthread_t threadid;
+ int signo;
+{
+ struct pthread *pd = (struct pthread *) threadid;
+
+ /* Make sure the descriptor is valid. */
+ if (INVALID_TD_P (pd))
+ /* Not a valid thread handle. */
+ return ESRCH;
+
+ /* Disallow sending the signal we use for cancellation, timers, for
+ for the setxid implementation. */
+ if (signo == SIGCANCEL || signo == SIGTIMER || signo == SIGSETXID)
+ return EINVAL;
+
+ /* We have a special syscall to do the work. */
+ INTERNAL_SYSCALL_DECL (err);
+
+ /* One comment: The PID field in the TCB can temporarily be changed
+ (in fork). But this must not affect this code here. Since this
+ function would have to be called while the thread is executing
+ fork, it would have to happen in a signal handler. But this is
+ no allowed, pthread_kill is not guaranteed to be async-safe. */
+ int val;
+#if __ASSUME_TGKILL
+ val = INTERNAL_SYSCALL (tgkill, err, 3, THREAD_GETMEM (THREAD_SELF, pid),
+ pd->tid, signo);
+#else
+# ifdef __NR_tgkill
+ val = INTERNAL_SYSCALL (tgkill, err, 3, THREAD_GETMEM (THREAD_SELF, pid),
+ pd->tid, signo);
+ if (INTERNAL_SYSCALL_ERROR_P (val, err)
+ && INTERNAL_SYSCALL_ERRNO (val, err) == ENOSYS)
+# endif
+ val = INTERNAL_SYSCALL (tkill, err, 2, pd->tid, signo);
+#endif
+
+ return (INTERNAL_SYSCALL_ERROR_P (val, err)
+ ? INTERNAL_SYSCALL_ERRNO (val, err) : 0);
+}
+strong_alias (__pthread_kill, pthread_kill)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/pthread_mutex_cond_lock.c b/libc/nptl/sysdeps/unix/sysv/linux/pthread_mutex_cond_lock.c
new file mode 100644
index 000000000..a97351f88
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/pthread_mutex_cond_lock.c
@@ -0,0 +1,9 @@
+#include <pthreadP.h>
+
+#define LLL_MUTEX_LOCK(mutex) lll_mutex_cond_lock (mutex)
+#define LLL_MUTEX_TRYLOCK(mutex) lll_mutex_cond_trylock (mutex)
+#define LLL_ROBUST_MUTEX_LOCK(mutex, id) lll_robust_mutex_cond_lock (mutex, id)
+#define __pthread_mutex_lock __pthread_mutex_cond_lock
+#define NO_INCR
+
+#include <nptl/pthread_mutex_lock.c>
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/pthread_setaffinity.c b/libc/nptl/sysdeps/unix/sysv/linux/pthread_setaffinity.c
new file mode 100644
index 000000000..3776e26e4
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/pthread_setaffinity.c
@@ -0,0 +1,99 @@
+/* Copyright (C) 2003, 2004, 2006 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 <alloca.h>
+#include <errno.h>
+#include <pthreadP.h>
+#include <sysdep.h>
+#include <sys/types.h>
+#include <shlib-compat.h>
+
+
+size_t __kernel_cpumask_size attribute_hidden;
+
+
+/* Determine the current affinity. As a side affect we learn
+ about the size of the cpumask_t in the kernel. */
+int
+__determine_cpumask_size (pid_t tid)
+{
+ INTERNAL_SYSCALL_DECL (err);
+ int res;
+
+ size_t psize = 128;
+ void *p = alloca (psize);
+
+ while (res = INTERNAL_SYSCALL (sched_getaffinity, err, 3, tid, psize, p),
+ INTERNAL_SYSCALL_ERROR_P (res, err)
+ && INTERNAL_SYSCALL_ERRNO (res, err) == EINVAL)
+ p = extend_alloca (p, psize, 2 * psize);
+
+ if (res == 0 || INTERNAL_SYSCALL_ERROR_P (res, err))
+ return INTERNAL_SYSCALL_ERRNO (res, err);
+
+ __kernel_cpumask_size = res;
+
+ return 0;
+}
+
+
+int
+__pthread_setaffinity_new (pthread_t th, size_t cpusetsize,
+ const cpu_set_t *cpuset)
+{
+ const struct pthread *pd = (const struct pthread *) th;
+
+ INTERNAL_SYSCALL_DECL (err);
+ int res;
+
+ if (__builtin_expect (__kernel_cpumask_size == 0, 0))
+ {
+ res = __determine_cpumask_size (pd->tid);
+ if (res != 0)
+ return res;
+ }
+
+ /* We now know the size of the kernel cpumask_t. Make sure the user
+ does not request to set a bit beyond that. */
+ for (size_t cnt = __kernel_cpumask_size; cnt < cpusetsize; ++cnt)
+ if (((char *) cpuset)[cnt] != '\0')
+ /* Found a nonzero byte. This means the user request cannot be
+ fulfilled. */
+ return EINVAL;
+
+ res = INTERNAL_SYSCALL (sched_setaffinity, err, 3, pd->tid, cpusetsize,
+ cpuset);
+ return (INTERNAL_SYSCALL_ERROR_P (res, err)
+ ? INTERNAL_SYSCALL_ERRNO (res, err)
+ : 0);
+}
+versioned_symbol (libpthread, __pthread_setaffinity_new,
+ pthread_setaffinity_np, GLIBC_2_3_4);
+
+
+#if SHLIB_COMPAT (libpthread, GLIBC_2_3_3, GLIBC_2_3_4)
+int
+__pthread_setaffinity_old (pthread_t th, cpu_set_t *cpuset)
+{
+ /* The old interface by default assumed a 1024 processor bitmap. */
+ return __pthread_setaffinity_new (th, 128, cpuset);
+}
+compat_symbol (libpthread, __pthread_setaffinity_old, pthread_setaffinity_np,
+ GLIBC_2_3_3);
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/pthread_yield.c b/libc/nptl/sysdeps/unix/sysv/linux/pthread_yield.c
new file mode 100644
index 000000000..5aecffcf0
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/pthread_yield.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <sched.h>
+
+
+/* With the 1-on-1 model we implement this function is equivalent to
+ the 'sched_yield' function. */
+int
+pthread_yield (void)
+{
+ return sched_yield ();
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/raise.c b/libc/nptl/sysdeps/unix/sysv/linux/raise.c
new file mode 100644
index 000000000..28d03c383
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/raise.c
@@ -0,0 +1,75 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <limits.h>
+#include <signal.h>
+#include <sysdep.h>
+#include <nptl/pthreadP.h>
+#include <kernel-features.h>
+
+
+int
+raise (sig)
+ int sig;
+{
+ struct pthread *pd = THREAD_SELF;
+#if __ASSUME_TGKILL || defined __NR_tgkill
+ pid_t pid = THREAD_GETMEM (pd, pid);
+#endif
+ pid_t selftid = THREAD_GETMEM (pd, tid);
+ if (selftid == 0)
+ {
+ /* This system call is not supposed to fail. */
+#ifdef INTERNAL_SYSCALL
+ INTERNAL_SYSCALL_DECL (err);
+ selftid = INTERNAL_SYSCALL (gettid, err, 0);
+#else
+ selftid = INLINE_SYSCALL (gettid, 0);
+#endif
+ THREAD_SETMEM (pd, tid, selftid);
+
+#if __ASSUME_TGKILL || defined __NR_tgkill
+ /* We do not set the PID field in the TID here since we might be
+ called from a signal handler while the thread executes fork. */
+ pid = selftid;
+#endif
+ }
+#if __ASSUME_TGKILL || defined __NR_tgkill
+ else
+ /* raise is an async-safe function. It could be called while the
+ fork/vfork function temporarily invalidated the PID field. Adjust for
+ that. */
+ if (__builtin_expect (pid <= 0, 0))
+ pid = (pid & INT_MAX) == 0 ? selftid : -pid;
+#endif
+
+#if __ASSUME_TGKILL
+ return INLINE_SYSCALL (tgkill, 3, pid, selftid, sig);
+#else
+# ifdef __NR_tgkill
+ int res = INLINE_SYSCALL (tgkill, 3, pid, selftid, sig);
+ if (res != -1 || errno != ENOSYS)
+ return res;
+# endif
+ return INLINE_SYSCALL (tkill, 2, selftid, sig);
+#endif
+}
+libc_hidden_def (raise)
+weak_alias (raise, gsignal)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/register-atfork.c b/libc/nptl/sysdeps/unix/sysv/linux/register-atfork.c
new file mode 100644
index 000000000..cb5b2b832
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/register-atfork.c
@@ -0,0 +1,135 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fork.h>
+
+
+/* Lock to protect allocation and deallocation of fork handlers. */
+lll_lock_t __fork_lock = LLL_LOCK_INITIALIZER;
+
+
+/* Number of pre-allocated handler entries. */
+#define NHANDLER 48
+
+/* Memory pool for fork handler structures. */
+static struct fork_handler_pool
+{
+ struct fork_handler_pool *next;
+ struct fork_handler mem[NHANDLER];
+} fork_handler_pool;
+
+
+static struct fork_handler *
+fork_handler_alloc (void)
+{
+ struct fork_handler_pool *runp = &fork_handler_pool;
+ struct fork_handler *result = NULL;
+ unsigned int i;
+
+ do
+ {
+ /* Search for an empty entry. */
+ for (i = 0; i < NHANDLER; ++i)
+ if (runp->mem[i].refcntr == 0)
+ goto found;
+ }
+ while ((runp = runp->next) != NULL);
+
+ /* We have to allocate a new entry. */
+ runp = (struct fork_handler_pool *) calloc (1, sizeof (*runp));
+ if (runp != NULL)
+ {
+ /* Enqueue the new memory pool into the list. */
+ runp->next = fork_handler_pool.next;
+ fork_handler_pool.next = runp;
+
+ /* We use the last entry on the page. This means when we start
+ searching from the front the next time we will find the first
+ entry unused. */
+ i = NHANDLER - 1;
+
+ found:
+ result = &runp->mem[i];
+ result->refcntr = 1;
+ result->need_signal = 0;
+ }
+
+ return result;
+}
+
+
+int
+__register_atfork (prepare, parent, child, dso_handle)
+ void (*prepare) (void);
+ void (*parent) (void);
+ void (*child) (void);
+ void *dso_handle;
+{
+ /* Get the lock to not conflict with other allocations. */
+ lll_lock (__fork_lock);
+
+ struct fork_handler *newp = fork_handler_alloc ();
+
+ if (newp != NULL)
+ {
+ /* Initialize the new record. */
+ newp->prepare_handler = prepare;
+ newp->parent_handler = parent;
+ newp->child_handler = child;
+ newp->dso_handle = dso_handle;
+
+ newp->next = __fork_handlers;
+ __fork_handlers = newp;
+ }
+
+ /* Release the lock. */
+ lll_unlock (__fork_lock);
+
+ return newp == NULL ? ENOMEM : 0;
+}
+libc_hidden_def (__register_atfork)
+
+
+libc_freeres_fn (free_mem)
+{
+ /* Get the lock to not conflict with running forks. */
+ lll_lock (__fork_lock);
+
+ /* No more fork handlers. */
+ __fork_handlers = NULL;
+
+ /* Free eventually alloated memory blocks for the object pool. */
+ struct fork_handler_pool *runp = fork_handler_pool.next;
+
+ memset (&fork_handler_pool, '\0', sizeof (fork_handler_pool));
+
+ /* Release the lock. */
+ lll_unlock (__fork_lock);
+
+ /* We can free the memory after releasing the lock. */
+ while (runp != NULL)
+ {
+ struct fork_handler_pool *oldp = runp;
+ runp = runp->next;
+ free (oldp);
+ }
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h b/libc/nptl/sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h
new file mode 100644
index 000000000..c77031d7b
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h
@@ -0,0 +1,217 @@
+/* Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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. */
+
+#ifndef _BITS_PTHREADTYPES_H
+#define _BITS_PTHREADTYPES_H 1
+
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+# define __SIZEOF_PTHREAD_ATTR_T 56
+# define __SIZEOF_PTHREAD_MUTEX_T 40
+# define __SIZEOF_PTHREAD_MUTEXATTR_T 4
+# define __SIZEOF_PTHREAD_COND_T 48
+# define __SIZEOF_PTHREAD_CONDATTR_T 4
+# define __SIZEOF_PTHREAD_RWLOCK_T 56
+# define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
+# define __SIZEOF_PTHREAD_BARRIER_T 32
+# define __SIZEOF_PTHREAD_BARRIERATTR_T 4
+#else
+# define __SIZEOF_PTHREAD_ATTR_T 36
+# define __SIZEOF_PTHREAD_MUTEX_T 24
+# define __SIZEOF_PTHREAD_MUTEXATTR_T 4
+# define __SIZEOF_PTHREAD_COND_T 48
+# define __SIZEOF_PTHREAD_CONDATTR_T 4
+# define __SIZEOF_PTHREAD_RWLOCK_T 32
+# define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
+# define __SIZEOF_PTHREAD_BARRIER_T 20
+# define __SIZEOF_PTHREAD_BARRIERATTR_T 4
+#endif
+
+
+/* Thread identifiers. The structure of the attribute type is not
+ exposed on purpose. */
+typedef unsigned long int pthread_t;
+
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_ATTR_T];
+ long int __align;
+} pthread_attr_t;
+
+
+#if __WORDSIZE == 64
+typedef struct __pthread_internal_list
+{
+ struct __pthread_internal_list *__prev;
+ struct __pthread_internal_list *__next;
+} __pthread_list_t;
+#else
+typedef struct __pthread_internal_slist
+{
+ struct __pthread_internal_slist *__next;
+} __pthread_slist_t;
+#endif
+
+
+/* Data structures for mutex handling. The structure of the attribute
+ type is not exposed on purpose. */
+typedef union
+{
+ struct __pthread_mutex_s
+ {
+ int __lock;
+ unsigned int __count;
+ int __owner;
+#if __WORDSIZE == 64
+ unsigned int __nusers;
+#endif
+ /* KIND must stay at this position in the structure to maintain
+ binary compatibility. */
+ int __kind;
+#if __WORDSIZE == 64
+ int __spins;
+ __pthread_list_t __list;
+# define __PTHREAD_MUTEX_HAVE_PREV 1
+#else
+ unsigned int __nusers;
+ __extension__ union
+ {
+ int __spins;
+ __pthread_slist_t __list;
+ };
+#endif
+ } __data;
+ char __size[__SIZEOF_PTHREAD_MUTEX_T];
+ long int __align;
+} pthread_mutex_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_MUTEXATTR_T];
+ int __align;
+} pthread_mutexattr_t;
+
+
+/* Data structure for conditional variable handling. The structure of
+ the attribute type is not exposed on purpose. */
+typedef union
+{
+ struct
+ {
+ int __lock;
+ unsigned int __futex;
+ __extension__ unsigned long long int __total_seq;
+ __extension__ unsigned long long int __wakeup_seq;
+ __extension__ unsigned long long int __woken_seq;
+ void *__mutex;
+ unsigned int __nwaiters;
+ unsigned int __broadcast_seq;
+ } __data;
+ char __size[__SIZEOF_PTHREAD_COND_T];
+ __extension__ long long int __align;
+} pthread_cond_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_CONDATTR_T];
+ int __align;
+} pthread_condattr_t;
+
+
+/* Keys for thread-specific data */
+typedef unsigned int pthread_key_t;
+
+
+/* Once-only execution */
+typedef int pthread_once_t;
+
+
+#if defined __USE_UNIX98 || defined __USE_XOPEN2K
+/* Data structure for read-write lock variable handling. The
+ structure of the attribute type is not exposed on purpose. */
+typedef union
+{
+# if __WORDSIZE == 64
+ struct
+ {
+ int __lock;
+ unsigned int __nr_readers;
+ unsigned int __readers_wakeup;
+ unsigned int __writer_wakeup;
+ unsigned int __nr_readers_queued;
+ unsigned int __nr_writers_queued;
+ int __writer;
+ int __pad1;
+ unsigned long int __pad2;
+ unsigned long int __pad3;
+ /* FLAGS must stay at this position in the structure to maintain
+ binary compatibility. */
+ unsigned int __flags;
+ } __data;
+# else
+ struct
+ {
+ int __lock;
+ unsigned int __nr_readers;
+ unsigned int __readers_wakeup;
+ unsigned int __writer_wakeup;
+ unsigned int __nr_readers_queued;
+ unsigned int __nr_writers_queued;
+ /* FLAGS must stay at this position in the structure to maintain
+ binary compatibility. */
+ unsigned int __flags;
+ int __writer;
+ } __data;
+# endif
+ char __size[__SIZEOF_PTHREAD_RWLOCK_T];
+ long int __align;
+} pthread_rwlock_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_RWLOCKATTR_T];
+ long int __align;
+} pthread_rwlockattr_t;
+#endif
+
+
+#ifdef __USE_XOPEN2K
+/* POSIX spinlock data type. */
+typedef volatile int pthread_spinlock_t;
+
+
+/* POSIX barriers data type. The structure of the type is
+ deliberately not exposed. */
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_BARRIER_T];
+ long int __align;
+} pthread_barrier_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_BARRIERATTR_T];
+ int __align;
+} pthread_barrierattr_t;
+#endif
+
+
+#endif /* bits/pthreadtypes.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/bits/semaphore.h b/libc/nptl/sysdeps/unix/sysv/linux/s390/bits/semaphore.h
new file mode 100644
index 000000000..ead266304
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/bits/semaphore.h
@@ -0,0 +1,43 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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. */
+
+#ifndef _SEMAPHORE_H
+# error "Never use <bits/semaphore.h> directly; include <semaphore.h> instead."
+#endif
+
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+# define __SIZEOF_SEM_T 32
+#else
+# define __SIZEOF_SEM_T 16
+#endif
+
+/* Value returned if `sem_open' failed. */
+#define SEM_FAILED ((sem_t *) 0)
+
+/* Maximum value the semaphore can have. */
+#define SEM_VALUE_MAX (2147483647)
+
+
+typedef union
+{
+ char __size[__SIZEOF_SEM_T];
+ long int __align;
+} sem_t;
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/fork.c b/libc/nptl/sysdeps/unix/sysv/linux/s390/fork.c
new file mode 100644
index 000000000..06635ab81
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/fork.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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 <sched.h>
+#include <signal.h>
+#include <sysdep.h>
+#include <tls.h>
+
+
+#define ARCH_FORK() \
+ INLINE_SYSCALL (clone, 5, \
+ 0, CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, \
+ NULL, &THREAD_SELF->tid, NULL)
+
+#include "../fork.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/jmp-unwind.c b/libc/nptl/sysdeps/unix/sysv/linux/s390/jmp-unwind.c
new file mode 100644
index 000000000..36886f58a
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/jmp-unwind.c
@@ -0,0 +1,41 @@
+/* Clean up stack frames unwound by longjmp. Linux/s390 version.
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <setjmp.h>
+#include <stddef.h>
+#include <pthreadP.h>
+
+extern void __pthread_cleanup_upto (__jmp_buf env, char *targetframe);
+#pragma weak __pthread_cleanup_upto
+
+
+void
+_longjmp_unwind (jmp_buf env, int val)
+{
+#ifdef SHARED
+# define fptr __libc_pthread_functions.ptr___pthread_cleanup_upto
+#else
+# define fptr __pthread_cleanup_upto
+#endif
+
+ unsigned char local_var;
+
+ if (fptr != NULL)
+ fptr (env->__jmpbuf, &local_var);
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/lowlevellock.h b/libc/nptl/sysdeps/unix/sysv/linux/s390/lowlevellock.h
new file mode 100644
index 000000000..38d9f2ac4
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/lowlevellock.h
@@ -0,0 +1,379 @@
+/* Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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. */
+
+#ifndef _LOWLEVELLOCK_H
+#define _LOWLEVELLOCK_H 1
+
+#include <time.h>
+#include <sys/param.h>
+#include <bits/pthreadtypes.h>
+#include <atomic.h>
+
+#define SYS_futex 238
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+#define FUTEX_REQUEUE 3
+#define FUTEX_CMP_REQUEUE 4
+#define FUTEX_WAKE_OP 5
+#define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE ((4 << 24) | 1)
+#define FUTEX_LOCK_PI 6
+#define FUTEX_UNLOCK_PI 7
+#define FUTEX_TRYLOCK_PI 8
+
+/* Initializer for compatibility lock. */
+#define LLL_MUTEX_LOCK_INITIALIZER (0)
+
+#define lll_futex_wait(futex, val) \
+ ({ \
+ register unsigned long int __r2 asm ("2") = (unsigned long int) (futex); \
+ register unsigned long int __r3 asm ("3") = FUTEX_WAIT; \
+ register unsigned long int __r4 asm ("4") = (unsigned long int) (val); \
+ register unsigned long int __r5 asm ("5") = 0ul; \
+ register unsigned long __result asm ("2"); \
+ \
+ __asm __volatile ("svc %b1" \
+ : "=d" (__result) \
+ : "i" (SYS_futex), "0" (__r2), "d" (__r3), \
+ "d" (__r4), "d" (__r5) \
+ : "cc", "memory" ); \
+ __result; \
+ })
+
+
+#define lll_futex_timed_wait(futex, val, timespec) \
+ ({ \
+ register unsigned long int __r2 asm ("2") = (unsigned long int) (futex); \
+ register unsigned long int __r3 asm ("3") = FUTEX_WAIT; \
+ register unsigned long int __r4 asm ("4") = (unsigned long int) (val); \
+ register unsigned long int __r5 asm ("5") = (unsigned long int)(timespec);\
+ register unsigned long int __result asm ("2"); \
+ \
+ __asm __volatile ("svc %b1" \
+ : "=d" (__result) \
+ : "i" (SYS_futex), "0" (__r2), "d" (__r3), \
+ "d" (__r4), "d" (__r5) \
+ : "cc", "memory" ); \
+ __result; \
+ })
+
+
+#define lll_futex_wake(futex, nr) \
+ ({ \
+ register unsigned long int __r2 asm ("2") = (unsigned long int) (futex); \
+ register unsigned long int __r3 asm ("3") = FUTEX_WAKE; \
+ register unsigned long int __r4 asm ("4") = (unsigned long int) (nr); \
+ register unsigned long int __result asm ("2"); \
+ \
+ __asm __volatile ("svc %b1" \
+ : "=d" (__result) \
+ : "i" (SYS_futex), "0" (__r2), "d" (__r3), "d" (__r4) \
+ : "cc", "memory" ); \
+ __result; \
+ })
+
+
+#define lll_robust_mutex_dead(futexv) \
+ do \
+ { \
+ int *__futexp = &(futexv); \
+ \
+ atomic_or (__futexp, FUTEX_OWNER_DIED); \
+ lll_futex_wake (__futexp, 1); \
+ } \
+ while (0)
+
+
+/* Returns non-zero if error happened, zero if success. */
+#define lll_futex_requeue(futex, nr_wake, nr_move, mutex, val) \
+ ({ \
+ register unsigned long int __r2 asm ("2") = (unsigned long int) (futex); \
+ register unsigned long int __r3 asm ("3") = FUTEX_CMP_REQUEUE; \
+ register unsigned long int __r4 asm ("4") = (long int) (nr_wake); \
+ register unsigned long int __r5 asm ("5") = (long int) (nr_move); \
+ register unsigned long int __r6 asm ("6") = (unsigned long int) (mutex); \
+ register unsigned long int __r7 asm ("7") = (int) (val); \
+ register unsigned long __result asm ("2"); \
+ \
+ __asm __volatile ("svc %b1" \
+ : "=d" (__result) \
+ : "i" (SYS_futex), "0" (__r2), "d" (__r3), \
+ "d" (__r4), "d" (__r5), "d" (__r6), "d" (__r7) \
+ : "cc", "memory" ); \
+ __result > -4096UL; \
+ })
+
+
+/* Returns non-zero if error happened, zero if success. */
+#define lll_futex_wake_unlock(futex, nr_wake, nr_wake2, futex2) \
+ ({ \
+ register unsigned long int __r2 asm ("2") = (unsigned long int) (futex); \
+ register unsigned long int __r3 asm ("3") = FUTEX_WAKE_OP; \
+ register unsigned long int __r4 asm ("4") = (long int) (nr_wake); \
+ register unsigned long int __r5 asm ("5") = (long int) (nr_wake2); \
+ register unsigned long int __r6 asm ("6") = (unsigned long int) (futex2); \
+ register unsigned long int __r7 asm ("7") \
+ = (int) FUTEX_OP_CLEAR_WAKE_IF_GT_ONE; \
+ register unsigned long __result asm ("2"); \
+ \
+ __asm __volatile ("svc %b1" \
+ : "=d" (__result) \
+ : "i" (SYS_futex), "0" (__r2), "d" (__r3), \
+ "d" (__r4), "d" (__r5), "d" (__r6), "d" (__r7) \
+ : "cc", "memory" ); \
+ __result > -4096UL; \
+ })
+
+
+#define lll_compare_and_swap(futex, oldval, newval, operation) \
+ do { \
+ __typeof (futex) __futex = (futex); \
+ __asm __volatile (" l %1,%0\n" \
+ "0: " operation "\n" \
+ " cs %1,%2,%0\n" \
+ " jl 0b\n" \
+ "1:" \
+ : "=Q" (*__futex), "=&d" (oldval), "=&d" (newval) \
+ : "m" (*__futex) : "cc", "memory" ); \
+ } while (0)
+
+
+static inline int
+__attribute__ ((always_inline))
+__lll_mutex_trylock (int *futex)
+{
+ unsigned int old;
+
+ __asm __volatile ("cs %0,%3,%1"
+ : "=d" (old), "=Q" (*futex)
+ : "0" (0), "d" (1), "m" (*futex) : "cc", "memory" );
+ return old != 0;
+}
+#define lll_mutex_trylock(futex) __lll_mutex_trylock (&(futex))
+
+
+static inline int
+__attribute__ ((always_inline))
+__lll_mutex_cond_trylock (int *futex)
+{
+ unsigned int old;
+
+ __asm __volatile ("cs %0,%3,%1"
+ : "=d" (old), "=Q" (*futex)
+ : "0" (0), "d" (2), "m" (*futex) : "cc", "memory" );
+ return old != 0;
+}
+#define lll_mutex_cond_trylock(futex) __lll_mutex_cond_trylock (&(futex))
+
+
+static inline int
+__attribute__ ((always_inline))
+__lll_robust_mutex_trylock (int *futex, int id)
+{
+ unsigned int old;
+
+ __asm __volatile ("cs %0,%3,%1"
+ : "=d" (old), "=Q" (*futex)
+ : "0" (0), "d" (id), "m" (*futex) : "cc", "memory" );
+ return old != 0;
+}
+#define lll_robust_mutex_trylock(futex, id) \
+ __lll_robust_mutex_trylock (&(futex), id)
+
+
+extern void __lll_lock_wait (int *futex) attribute_hidden;
+extern int __lll_robust_lock_wait (int *futex) attribute_hidden;
+
+static inline void
+__attribute__ ((always_inline))
+__lll_mutex_lock (int *futex)
+{
+ if (atomic_compare_and_exchange_bool_acq (futex, 1, 0) != 0)
+ __lll_lock_wait (futex);
+}
+#define lll_mutex_lock(futex) __lll_mutex_lock (&(futex))
+
+static inline int
+__attribute__ ((always_inline))
+__lll_robust_mutex_lock (int *futex, int id)
+{
+ int result = 0;
+ if (atomic_compare_and_exchange_bool_acq (futex, id, 0) != 0)
+ result = __lll_robust_lock_wait (futex);
+ return result;
+}
+#define lll_robust_mutex_lock(futex, id) __lll_robust_mutex_lock (&(futex), id)
+
+static inline void
+__attribute__ ((always_inline))
+__lll_mutex_cond_lock (int *futex)
+{
+ if (atomic_compare_and_exchange_bool_acq (futex, 2, 0) != 0)
+ __lll_lock_wait (futex);
+}
+#define lll_mutex_cond_lock(futex) __lll_mutex_cond_lock (&(futex))
+
+#define lll_robust_mutex_cond_lock(futex, id) \
+ __lll_robust_mutex_lock (&(futex), (id) | FUTEX_WAITERS)
+
+extern int __lll_timedlock_wait
+ (int *futex, const struct timespec *) attribute_hidden;
+extern int __lll_robust_timedlock_wait
+ (int *futex, const struct timespec *) attribute_hidden;
+
+static inline int
+__attribute__ ((always_inline))
+__lll_mutex_timedlock (int *futex, const struct timespec *abstime)
+{
+ int result = 0;
+ if (atomic_compare_and_exchange_bool_acq (futex, 1, 0) != 0)
+ result = __lll_timedlock_wait (futex, abstime);
+ return result;
+}
+#define lll_mutex_timedlock(futex, abstime) \
+ __lll_mutex_timedlock (&(futex), abstime)
+
+static inline int
+__attribute__ ((always_inline))
+__lll_robust_mutex_timedlock (int *futex, const struct timespec *abstime,
+ int id)
+{
+ int result = 0;
+ if (atomic_compare_and_exchange_bool_acq (futex, id, 0) != 0)
+ result = __lll_robust_timedlock_wait (futex, abstime);
+ return result;
+}
+#define lll_robust_mutex_timedlock(futex, abstime, id) \
+ __lll_robust_mutex_timedlock (&(futex), abstime, id)
+
+
+static inline void
+__attribute__ ((always_inline))
+__lll_mutex_unlock (int *futex)
+{
+ int oldval;
+ int newval = 0;
+
+ lll_compare_and_swap (futex, oldval, newval, "slr %2,%2");
+ if (oldval > 1)
+ lll_futex_wake (futex, 1);
+}
+#define lll_mutex_unlock(futex) \
+ __lll_mutex_unlock(&(futex))
+
+
+static inline void
+__attribute__ ((always_inline))
+__lll_robust_mutex_unlock (int *futex, int mask)
+{
+ int oldval;
+ int newval = 0;
+
+ lll_compare_and_swap (futex, oldval, newval, "slr %2,%2");
+ if (oldval & mask)
+ lll_futex_wake (futex, 1);
+}
+#define lll_robust_mutex_unlock(futex) \
+ __lll_robust_mutex_unlock(&(futex), FUTEX_WAITERS)
+
+
+static inline void
+__attribute__ ((always_inline))
+__lll_mutex_unlock_force (int *futex)
+{
+ *futex = 0;
+ lll_futex_wake (futex, 1);
+}
+#define lll_mutex_unlock_force(futex) \
+ __lll_mutex_unlock_force(&(futex))
+
+#define lll_mutex_islocked(futex) \
+ (futex != 0)
+
+
+/* We have a separate internal lock implementation which is not tied
+ to binary compatibility. We can use the lll_mutex_*. */
+
+/* Type for lock object. */
+typedef int lll_lock_t;
+
+/* Initializers for lock. */
+#define LLL_LOCK_INITIALIZER (0)
+#define LLL_LOCK_INITIALIZER_LOCKED (1)
+
+#define lll_trylock(futex) lll_mutex_trylock (futex)
+#define lll_lock(futex) lll_mutex_lock (futex)
+#define lll_unlock(futex) lll_mutex_unlock (futex)
+#define lll_islocked(futex) lll_mutex_islocked (futex)
+
+extern int lll_unlock_wake_cb (int *__futex) attribute_hidden;
+
+/* The states of a lock are:
+ 1 - untaken
+ 0 - taken by one user
+ <0 - taken by more users */
+
+
+/* The kernel notifies a process with uses CLONE_CLEARTID via futex
+ wakeup when the clone terminates. The memory location contains the
+ thread ID while the clone is running and is reset to zero
+ afterwards. */
+static inline void
+__attribute__ ((always_inline))
+__lll_wait_tid (int *ptid)
+{
+ int tid;
+
+ while ((tid = *ptid) != 0)
+ lll_futex_wait (ptid, tid);
+}
+#define lll_wait_tid(tid) __lll_wait_tid(&(tid))
+
+extern int __lll_timedwait_tid (int *, const struct timespec *)
+ attribute_hidden;
+
+#define lll_timedwait_tid(tid, abstime) \
+ ({ \
+ int __res = 0; \
+ if ((tid) != 0) \
+ __res = __lll_timedwait_tid (&(tid), (abstime)); \
+ __res; \
+ })
+
+/* Conditional variable handling. */
+
+extern void __lll_cond_wait (pthread_cond_t *cond)
+ attribute_hidden;
+extern int __lll_cond_timedwait (pthread_cond_t *cond,
+ const struct timespec *abstime)
+ attribute_hidden;
+extern void __lll_cond_wake (pthread_cond_t *cond)
+ attribute_hidden;
+extern void __lll_cond_broadcast (pthread_cond_t *cond)
+ attribute_hidden;
+
+#define lll_cond_wait(cond) \
+ __lll_cond_wait (cond)
+#define lll_cond_timedwait(cond, abstime) \
+ __lll_cond_timedwait (cond, abstime)
+#define lll_cond_wake(cond) \
+ __lll_cond_wake (cond)
+#define lll_cond_broadcast(cond) \
+ __lll_cond_broadcast (cond)
+
+#endif /* lowlevellock.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/not-cancel.h b/libc/nptl/sysdeps/unix/sysv/linux/s390/not-cancel.h
new file mode 100644
index 000000000..acf1a617e
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/not-cancel.h
@@ -0,0 +1 @@
+#include "../i386/not-cancel.h"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/pthread_once.c b/libc/nptl/sysdeps/unix/sysv/linux/s390/pthread_once.c
new file mode 100644
index 000000000..f29e23fd4
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/pthread_once.c
@@ -0,0 +1,111 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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 "pthreadP.h"
+#include <lowlevellock.h>
+
+
+unsigned long int __fork_generation attribute_hidden;
+
+
+static void
+clear_once_control (void *arg)
+{
+ pthread_once_t *once_control = (pthread_once_t *) arg;
+
+ *once_control = 0;
+ lll_futex_wake (once_control, INT_MAX);
+}
+
+
+int
+__pthread_once (once_control, init_routine)
+ pthread_once_t *once_control;
+ void (*init_routine) (void);
+{
+ while (1)
+ {
+ int oldval;
+ int newval;
+
+ /* Pseudo code:
+ oldval = *once_control;
+ if ((oldval & 2) == 0)
+ {
+ newval = (oldval & 3) | __fork_generation | 1;
+ *once_control = newval;
+ }
+ Do this atomically. */
+ __asm __volatile (" l %1,%0\n"
+ "0: lhi %2,2\n"
+ " tml %1,2\n"
+ " jnz 1f\n"
+ " nr %2,%1\n"
+ " ahi %2,1\n"
+ " o %2,%3\n"
+ " cs %1,%2,%0\n"
+ " jl 0b\n"
+ "1:"
+ : "=Q" (*once_control), "=&d" (oldval), "=&d" (newval)
+ : "m" (__fork_generation), "m" (*once_control)
+ : "cc" );
+ /* Check if the initialized has already been done. */
+ if ((oldval & 2) != 0)
+ break;
+ /* Check if another thread already runs the initializer. */
+ if ((oldval & 1) != 0)
+ {
+ /* Check whether the initializer execution was interrupted
+ by a fork. */
+ if (((oldval ^ newval) & -4) == 0)
+ {
+ /* Same generation, some other thread was faster. Wait. */
+ lll_futex_wait (once_control, newval);
+ continue;
+ }
+ }
+
+ /* This thread is the first here. Do the initialization.
+ Register a cleanup handler so that in case the thread gets
+ interrupted the initialization can be restarted. */
+ pthread_cleanup_push (clear_once_control, once_control);
+
+ init_routine ();
+
+ pthread_cleanup_pop (0);
+
+
+ /* Add one to *once_control. */
+ __asm __volatile (" l %1,%0\n"
+ "0: lr %2,%1\n"
+ " ahi %2,1\n"
+ " cs %1,%2,%0\n"
+ " jl 0b\n"
+ : "=Q" (*once_control), "=&d" (oldval), "=&d" (newval)
+ : "m" (*once_control) : "cc" );
+
+ /* Wake up all other threads. */
+ lll_futex_wake (once_control, INT_MAX);
+ break;
+ }
+
+ return 0;
+}
+weak_alias (__pthread_once, pthread_once)
+strong_alias (__pthread_once, __pthread_once_internal)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/clone.S b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/clone.S
new file mode 100644
index 000000000..675a997e9
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/clone.S
@@ -0,0 +1,9 @@
+/* We want an #include_next, but we are the main source file.
+ So, #include ourselves and in that incarnation we can use #include_next. */
+#ifndef INCLUDED_SELF
+# define INCLUDED_SELF
+# include <clone.S>
+#else
+# define RESET_PID
+# include_next <clone.S>
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/pt-initfini.c b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/pt-initfini.c
new file mode 100644
index 000000000..40d4d50c3
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/pt-initfini.c
@@ -0,0 +1,154 @@
+/* Special .init and .fini section support for S/390.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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.
+
+ In addition to the permissions in the GNU Lesser General Public
+ License, the Free Software Foundation gives you unlimited
+ permission to link the compiled version of this file with other
+ programs, and to distribute those programs without any restriction
+ coming from the use of this file. (The Lesser General Public
+ License restrictions do apply in other respects; for example, they
+ cover modification of the file, and distribution when not linked
+ into another program.)
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* This file is compiled into assembly code which is then munged by a sed
+ script into two files: crti.s and crtn.s.
+
+ * crti.s puts a function prologue at the beginning of the
+ .init and .fini sections and defines global symbols for
+ those addresses, so they can be called as functions.
+
+ * crtn.s puts the corresponding function epilogues
+ in the .init and .fini sections. */
+
+__asm__ ("\
+\n\
+#include \"defs.h\"\n\
+\n\
+/*@HEADER_ENDS*/\n\
+\n\
+/*@TESTS_BEGIN*/\n\
+\n\
+/*@TESTS_END*/\n\
+\n\
+/*@_init_PROLOG_BEGINS*/\n\
+\n\
+ .section .init\n\
+#NO_APP\n\
+ .align 4\n\
+.globl _init\n\
+ .type _init,@function\n\
+_init:\n\
+# leaf function 0\n\
+# automatics 0\n\
+# outgoing args 0\n\
+# need frame pointer 0\n\
+# call alloca 0\n\
+# has varargs 0\n\
+# incoming args (stack) 0\n\
+# function length 36\n\
+ STM 6,15,24(15)\n\
+ BRAS 13,.LTN1_0\n\
+.LT1_0:\n\
+.LC13:\n\
+ .long __pthread_initialize_minimal_internal-.LT1_0\n\
+.LC14:\n\
+ .long __gmon_start__@GOT\n\
+.LC15:\n\
+ .long _GLOBAL_OFFSET_TABLE_-.LT1_0\n\
+.LTN1_0:\n\
+ LR 1,15\n\
+ AHI 15,-96\n\
+ ST 1,0(15)\n\
+ L 12,.LC15-.LT1_0(13)\n\
+ AR 12,13\n\
+ L 1,.LC13-.LT1_0(13)\n\
+ LA 1,0(1,13)\n\
+ BASR 14,1\n\
+ L 1,.LC14-.LT1_0(13)\n\
+ L 1,0(1,12)\n\
+ LTR 1,1\n\
+ JE .L22\n\
+ BASR 14,1\n\
+.L22:\n\
+#APP\n\
+ .align 4,0x07\n\
+ END_INIT\n\
+\n\
+/*@_init_PROLOG_ENDS*/\n\
+\n\
+/*@_init_EPILOG_BEGINS*/\n\
+ .align 4\n\
+ .section .init\n\
+#NO_APP\n\
+ .align 4\n\
+ L 4,152(15)\n\
+ LM 6,15,120(15)\n\
+ BR 4\n\
+#APP\n\
+ END_INIT\n\
+\n\
+/*@_init_EPILOG_ENDS*/\n\
+\n\
+/*@_fini_PROLOG_BEGINS*/\n\
+ .section .fini\n\
+#NO_APP\n\
+ .align 4\n\
+.globl _fini\n\
+ .type _fini,@function\n\
+_fini:\n\
+# leaf function 0\n\
+# automatics 0\n\
+# outgoing args 0\n\
+# need frame pointer 0\n\
+# call alloca 0\n\
+# has varargs 0\n\
+# incoming args (stack) 0\n\
+# function length 30\n\
+ STM 6,15,24(15)\n\
+ BRAS 13,.LTN2_0\n\
+.LT2_0:\n\
+.LC17:\n\
+ .long _GLOBAL_OFFSET_TABLE_-.LT2_0\n\
+.LTN2_0:\n\
+ LR 1,15\n\
+ AHI 15,-96\n\
+ ST 1,0(15)\n\
+ L 12,.LC17-.LT2_0(13)\n\
+ AR 12,13\n\
+#APP\n\
+ .align 4,0x07\n\
+ END_FINI\n\
+\n\
+/*@_fini_PROLOG_ENDS*/\n\
+\n\
+/*@_fini_EPILOG_BEGINS*/\n\
+ .align 4\n\
+ .section .fini\n\
+#NO_APP\n\
+ .align 4\n\
+ L 4,152(15)\n\
+ LM 6,15,120(15)\n\
+ BR 4\n\
+#APP\n\
+ END_FINI\n\
+\n\
+/*@_fini_EPILOG_ENDS*/\n\
+\n\
+/*@TRAILER_BEGINS*/\
+");
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/pt-vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/pt-vfork.S
new file mode 100644
index 000000000..60d6dbdef
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/pt-vfork.S
@@ -0,0 +1,54 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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 <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <kernel-features.h>
+#include <bits/wordsize.h>
+#include <tcb-offsets.h>
+
+/* Clone the calling process, but without copying the whole address space.
+ The calling process is suspended until the new process exits or is
+ replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
+ and the process ID of the new process to the old process. */
+
+ENTRY (__vfork)
+ ear %r4,%a0
+ l %r3,PID(%r4)
+ lcr %r1,%r3
+ st %r1,PID(%r4)
+
+ /* Do vfork system call. */
+ svc SYS_ify (vfork)
+
+ ltr %r2,%r2
+ je 1f
+ st %r3,PID(%r4)
+1:
+ /* Check for error. */
+ lhi %r4,-4095
+ clr %r2,%r4
+ jnl SYSCALL_ERROR_LABEL
+
+ /* Normal return. */
+ br %r14
+PSEUDO_END(__vfork)
+
+weak_alias (__vfork, vfork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h
new file mode 100644
index 000000000..09dac2c90
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h
@@ -0,0 +1,115 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 <sysdep.h>
+#include <tls.h>
+#ifndef __ASSEMBLER__
+# include <nptl/pthreadP.h>
+#endif
+
+#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
+
+# undef PSEUDO
+# define PSEUDO(name, syscall_name, args) \
+ .text; \
+L(pseudo_cancel): \
+ cfi_startproc; \
+ STM_##args \
+ stm %r12,%r15,48(%r15); \
+ cfi_offset (%r15, -36); \
+ cfi_offset (%r14, -40); \
+ cfi_offset (%r13, -44); \
+ cfi_offset (%r12, -48); \
+ lr %r14,%r15; \
+ ahi %r15,-96; \
+ cfi_adjust_cfa_offset (96); \
+ st %r14,0(%r15); \
+ basr %r13,0; \
+0: l %r1,1f-0b(%r13); \
+ bas %r14,0(%r1,%r13); \
+ lr %r0,%r2; \
+ LM_##args \
+ DO_CALL(syscall_name, args); \
+ l %r1,2f-0b(%r13); \
+ lr %r12,%r2; \
+ lr %r2,%r0; \
+ bas %r14,0(%r1,%r13); \
+ lr %r2,%r12; \
+ lm %r12,%r15,48+96(%r15); \
+ cfi_endproc; \
+ j L(pseudo_check); \
+1: .long CENABLE-0b; \
+2: .long CDISABLE-0b; \
+ENTRY(name) \
+ SINGLE_THREAD_P(%r1) \
+ jne L(pseudo_cancel); \
+.type __##syscall_name##_nocancel,@function; \
+.globl __##syscall_name##_nocancel; \
+__##syscall_name##_nocancel: \
+ DO_CALL(syscall_name, args); \
+L(pseudo_check): \
+ lhi %r4,-4095; \
+ clr %r2,%r4; \
+ jnl SYSCALL_ERROR_LABEL; \
+.size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
+L(pseudo_end):
+
+# ifdef IS_IN_libpthread
+# define CENABLE __pthread_enable_asynccancel
+# define CDISABLE __pthread_disable_asynccancel
+# elif !defined NOT_IN_libc
+# define CENABLE __libc_enable_asynccancel
+# define CDISABLE __libc_disable_asynccancel
+# elif defined IS_IN_librt
+# define CENABLE __librt_enable_asynccancel
+# define CDISABLE __librt_disable_asynccancel
+# else
+# error Unsupported library
+# endif
+
+#define STM_0 /* Nothing */
+#define STM_1 st %r2,8(%r15);
+#define STM_2 stm %r2,%r3,8(%r15);
+#define STM_3 stm %r2,%r4,8(%r15);
+#define STM_4 stm %r2,%r5,8(%r15);
+#define STM_5 stm %r2,%r5,8(%r15);
+
+#define LM_0 /* Nothing */
+#define LM_1 l %r2,8+96(%r15);
+#define LM_2 lm %r2,%r3,8+96(%r15);
+#define LM_3 lm %r2,%r4,8+96(%r15);
+#define LM_4 lm %r2,%r5,8+96(%r15);
+#define LM_5 lm %r2,%r5,8+96(%r15);
+
+# ifndef __ASSEMBLER__
+# define SINGLE_THREAD_P \
+ __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+ header.multiple_threads) == 0, 1)
+# else
+# define SINGLE_THREAD_P(reg) \
+ ear reg,%a0; \
+ icm reg,15,MULTIPLE_THREADS_OFFSET(reg);
+# endif
+
+#elif !defined __ASSEMBLER__
+
+# define SINGLE_THREAD_P (1)
+# define NO_CANCELLATION 1
+
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/vfork.S
new file mode 100644
index 000000000..7b139341f
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/vfork.S
@@ -0,0 +1,57 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
+
+ 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 <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <kernel-features.h>
+#include <bits/wordsize.h>
+#include <tcb-offsets.h>
+
+/* Clone the calling process, but without copying the whole address space.
+ The calling process is suspended until the new process exits or is
+ replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
+ and the process ID of the new process to the old process. */
+
+ENTRY (__vfork)
+ ear %r4,%a0
+ lhi %r1,1
+ icm %r3,15,PID(%r4)
+ sll %r1,31
+ je 1f
+ lcr %r1,%r3
+1: st %r1,PID(%r4)
+
+ /* Do vfork system call. */
+ svc SYS_ify (vfork)
+
+ ltr %r2,%r2
+ je 1f
+ st %r3,PID(%r4)
+1:
+ /* Check for error. */
+ lhi %r4,-4095
+ clr %r2,%r4
+ jnl SYSCALL_ERROR_LABEL
+
+ /* Normal return. */
+ br %r14
+PSEUDO_END(__vfork)
+libc_hidden_def (__vfork)
+weak_alias (__vfork, vfork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/Versions b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/Versions
new file mode 100644
index 000000000..3b111ddb5
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/Versions
@@ -0,0 +1,7 @@
+librt {
+ GLIBC_2.3.3 {
+ # Changed timer_t.
+ timer_create; timer_delete; timer_getoverrun; timer_gettime;
+ timer_settime;
+ }
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/clone.S b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/clone.S
new file mode 100644
index 000000000..675a997e9
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/clone.S
@@ -0,0 +1,9 @@
+/* We want an #include_next, but we are the main source file.
+ So, #include ourselves and in that incarnation we can use #include_next. */
+#ifndef INCLUDED_SELF
+# define INCLUDED_SELF
+# include <clone.S>
+#else
+# define RESET_PID
+# include_next <clone.S>
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/pt-initfini.c b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/pt-initfini.c
new file mode 100644
index 000000000..a102d07d6
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/pt-initfini.c
@@ -0,0 +1,136 @@
+/* Special .init and .fini section support for 64 bit S/390.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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.
+
+ In addition to the permissions in the GNU Lesser General Public
+ License, the Free Software Foundation gives you unlimited
+ permission to link the compiled version of this file with other
+ programs, and to distribute those programs without any restriction
+ coming from the use of this file. (The Lesser General Public
+ License restrictions do apply in other respects; for example, they
+ cover modification of the file, and distribution when not linked
+ into another program.)
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* This file is compiled into assembly code which is then munged by a sed
+ script into two files: crti.s and crtn.s.
+
+ * crti.s puts a function prologue at the beginning of the
+ .init and .fini sections and defines global symbols for
+ those addresses, so they can be called as functions.
+
+ * crtn.s puts the corresponding function epilogues
+ in the .init and .fini sections. */
+
+__asm__ ("\
+\n\
+#include \"defs.h\"\n\
+\n\
+/*@HEADER_ENDS*/\n\
+\n\
+/*@TESTS_BEGIN*/\n\
+\n\
+/*@TESTS_END*/\n\
+\n\
+/*@_init_PROLOG_BEGINS*/\n\
+\n\
+ .section .init\n\
+#NO_APP\n\
+ .align 4\n\
+.globl _init\n\
+ .type _init,@function\n\
+_init:\n\
+# leaf function 0\n\
+# automatics 0\n\
+# outgoing args 0\n\
+# need frame pointer 0\n\
+# call alloca 0\n\
+# has varargs 0\n\
+# incoming args (stack) 0\n\
+# function length 36\n\
+ STMG 6,15,48(15)\n\
+ LGR 1,15\n\
+ AGHI 15,-160\n\
+ STG 1,0(15)\n\
+ LARL 12,_GLOBAL_OFFSET_TABLE_\n\
+ BRASL 14,__pthread_initialize_minimal_internal\n\
+ LARL 1,__gmon_start__@GOTENT\n\
+ LG 1,0(1)\n\
+ LTGR 1,1\n\
+ JE .L22\n\
+ BASR 14,1\n\
+.L22:\n\
+#APP\n\
+ .align 4,0x07\n\
+ END_INIT\n\
+\n\
+/*@_init_PROLOG_ENDS*/\n\
+\n\
+/*@_init_EPILOG_BEGINS*/\n\
+ .align 4\n\
+ .section .init\n\
+#NO_APP\n\
+ .align 4\n\
+ LG 4,272(15)\n\
+ LMG 6,15,208(15)\n\
+ BR 4\n\
+#APP\n\
+ END_INIT\n\
+\n\
+/*@_init_EPILOG_ENDS*/\n\
+\n\
+/*@_fini_PROLOG_BEGINS*/\n\
+ .section .fini\n\
+#NO_APP\n\
+ .align 4\n\
+.globl _fini\n\
+ .type _fini,@function\n\
+_fini:\n\
+# leaf function 0\n\
+# automatics 0\n\
+# outgoing args 0\n\
+# need frame pointer 0\n\
+# call alloca 0\n\
+# has varargs 0\n\
+# incoming args (stack) 0\n\
+# function length 30\n\
+ STMG 6,15,48(15)\n\
+ LGR 1,15\n\
+ AGHI 15,-160\n\
+ STG 1,0(15)\n\
+ LARL 12,_GLOBAL_OFFSET_TABLE_\n\
+#APP\n\
+ .align 4,0x07\n\
+ END_FINI\n\
+\n\
+/*@_fini_PROLOG_ENDS*/\n\
+\n\
+/*@_fini_EPILOG_BEGINS*/\n\
+ .align 4\n\
+ .section .fini\n\
+#NO_APP\n\
+ .align 4\n\
+ LG 4,272(15)\n\
+ LMG 6,15,208(15)\n\
+ BR 4\n\
+#APP\n\
+ END_FINI\n\
+\n\
+/*@_fini_EPILOG_ENDS*/\n\
+\n\
+/*@TRAILER_BEGINS*/\n\
+ ");
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/pt-vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/pt-vfork.S
new file mode 100644
index 000000000..04ae5bf59
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/pt-vfork.S
@@ -0,0 +1,57 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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 <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <kernel-features.h>
+#include <bits/wordsize.h>
+#include <tcb-offsets.h>
+
+/* Clone the calling process, but without copying the whole address space.
+ The calling process is suspended until the new process exits or is
+ replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
+ and the process ID of the new process to the old process. */
+
+ENTRY (__vfork)
+
+ ear %r4,%a0
+ sllg %r4,%r4,32
+ ear %r4,%a1
+ l %r3,PID(%r4)
+ lcr %r1,%r3
+ st %r1,PID(%r4)
+
+ /* Do vfork system call. */
+ svc SYS_ify (vfork)
+
+ ltgr %r2,%r2
+ je 1f
+ st %r3,PID(%r4)
+1:
+ /* Check for error. */
+ lghi %r4,-4095
+ clgr %r2,%r4
+ jgnl SYSCALL_ERROR_LABEL
+
+ /* Normal return. */
+ br %r14
+PSEUDO_END(__vfork)
+
+weak_alias (__vfork, vfork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h
new file mode 100644
index 000000000..f8eb6a9eb
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h
@@ -0,0 +1,128 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 <sysdep.h>
+#include <tls.h>
+#ifndef __ASSEMBLER__
+# include <nptl/pthreadP.h>
+#endif
+
+#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
+
+# undef PSEUDO
+# define PSEUDO(name, syscall_name, args) \
+ .text; \
+L(pseudo_cancel): \
+ cfi_startproc; \
+ STM_##args \
+ stmg %r13,%r15,104(%r15); \
+ cfi_offset (%r15,-40); \
+ cfi_offset (%r14,-48); \
+ cfi_offset (%r13,-56); \
+ lgr %r14,%r15; \
+ aghi %r15,-160; \
+ cfi_adjust_cfa_offset (160); \
+ stg %r14,0(%r15); \
+ brasl %r14,CENABLE; \
+ lgr %r0,%r2; \
+ LM_##args \
+ DO_CALL(syscall_name, args); \
+ lgr %r13,%r2; \
+ lgr %r2,%r0; \
+ brasl %r14,CDISABLE; \
+ lgr %r2,%r13; \
+ lmg %r13,%r15,104+160(%r15); \
+ cfi_endproc; \
+ j L(pseudo_check); \
+ENTRY(name) \
+ SINGLE_THREAD_P \
+ jne L(pseudo_cancel); \
+.type __##syscall_name##_nocancel,@function; \
+.globl __##syscall_name##_nocancel; \
+__##syscall_name##_nocancel: \
+ DO_CALL(syscall_name, args); \
+L(pseudo_check): \
+ lghi %r4,-4095; \
+ clgr %r2,%r4; \
+ jgnl SYSCALL_ERROR_LABEL; \
+.size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
+L(pseudo_end):
+
+# ifdef IS_IN_libpthread
+# define CENABLE __pthread_enable_asynccancel
+# define CDISABLE __pthread_disable_asynccancel
+# define __local_multiple_threads __pthread_multiple_threads
+# elif !defined NOT_IN_libc
+# define CENABLE __libc_enable_asynccancel
+# define CDISABLE __libc_disable_asynccancel
+# define __local_multiple_threads __libc_multiple_threads
+# elif defined IS_IN_librt
+# define CENABLE __librt_enable_asynccancel
+# define CDISABLE __librt_disable_asynccancel
+# else
+# error Unsupported library
+# endif
+
+#define STM_0 /* Nothing */
+#define STM_1 stg %r2,16(%r15);
+#define STM_2 stmg %r2,%r3,16(%r15);
+#define STM_3 stmg %r2,%r4,16(%r15);
+#define STM_4 stmg %r2,%r5,16(%r15);
+#define STM_5 stmg %r2,%r5,16(%r15);
+
+#define LM_0 /* Nothing */
+#define LM_1 lg %r2,16+160(%r15);
+#define LM_2 lmg %r2,%r3,16+160(%r15);
+#define LM_3 lmg %r2,%r4,16+160(%r15);
+#define LM_4 lmg %r2,%r5,16+160(%r15);
+#define LM_5 lmg %r2,%r5,16+160(%r15);
+
+# 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 \
+ larl %r1,__local_multiple_threads; \
+ icm %r0,15,0(%r1);
+# endif
+
+# else
+
+# ifndef __ASSEMBLER__
+# define SINGLE_THREAD_P \
+ __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+ header.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__
+
+# define SINGLE_THREAD_P (1)
+# define NO_CANCELLATION 1
+
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_create.c b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_create.c
new file mode 100644
index 000000000..172223af3
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_create.c
@@ -0,0 +1 @@
+#include "../x86_64/timer_create.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_delete.c b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_delete.c
new file mode 100644
index 000000000..537516e0a
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_delete.c
@@ -0,0 +1 @@
+#include "../x86_64/timer_delete.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_getoverr.c b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_getoverr.c
new file mode 100644
index 000000000..3f21a73c9
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_getoverr.c
@@ -0,0 +1 @@
+#include "../x86_64/timer_getoverr.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_gettime.c b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_gettime.c
new file mode 100644
index 000000000..a50143adc
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_gettime.c
@@ -0,0 +1 @@
+#include "../x86_64/timer_gettime.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_settime.c b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_settime.c
new file mode 100644
index 000000000..37baeffac
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_settime.c
@@ -0,0 +1 @@
+#include "../x86_64/timer_settime.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/vfork.S
new file mode 100644
index 000000000..f43e9c34b
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/vfork.S
@@ -0,0 +1,59 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
+
+ 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 <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <kernel-features.h>
+#include <bits/wordsize.h>
+#include <tcb-offsets.h>
+
+/* Clone the calling process, but without copying the whole address space.
+ The calling process is suspended until the new process exits or is
+ replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
+ and the process ID of the new process to the old process. */
+
+ENTRY (__vfork)
+
+ ear %r4,%a0
+ sllg %r4,%r4,32
+ ear %r4,%a1
+ icm %r3,15,PID(%r4)
+ llilh %r1,32768
+ je 1f
+ lcr %r1,%r3
+1: st %r1,PID(%r4)
+
+ /* Do vfork system call. */
+ svc SYS_ify (vfork)
+
+ ltgr %r2,%r2
+ je 1f
+ st %r3,PID(%r4)
+1:
+ /* Check for error. */
+ lghi %r4,-4095
+ clgr %r2,%r4
+ jgnl SYSCALL_ERROR_LABEL
+
+ /* Normal return. */
+ br %r14
+PSEUDO_END(__vfork)
+libc_hidden_def (__vfork)
+weak_alias (__vfork, vfork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sem_post.c b/libc/nptl/sysdeps/unix/sysv/linux/sem_post.c
new file mode 100644
index 000000000..671b43f7f
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sem_post.c
@@ -0,0 +1,47 @@
+/* sem_post -- post to a POSIX semaphore. Generic futex-using version.
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <internaltypes.h>
+#include <semaphore.h>
+
+#include <shlib-compat.h>
+
+int
+__new_sem_post (sem_t *sem)
+{
+ int *futex = (int *) sem;
+
+ int nr = atomic_increment_val (futex);
+ int err = lll_futex_wake (futex, nr);
+ if (__builtin_expect (err, 0) < 0)
+ {
+ __set_errno (-err);
+ return -1;
+ }
+ return 0;
+}
+versioned_symbol (libpthread, __new_sem_post, sem_post, GLIBC_2_1);
+#if SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_1)
+strong_alias (__new_sem_post, __old_sem_post)
+compat_symbol (libpthread, __old_sem_post, sem_post, GLIBC_2_0);
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sem_timedwait.c b/libc/nptl/sysdeps/unix/sysv/linux/sem_timedwait.c
new file mode 100644
index 000000000..ef897c1e9
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sem_timedwait.c
@@ -0,0 +1,99 @@
+/* sem_timedwait -- wait on a semaphore. Generic futex-using version.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus@au.ibm.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 <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <internaltypes.h>
+#include <semaphore.h>
+
+#include <pthreadP.h>
+#include <shlib-compat.h>
+
+
+int
+sem_timedwait (sem_t *sem, const struct timespec *abstime)
+{
+ /* First check for cancellation. */
+ CANCELLATION_P (THREAD_SELF);
+
+ int *futex = (int *) sem;
+ int val;
+ int err;
+
+ if (*futex > 0)
+ {
+ val = atomic_decrement_if_positive (futex);
+ if (val > 0)
+ return 0;
+ }
+
+ err = -EINVAL;
+ if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)
+ goto error_return;
+
+ do
+ {
+ struct timeval tv;
+ struct timespec rt;
+ int sec, nsec;
+
+ /* Get the current time. */
+ __gettimeofday (&tv, NULL);
+
+ /* Compute relative timeout. */
+ sec = abstime->tv_sec - tv.tv_sec;
+ nsec = abstime->tv_nsec - tv.tv_usec * 1000;
+ if (nsec < 0)
+ {
+ nsec += 1000000000;
+ --sec;
+ }
+
+ /* Already timed out? */
+ err = -ETIMEDOUT;
+ if (sec < 0)
+ goto error_return;
+
+ /* Do wait. */
+ rt.tv_sec = sec;
+ rt.tv_nsec = nsec;
+
+ /* Enable asynchronous cancellation. Required by the standard. */
+ int oldtype = __pthread_enable_asynccancel ();
+
+ err = lll_futex_timed_wait (futex, 0, &rt);
+
+ /* Disable asynchronous cancellation. */
+ __pthread_disable_asynccancel (oldtype);
+
+ if (err != 0 && err != -EWOULDBLOCK)
+ goto error_return;
+
+ val = atomic_decrement_if_positive (futex);
+ }
+ while (val <= 0);
+
+ return 0;
+
+ error_return:
+ __set_errno (-err);
+ return -1;
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sem_trywait.c b/libc/nptl/sysdeps/unix/sysv/linux/sem_trywait.c
new file mode 100644
index 000000000..f50036114
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sem_trywait.c
@@ -0,0 +1,50 @@
+/* sem_trywait -- wait on a semaphore. Generic futex-using version.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus@au.ibm.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 <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <internaltypes.h>
+#include <semaphore.h>
+
+#include <shlib-compat.h>
+
+
+int
+__new_sem_trywait (sem_t *sem)
+{
+ int *futex = (int *) sem;
+ int val;
+
+ if (*futex > 0)
+ {
+ val = atomic_decrement_if_positive (futex);
+ if (val > 0)
+ return 0;
+ }
+
+ __set_errno (EAGAIN);
+ return -1;
+}
+versioned_symbol (libpthread, __new_sem_trywait, sem_trywait, GLIBC_2_1);
+#if SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_1)
+strong_alias (__new_sem_trywait, __old_sem_trywait)
+compat_symbol (libpthread, __old_sem_trywait, sem_trywait, GLIBC_2_0);
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sem_wait.c b/libc/nptl/sysdeps/unix/sysv/linux/sem_wait.c
new file mode 100644
index 000000000..e6733e88a
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sem_wait.c
@@ -0,0 +1,63 @@
+/* sem_wait -- wait on a semaphore. Generic futex-using version.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus@au.ibm.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 <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <internaltypes.h>
+#include <semaphore.h>
+
+#include <pthreadP.h>
+#include <shlib-compat.h>
+
+
+int
+__new_sem_wait (sem_t *sem)
+{
+ /* First check for cancellation. */
+ CANCELLATION_P (THREAD_SELF);
+
+ int *futex = (int *) sem;
+ int err;
+
+ do
+ {
+ if (atomic_decrement_if_positive (futex) > 0)
+ return 0;
+
+ /* Enable asynchronous cancellation. Required by the standard. */
+ int oldtype = __pthread_enable_asynccancel ();
+
+ err = lll_futex_wait (futex, 0);
+
+ /* Disable asynchronous cancellation. */
+ __pthread_disable_asynccancel (oldtype);
+ }
+ while (err == 0 || err == -EWOULDBLOCK);
+
+ __set_errno (-err);
+ return -1;
+}
+
+versioned_symbol (libpthread, __new_sem_wait, sem_wait, GLIBC_2_1);
+#if SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_1)
+strong_alias (__new_sem_wait, __old_sem_wait)
+compat_symbol (libpthread, __old_sem_wait, sem_wait, GLIBC_2_0);
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h b/libc/nptl/sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h
new file mode 100644
index 000000000..969686dd5
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h
@@ -0,0 +1,168 @@
+/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+#ifndef _BITS_PTHREADTYPES_H
+#define _BITS_PTHREADTYPES_H 1
+
+#define __SIZEOF_PTHREAD_ATTR_T 36
+#define __SIZEOF_PTHREAD_MUTEX_T 24
+#define __SIZEOF_PTHREAD_MUTEXATTR_T 4
+#define __SIZEOF_PTHREAD_COND_T 48
+#define __SIZEOF_PTHREAD_COND_COMPAT_T 12
+#define __SIZEOF_PTHREAD_CONDATTR_T 4
+#define __SIZEOF_PTHREAD_RWLOCK_T 32
+#define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
+#define __SIZEOF_PTHREAD_BARRIER_T 20
+#define __SIZEOF_PTHREAD_BARRIERATTR_T 4
+
+
+/* Thread identifiers. The structure of the attribute type is not
+ exposed on purpose. */
+typedef unsigned long int pthread_t;
+
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_ATTR_T];
+ long int __align;
+} pthread_attr_t;
+
+
+typedef struct __pthread_internal_slist
+{
+ struct __pthread_internal_slist *__next;
+} __pthread_slist_t;
+
+
+/* Data structures for mutex handling. The structure of the attribute
+ type is not exposed on purpose. */
+typedef union
+{
+ struct __pthread_mutex_s
+ {
+ int __lock;
+ unsigned int __count;
+ int __owner;
+ /* KIND must stay at this position in the structure to maintain
+ binary compatibility. */
+ int __kind;
+ unsigned int __nusers;
+ __extension__ union
+ {
+ int __spins;
+ __pthread_slist_t __list;
+ };
+ } __data;
+ char __size[__SIZEOF_PTHREAD_MUTEX_T];
+ long int __align;
+} pthread_mutex_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_MUTEXATTR_T];
+ long int __align;
+} pthread_mutexattr_t;
+
+
+/* Data structure for conditional variable handling. The structure of
+ the attribute type is not exposed on purpose. */
+typedef union
+{
+ struct
+ {
+ int __lock;
+ unsigned int __futex;
+ __extension__ unsigned long long int __total_seq;
+ __extension__ unsigned long long int __wakeup_seq;
+ __extension__ unsigned long long int __woken_seq;
+ void *__mutex;
+ unsigned int __nwaiters;
+ unsigned int __broadcast_seq;
+ } __data;
+ char __size[__SIZEOF_PTHREAD_COND_T];
+ __extension__ long long int __align;
+} pthread_cond_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_CONDATTR_T];
+ long int __align;
+} pthread_condattr_t;
+
+
+/* Keys for thread-specific data */
+typedef unsigned int pthread_key_t;
+
+
+/* Once-only execution */
+typedef int pthread_once_t;
+
+
+#if defined __USE_UNIX98 || defined __USE_XOPEN2K
+/* Data structure for read-write lock variable handling. The
+ structure of the attribute type is not exposed on purpose. */
+typedef union
+{
+ struct
+ {
+ int __lock;
+ unsigned int __nr_readers;
+ unsigned int __readers_wakeup;
+ unsigned int __writer_wakeup;
+ unsigned int __nr_readers_queued;
+ unsigned int __nr_writers_queued;
+ /* FLAGS must stay at this position in the structure to maintain
+ binary compatibility. */
+ unsigned int __flags;
+ pthread_t __writer;
+ } __data;
+ char __size[__SIZEOF_PTHREAD_RWLOCK_T];
+ long int __align;
+} pthread_rwlock_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_RWLOCKATTR_T];
+ long int __align;
+} pthread_rwlockattr_t;
+#endif
+
+
+#ifdef __USE_XOPEN2K
+/* POSIX spinlock data type. */
+typedef volatile int pthread_spinlock_t;
+
+
+/* POSIX barriers data type. The structure of the type is
+ deliberately not exposed. */
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_BARRIER_T];
+ long int __align;
+} pthread_barrier_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_BARRIERATTR_T];
+ int __align;
+} pthread_barrierattr_t;
+#endif
+
+
+#endif /* bits/pthreadtypes.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/bits/semaphore.h b/libc/nptl/sysdeps/unix/sysv/linux/sh/bits/semaphore.h
new file mode 100644
index 000000000..e6c5d845c
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/bits/semaphore.h
@@ -0,0 +1,39 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+#ifndef _SEMAPHORE_H
+# error "Never use <bits/semaphore.h> directly; include <semaphore.h> instead."
+#endif
+
+
+#define __SIZEOF_SEM_T 16
+
+
+/* Value returned if `sem_open' failed. */
+#define SEM_FAILED ((sem_t *) 0)
+
+/* Maximum value the semaphore can have. */
+#define SEM_VALUE_MAX (2147483647)
+
+
+typedef union
+{
+ char __size[__SIZEOF_SEM_T];
+ long int __align;
+} sem_t;
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/clone.S b/libc/nptl/sysdeps/unix/sysv/linux/sh/clone.S
new file mode 100644
index 000000000..675a997e9
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/clone.S
@@ -0,0 +1,9 @@
+/* We want an #include_next, but we are the main source file.
+ So, #include ourselves and in that incarnation we can use #include_next. */
+#ifndef INCLUDED_SELF
+# define INCLUDED_SELF
+# include <clone.S>
+#else
+# define RESET_PID
+# include_next <clone.S>
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/createthread.c b/libc/nptl/sysdeps/unix/sysv/linux/sh/createthread.c
new file mode 100644
index 000000000..8e6821538
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/createthread.c
@@ -0,0 +1,24 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+/* Value passed to 'clone' for initialization of the thread register. */
+#define TLS_VALUE (pd + 1)
+
+
+/* Get the real implementation. */
+#include <nptl/sysdeps/pthread/createthread.c>
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/fork.c b/libc/nptl/sysdeps/unix/sysv/linux/sh/fork.c
new file mode 100644
index 000000000..6868b9bcd
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/fork.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sched.h>
+#include <signal.h>
+#include <sysdep.h>
+#include <tls.h>
+
+/* TLS pointer argument is passed as the 5-th argument. */
+#define ARCH_FORK() \
+ INLINE_SYSCALL (clone, 5, \
+ CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, 0, \
+ NULL, &THREAD_SELF->tid, NULL)
+
+#include "../fork.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/libc-lowlevellock.S b/libc/nptl/sysdeps/unix/sysv/linux/sh/libc-lowlevellock.S
new file mode 100644
index 000000000..94a24b46e
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/libc-lowlevellock.S
@@ -0,0 +1,19 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 "lowlevellock.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevel-atomic.h b/libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevel-atomic.h
new file mode 100644
index 000000000..76d22c88f
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevel-atomic.h
@@ -0,0 +1,79 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+#ifdef __ASSEMBLER__
+
+#define _IMP1 #1
+#define _IMM1 #-1
+#define _IMM4 #-4
+#define _IMM6 #-6
+#define _IMM8 #-8
+
+#define INC(mem, reg) \
+ .align 2; \
+ mova 99f, r0; \
+ mov r15, r1; \
+ mov _IMM6, r15; \
+98: mov.l mem, reg; \
+ add _IMP1, reg; \
+ mov.l reg, mem; \
+99: mov r1, r15
+
+#define DEC(mem, reg) \
+ .align 2; \
+ mova 99f, r0; \
+ mov r15, r1; \
+ mov _IMM6, r15; \
+98: mov.l mem, reg; \
+ add _IMM1, reg; \
+ mov.l reg, mem; \
+99: mov r1, r15
+
+#define XADD(reg, mem, old) \
+ .align 2; \
+ mova 99f, r0; \
+ mov r15, r1; \
+ mov _IMM6, r15; \
+98: mov.l mem, old; \
+ add old, reg; \
+ mov.l reg, mem; \
+99: mov r1, r15
+
+#define XCHG(reg, mem, old) \
+ .align 2; \
+ mova 99f, r0; \
+ nop; \
+ mov r15, r1; \
+ mov _IMM4, r15; \
+98: mov.l mem, old; \
+ mov.l reg, mem; \
+99: mov r1, r15
+
+#define CMPXCHG(reg, mem, new, old) \
+ .align 2; \
+ mova 99f, r0; \
+ nop; \
+ mov r15, r1; \
+ mov _IMM8, r15; \
+98: mov.l mem, old; \
+ cmp/eq old, reg; \
+ bf 99f; \
+ mov.l new, mem; \
+99: mov r1, r15
+
+#endif /* __ASSEMBLER__ */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.S b/libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.S
new file mode 100644
index 000000000..ac3169889
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.S
@@ -0,0 +1,326 @@
+/* Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#include <pthread-errnos.h>
+#include "lowlevel-atomic.h"
+
+ .text
+
+#define SYS_gettimeofday __NR_gettimeofday
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+
+ .globl __lll_mutex_lock_wait
+ .type __lll_mutex_lock_wait,@function
+ .hidden __lll_mutex_lock_wait
+ .align 5
+ cfi_startproc
+__lll_mutex_lock_wait:
+ mov.l r8, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r8, 0)
+ mov r4, r6
+ mov r5, r8
+ mov #0, r7 /* No timeout. */
+ mov #FUTEX_WAIT, r5
+
+ mov #2, r4
+ cmp/eq r4, r6
+ bf 2f
+
+1:
+ mov r8, r4
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+
+2:
+ mov #2, r6
+ XCHG (r6, @r8, r2)
+ tst r2, r2
+ bf 1b
+
+ mov.l @r15+, r8
+ ret
+ mov r2, r0
+ cfi_endproc
+ .size __lll_mutex_lock_wait,.-__lll_mutex_lock_wait
+
+
+#ifdef NOT_IN_libc
+ .globl __lll_mutex_timedlock_wait
+ .type __lll_mutex_timedlock_wait,@function
+ .hidden __lll_mutex_timedlock_wait
+ .align 5
+ cfi_startproc
+__lll_mutex_timedlock_wait:
+ /* Check for a valid timeout value. */
+ mov.l @(4,r6), r1
+ mov.l .L1g, r0
+ cmp/hs r0, r1
+ bt 3f
+
+ mov.l r10, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r10, 0)
+ mov.l r9, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r9, 0)
+ mov.l r8, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r8, 0)
+ mov r4, r10
+ mov r6, r9
+ mov r5, r8
+
+ /* Stack frame for the timespec and timeval structs. */
+ add #-8, r15
+ cfi_adjust_cfa_offset(8)
+
+1:
+ /* Get current time. */
+ mov r15, r4
+ mov #0, r5
+ mov #SYS_gettimeofday, r3
+ trapa #0x12
+ SYSCALL_INST_PAD
+
+ /* Compute relative timeout. */
+ mov.l @(4,r15), r0
+ mov.w .L1k, r1
+ dmulu.l r0, r1 /* Micro seconds to nano seconds. */
+ mov.l @r9, r2
+ mov.l @(4,r9), r3
+ mov.l @r15, r0
+ sts macl, r1
+ sub r0, r2
+ clrt
+ subc r1, r3
+ bf 4f
+ mov.l .L1g, r1
+ add r1, r3
+ add #-1, r2
+4:
+ cmp/pz r2
+ bf 5f /* Time is already up. */
+
+ mov.l r2, @r15 /* Store relative timeout. */
+ mov.l r3, @(4,r15)
+
+ mov #1, r3
+ mov #2, r4
+ CMPXCHG (r3, @r8, r4, r2)
+ tst r2, r2
+ bt 8f
+
+ mov r8, r4
+ mov #FUTEX_WAIT, r5
+ mov r10, r6
+ mov r15, r7
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+ mov r0, r5
+
+8:
+ mov #0, r3
+ mov #2, r4
+ CMPXCHG (r3, @r8, r4, r2)
+ bf/s 7f
+ mov #0, r0
+
+6:
+ add #8, r15
+ mov.l @r15+, r8
+ mov.l @r15+, r9
+ rts
+ mov.l @r15+, r10
+7:
+ /* Check whether the time expired. */
+ mov #-ETIMEDOUT, r1
+ cmp/eq r5, r1
+ bt 5f
+
+ /* Make sure the current holder knows we are going to sleep. */
+ XCHG (r2, @r8, r3)
+ tst r3, r3
+ bt/s 6b
+ mov #0, r0
+ bra 1b
+ nop
+3:
+ rts
+ mov #EINVAL, r0
+5:
+ bra 6b
+ mov #ETIMEDOUT, r0
+ cfi_endproc
+
+.L1k:
+ .word 1000
+ .align 2
+.L1g:
+ .long 1000000000
+
+ .size __lll_mutex_timedlock_wait,.-__lll_mutex_timedlock_wait
+#endif
+
+
+#ifdef NOT_IN_libc
+ .globl lll_unlock_wake_cb
+ .type lll_unlock_wake_cb,@function
+ .hidden lll_unlock_wake_cb
+ .align 5
+ cfi_startproc
+lll_unlock_wake_cb:
+ DEC (@r4, r2)
+ tst r2, r2
+ bt 1f
+
+ mov #FUTEX_WAKE, r5
+ mov #1, r6 /* Wake one thread. */
+ mov #0, r7
+ mov.l r7, @r4 /* Stores 0. */
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+
+1:
+ rts
+ nop
+ cfi_endproc
+ .size lll_unlock_wake_cb,.-lll_unlock_wake_cb
+#endif
+
+
+ .globl __lll_mutex_unlock_wake
+ .type __lll_mutex_unlock_wake,@function
+ .hidden __lll_mutex_unlock_wake
+ .align 5
+ cfi_startproc
+__lll_mutex_unlock_wake:
+ mov #FUTEX_WAKE, r5
+ mov #1, r6 /* Wake one thread. */
+ mov #0, r7
+ mov.l r7, @r4 /* Stores 0. */
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+ rts
+ nop
+ cfi_endproc
+ .size __lll_mutex_unlock_wake,.-__lll_mutex_unlock_wake
+
+
+#ifdef NOT_IN_libc
+ .globl __lll_timedwait_tid
+ .type __lll_timedwait_tid,@function
+ .hidden __lll_timedwait_tid
+ .align 5
+ cfi_startproc
+__lll_timedwait_tid:
+ mov.l r9, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r9, 0)
+ mov.l r8, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r8, 0)
+ mov r4, r8
+ mov r5, r9
+
+ /* Stack frame for the timespec and timeval structs. */
+ add #-8, r15
+ cfi_adjust_cfa_offset(8)
+
+2:
+ /* Get current time. */
+ mov r15, r4
+ mov #0, r5
+ mov #SYS_gettimeofday, r3
+ trapa #0x12
+ SYSCALL_INST_PAD
+
+ /* Compute relative timeout. */
+ mov.l @(4,r15), r0
+ mov.w .L1k2, r1
+ dmulu.l r0, r1 /* Micro seconds to nano seconds. */
+ mov.l @r9, r2
+ mov.l @(4,r9), r3
+ mov.l @r15, r0
+ sts macl, r1
+ sub r0, r2
+ clrt
+ subc r1, r3
+ bf 5f
+ mov.l .L1g2, r1
+ add r1, r3
+ add #-1, r2
+5:
+ cmp/pz r2
+ bf 6f /* Time is already up. */
+
+ mov.l r2, @r15 /* Store relative timeout. */
+ mov.l r3, @(4,r15)
+
+ mov.l @r8, r2
+ tst r2, r2
+ bt 4f
+
+ mov r8, r4
+ mov #FUTEX_WAIT, r5
+ mov r2, r6
+ mov r15, r7
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+
+ mov.l @r8, r2
+ tst r2, r2
+ bf 1f
+4:
+ mov #0, r0
+3:
+ add #8, r15
+ mov.l @r15+, r8
+ rts
+ mov.l @r15+, r9
+1:
+ /* Check whether the time expired. */
+ mov #-ETIMEDOUT, r1
+ cmp/eq r0, r1
+ bf 2b
+6:
+ bra 3b
+ mov #ETIMEDOUT, r0
+ cfi_endproc
+
+.L1k2:
+ .word 1000
+ .align 2
+.L1g2:
+ .long 1000000000
+ .size __lll_timedwait_tid,.-__lll_timedwait_tid
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.h b/libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.h
new file mode 100644
index 000000000..0eb1f0114
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.h
@@ -0,0 +1,410 @@
+/* Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+#ifndef _LOWLEVELLOCK_H
+#define _LOWLEVELLOCK_H 1
+
+#include <time.h>
+#include <sys/param.h>
+#include <bits/pthreadtypes.h>
+
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+#define FUTEX_LOCK_PI 6
+#define FUTEX_UNLOCK_PI 7
+#define FUTEX_TRYLOCK_PI 8
+
+
+/* Initializer for compatibility lock. */
+#define LLL_MUTEX_LOCK_INITIALIZER (0)
+#define LLL_MUTEX_LOCK_INITIALIZER_LOCKED (1)
+#define LLL_MUTEX_LOCK_INITIALIZER_WAITERS (2)
+
+extern int __lll_mutex_lock_wait (int val, int *__futex) attribute_hidden;
+extern int __lll_mutex_timedlock_wait (int val, int *__futex,
+ const struct timespec *abstime)
+ attribute_hidden;
+extern int __lll_mutex_unlock_wake (int *__futex) attribute_hidden;
+
+
+#define lll_mutex_trylock(futex) \
+ ({ unsigned char __result; \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ nop\n\
+ mov r15,r1\n\
+ mov #-8,r15\n\
+ 0: mov.l @%1,r2\n\
+ cmp/eq r2,%3\n\
+ bf 1f\n\
+ mov.l %2,@%1\n\
+ 1: mov r1,r15\n\
+ mov #-1,%0\n\
+ negc %0,%0"\
+ : "=r" (__result) \
+ : "r" (&(futex)), \
+ "r" (LLL_MUTEX_LOCK_INITIALIZER_LOCKED), \
+ "r" (LLL_MUTEX_LOCK_INITIALIZER) \
+ : "r0", "r1", "r2", "t", "memory"); \
+ __result; })
+
+#define lll_robust_mutex_trylock(futex, id) \
+ ({ unsigned char __result; \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ nop\n\
+ mov r15,r1\n\
+ mov #-8,r15\n\
+ 0: mov.l @%1,r2\n\
+ cmp/eq r2,%3\n\
+ bf 1f\n\
+ mov.l %2,@%1\n\
+ 1: mov r1,r15\n\
+ mov #-1,%0\n\
+ negc %0,%0"\
+ : "=r" (__result) \
+ : "r" (&(futex)), \
+ "r" (id), \
+ "r" (LLL_MUTEX_LOCK_INITIALIZER) \
+ : "r0", "r1", "r2", "t", "memory"); \
+ __result; })
+
+#define lll_mutex_cond_trylock(futex) \
+ ({ unsigned char __result; \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ nop\n\
+ mov r15,r1\n\
+ mov #-8,r15\n\
+ 0: mov.l @%1,r2\n\
+ cmp/eq r2,%3\n\
+ bf 1f\n\
+ mov.l %2,@%1\n\
+ 1: mov r1,r15\n\
+ mov #-1,%0\n\
+ negc %0,%0"\
+ : "=r" (__result) \
+ : "r" (&(futex)), \
+ "r" (LLL_MUTEX_LOCK_INITIALIZER_WAITERS), \
+ "r" (LLL_MUTEX_LOCK_INITIALIZER) \
+ : "r0", "r1", "r2", "t", "memory"); \
+ __result; })
+
+#define lll_mutex_lock(futex) \
+ (void) ({ int __result, val, *__futex = &(futex); \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ nop\n\
+ mov r15,r1\n\
+ mov #-8,r15\n\
+ 0: mov.l @%2,%0\n\
+ tst %0,%0\n\
+ bf 1f\n\
+ mov.l %1,@%2\n\
+ 1: mov r1,r15"\
+ : "=&r" (__result) : "r" (1), "r" (__futex) \
+ : "r0", "r1", "t", "memory"); \
+ if (__result) \
+ __lll_mutex_lock_wait (__result, __futex); })
+
+#define lll_robust_mutex_lock(futex, id) \
+ ({ int __result, val, *__futex = &(futex); \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ nop\n\
+ mov r15,r1\n\
+ mov #-8,r15\n\
+ 0: mov.l @%2,%0\n\
+ tst %0,%0\n\
+ bf 1f\n\
+ mov.l %1,@%2\n\
+ 1: mov r1,r15"\
+ : "=&r" (__result) : "r" (id), "r" (__futex) \
+ : "r0", "r1", "t", "memory"); \
+ if (__result) \
+ __result = __lll_robust_mutex_lock_wait (__result, __futex); \
+ __result; })
+
+/* Special version of lll_mutex_lock which causes the unlock function to
+ always wakeup waiters. */
+#define lll_mutex_cond_lock(futex) \
+ (void) ({ int __result, val, *__futex = &(futex); \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ nop\n\
+ mov r15,r1\n\
+ mov #-8,r15\n\
+ 0: mov.l @%2,%0\n\
+ tst %0,%0\n\
+ bf 1f\n\
+ mov.l %1,@%2\n\
+ 1: mov r1,r15"\
+ : "=&r" (__result) : "r" (2), "r" (__futex) \
+ : "r0", "r1", "t", "memory"); \
+ if (__result) \
+ __lll_mutex_lock_wait (__result, __futex); })
+
+#define lll_robust_mutex_cond_lock(futex, id) \
+ ({ int __result, val, *__futex = &(futex); \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ nop\n\
+ mov r15,r1\n\
+ mov #-8,r15\n\
+ 0: mov.l @%2,%0\n\
+ tst %0,%0\n\
+ bf 1f\n\
+ mov.l %1,@%2\n\
+ 1: mov r1,r15"\
+ : "=&r" (__result) : "r" (id | FUTEX_WAITERS), "r" (__futex) \
+ : "r0", "r1", "t", "memory"); \
+ if (__result) \
+ __result = __lll_robust_mutex_lock_wait (__result, __futex); \
+ __result; })
+
+#define lll_mutex_timedlock(futex, timeout) \
+ ({ int __result, val, *__futex = &(futex); \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ nop\n\
+ mov r15,r1\n\
+ mov #-8,r15\n\
+ 0: mov.l @%2,%0\n\
+ tst %0,%0\n\
+ bf 1f\n\
+ mov.l %1,@%2\n\
+ 1: mov r1,r15"\
+ : "=&r" (__result) : "r" (1), "r" (__futex) \
+ : "r0", "r1", "t", "memory"); \
+ if (__result) \
+ __result = __lll_mutex_timedlock_wait (__result, __futex, timeout); \
+ __result; })
+
+#define lll_robust_mutex_timedlock(futex, timeout, id) \
+ ({ int __result, val, *__futex = &(futex); \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ nop\n\
+ mov r15,r1\n\
+ mov #-8,r15\n\
+ 0: mov.l @%2,%0\n\
+ tst %0,%0\n\
+ bf 1f\n\
+ mov.l %1,@%2\n\
+ 1: mov r1,r15"\
+ : "=&r" (__result) : "r" (id), "r" (__futex) \
+ : "r0", "r1", "t", "memory"); \
+ if (__result) \
+ __result = __lll_robust_mutex_timedlock_wait (__result, __futex, \
+ timeout); \
+ __result; })
+
+#define lll_mutex_unlock(futex) \
+ (void) ({ int __result, *__futex = &(futex); \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ mov r15,r1\n\
+ mov #-6,r15\n\
+ 0: mov.l @%1,%0\n\
+ add #-1,%0\n\
+ mov.l %0,@%1\n\
+ 1: mov r1,r15"\
+ : "=&r" (__result) : "r" (__futex) \
+ : "r0", "r1", "memory"); \
+ if (__result) \
+ __lll_mutex_unlock_wake (__futex); })
+
+#define lll_robust_mutex_unlock(futex) \
+ (void) ({ int __result, *__futex = &(futex); \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ mov r15,r1\n\
+ mov #-6,r15\n\
+ 0: mov.l @%1,%0\n\
+ and %2,%0\n\
+ mov.l %0,@%1\n\
+ 1: mov r1,r15"\
+ : "=&r" (__result) : "r" (__futex), "r" (FUTEX_TID_MASK) \
+ : "r0", "r1", "memory"); \
+ if (__result) \
+ __lll_mutex_unlock_wake (__futex); })
+
+#define lll_robust_mutex_dead(futex) \
+ (void) ({ int __ignore, *__futex = &(futex); \
+ __asm __volatile ("\
+ .align 2\n\
+ mova 1f,r0\n\
+ mov r15,r1\n\
+ mov #-6,r15\n\
+ 0: mov.l @%1,%0\n\
+ or %2,%0\n\
+ mov.l %0,@%1\n\
+ 1: mov r1,r15"\
+ : "=&r" (__ignore) : "r" (__futex), "r" (FUTEX_OWNER_DIED) \
+ : "r0", "r1", "memory"); \
+ lll_futex_wake (__futex, 1); })
+
+#define lll_mutex_islocked(futex) \
+ (futex != 0)
+
+
+/* We have a separate internal lock implementation which is not tied
+ to binary compatibility. */
+
+/* Type for lock object. */
+typedef int lll_lock_t;
+
+/* Initializers for lock. */
+#define LLL_LOCK_INITIALIZER (0)
+#define LLL_LOCK_INITIALIZER_LOCKED (1)
+
+
+# ifdef NEED_SYSCALL_INST_PAD
+# define SYSCALL_WITH_INST_PAD "\
+ trapa #0x14; or r0,r0; or r0,r0; or r0,r0; or r0,r0; or r0,r0"
+# else
+# define SYSCALL_WITH_INST_PAD "\
+ trapa #0x14"
+# endif
+
+#define lll_futex_wait(futex, val) \
+ ({ \
+ int __status; \
+ register unsigned long __r3 asm ("r3") = SYS_futex; \
+ register unsigned long __r4 asm ("r4") = (unsigned long) (futex); \
+ register unsigned long __r5 asm ("r5") = FUTEX_WAIT; \
+ register unsigned long __r6 asm ("r6") = (unsigned long) (val); \
+ register unsigned long __r7 asm ("r7") = 0; \
+ __asm __volatile (SYSCALL_WITH_INST_PAD \
+ : "=z" (__status) \
+ : "r" (__r3), "r" (__r4), "r" (__r5), \
+ "r" (__r6), "r" (__r7) \
+ : "memory", "t"); \
+ __status; \
+ })
+
+
+#define lll_futex_timed_wait(futex, val, timeout) \
+ ({ \
+ int __status; \
+ register unsigned long __r3 asm ("r3") = SYS_futex; \
+ register unsigned long __r4 asm ("r4") = (unsigned long) (futex); \
+ register unsigned long __r5 asm ("r5") = FUTEX_WAIT; \
+ register unsigned long __r6 asm ("r6") = (unsigned long) (val); \
+ register unsigned long __r7 asm ("r7") = (timeout); \
+ __asm __volatile (SYSCALL_WITH_INST_PAD \
+ : "=z" (__status) \
+ : "r" (__r3), "r" (__r4), "r" (__r5), \
+ "r" (__r6), "r" (__r7) \
+ : "memory", "t"); \
+ __status; \
+ })
+
+
+#define lll_futex_wake(futex, nr) \
+ do { \
+ int __ignore; \
+ register unsigned long __r3 asm ("r3") = SYS_futex; \
+ register unsigned long __r4 asm ("r4") = (unsigned long) (futex); \
+ register unsigned long __r5 asm ("r5") = FUTEX_WAKE; \
+ register unsigned long __r6 asm ("r6") = (unsigned long) (nr); \
+ register unsigned long __r7 asm ("r7") = 0; \
+ __asm __volatile (SYSCALL_WITH_INST_PAD \
+ : "=z" (__ignore) \
+ : "r" (__r3), "r" (__r4), "r" (__r5), \
+ "r" (__r6), "r" (__r7) \
+ : "memory", "t"); \
+ } while (0)
+
+
+extern int lll_unlock_wake_cb (int *__futex) attribute_hidden;
+
+
+/* The states of a lock are:
+ 0 - untaken
+ 1 - taken by one user
+ 2 - taken by more users */
+
+#define lll_trylock(futex) lll_mutex_trylock (futex)
+#define lll_lock(futex) lll_mutex_lock (futex)
+#define lll_unlock(futex) lll_mutex_unlock (futex)
+
+#define lll_islocked(futex) \
+ (futex != LLL_LOCK_INITIALIZER)
+
+
+/* The kernel notifies a process with uses CLONE_CLEARTID via futex
+ wakeup when the clone terminates. The memory location contains the
+ thread ID while the clone is running and is reset to zero
+ afterwards. */
+
+extern int __lll_wait_tid (int *tid) attribute_hidden;
+#define lll_wait_tid(tid) \
+ do { \
+ __typeof (tid) *__tid = &(tid); \
+ while (*__tid != 0) \
+ lll_futex_wait (__tid, *__tid); \
+ } while (0)
+
+extern int __lll_timedwait_tid (int *tid, const struct timespec *abstime)
+ attribute_hidden;
+#define lll_timedwait_tid(tid, abstime) \
+ ({ \
+ int __result = 0; \
+ if (tid != 0) \
+ { \
+ if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) \
+ __result = EINVAL; \
+ else \
+ __result = __lll_timedwait_tid (&tid, abstime); \
+ } \
+ __result; })
+
+
+/* Conditional variable handling. */
+
+extern void __lll_cond_wait (pthread_cond_t *cond) attribute_hidden;
+extern int __lll_cond_timedwait (pthread_cond_t *cond,
+ const struct timespec *abstime)
+ attribute_hidden;
+extern void __lll_cond_wake (pthread_cond_t *cond) attribute_hidden;
+extern void __lll_cond_broadcast (pthread_cond_t *cond) attribute_hidden;
+
+
+#define lll_cond_wait(cond) \
+ __lll_cond_wait (cond)
+#define lll_cond_timedwait(cond, abstime) \
+ __lll_cond_timedwait (cond, abstime)
+#define lll_cond_wake(cond) \
+ __lll_cond_wake (cond)
+#define lll_cond_broadcast(cond) \
+ __lll_cond_broadcast (cond)
+
+#endif /* lowlevellock.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevelrobustlock.S b/libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevelrobustlock.S
new file mode 100644
index 000000000..c57d3cff1
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/lowlevelrobustlock.S
@@ -0,0 +1,224 @@
+/* Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#include <pthread-errnos.h>
+#include <lowlevelrobustlock.h>
+#include "lowlevel-atomic.h"
+
+ .text
+
+#define SYS_gettimeofday __NR_gettimeofday
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+#define FUTEX_WAITERS 0x80000000
+#define FUTEX_OWNER_DIED 0x40000000
+
+
+ .globl __lll_robust_mutex_lock_wait
+ .type __lll_robust_mutex_lock_wait,@function
+ .hidden __lll_robust_mutex_lock_wait
+ .align 5
+ cfi_startproc
+__lll_robust_mutex_lock_wait:
+ mov.l r8, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r8, 0)
+ mov r5, r8
+ mov #0, r7 /* No timeout. */
+ mov #FUTEX_WAIT, r5
+
+4:
+ mov r4, r6
+ mov.l .L_FUTEX_WAITERS, r0
+ or r0, r6
+ shlr r0 /* r0 = FUTEX_OWNER_DIED */
+ tst r0, r4
+ bf/s 3f
+ cmp/eq r4, r6
+ bt 1f
+
+ CMPXCHG (r4, @r8, r6, r2)
+ bf 2f
+
+1:
+ mov r8, r4
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+
+ mov.l @r8, r2
+
+2:
+ tst r2, r2
+ bf/s 4b
+ mov r2, r4
+
+ stc gbr, r1
+ mov.w .Ltidoff, r2
+ add r2, r1
+ mov.l @r1, r6
+ mov #0, r3
+ CMPXCHG (r3, @r8, r6, r4)
+ bf 4b
+ mov #0, r4
+
+3:
+ mov.l @r15+, r8
+ ret
+ mov r4, r0
+ cfi_endproc
+ .align 2
+.L_FUTEX_WAITERS:
+ .long FUTEX_WAITERS
+.Ltidoff:
+ .word TID - TLS_PRE_TCB_SIZE
+ .size __lll_robust_mutex_lock_wait,.-__lll_robust_mutex_lock_wait
+
+
+ .globl __lll_robust_mutex_timedlock_wait
+ .type __lll_robust_mutex_timedlock_wait,@function
+ .hidden __lll_robust_mutex_timedlock_wait
+ .align 5
+ cfi_startproc
+__lll_robust_mutex_timedlock_wait:
+ /* Check for a valid timeout value. */
+ mov.l @(4,r6), r1
+ mov.l .L1g, r0
+ cmp/hs r0, r1
+ bt 3f
+
+ mov.l r10, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r10, 0)
+ mov.l r9, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r9, 0)
+ mov.l r8, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r8, 0)
+ mov r4, r10
+ mov r6, r9
+ mov r5, r8
+
+ /* Stack frame for the timespec and timeval structs. */
+ add #-8, r15
+ cfi_adjust_cfa_offset(8)
+
+1:
+ /* Get current time. */
+ mov r15, r4
+ mov #0, r5
+ mov #SYS_gettimeofday, r3
+ trapa #0x12
+ SYSCALL_INST_PAD
+
+ /* Compute relative timeout. */
+ mov.l @(4,r15), r0
+ mov.w .L1k, r1
+ dmulu.l r0, r1 /* Micro seconds to nano seconds. */
+ mov.l @r9, r2
+ mov.l @(4,r9), r3
+ mov.l @r15, r0
+ sts macl, r1
+ sub r0, r2
+ clrt
+ subc r1, r3
+ bf 4f
+ mov.l .L1g, r1
+ add r1, r3
+ add #-1, r2
+4:
+ cmp/pz r2
+ bf 8f /* Time is already up. */
+
+ mov.l r2, @r15 /* Store relative timeout. */
+ mov.l r3, @(4,r15)
+
+ mov r10, r6
+ mov.l .L_FUTEX_WAITERS2, r0
+ or r0, r6
+ shlr r0 /* r0 = FUTEX_OWNER_DIED */
+ tst r0, r4
+ bf/s 6f
+ cmp/eq r4, r6
+ bt 2f
+
+ CMPXCHG (r4, @r8, r6, r2)
+ bf/s 5f
+ mov #0, r5
+
+2:
+ mov r8, r4
+ mov #FUTEX_WAIT, r5
+ mov r10, r6
+ mov r15, r7
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+ mov r0, r5
+
+ mov.l @r8, r2
+
+5:
+ tst r2, r2
+ bf/s 7f
+ mov r2, r10
+
+ stc gbr, r1
+ mov.w .Ltidoff2, r2
+ add r2, r1
+ mov.l @r1, r4
+ mov #0, r3
+ CMPXCHG (r3, @r8, r4, r10)
+ bf 7f
+ mov #0, r0
+
+6:
+ add #8, r15
+ mov.l @r15+, r8
+ mov.l @r15+, r9
+ rts
+ mov.l @r15+, r10
+
+7:
+ /* Check whether the time expired. */
+ mov #-ETIMEDOUT, r1
+ cmp/eq r5, r1
+ bf 1b
+
+8:
+ bra 6b
+ mov #ETIMEDOUT, r0
+3:
+ rts
+ mov #EINVAL, r0
+ cfi_endproc
+ .align 2
+.L_FUTEX_WAITERS2:
+ .long FUTEX_WAITERS
+.L1g:
+ .long 1000000000
+.Ltidoff2:
+ .word TID - TLS_PRE_TCB_SIZE
+.L1k:
+ .word 1000
+ .size __lll_robust_mutex_timedlock_wait,.-__lll_robust_mutex_timedlock_wait
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/not-cancel.h b/libc/nptl/sysdeps/unix/sysv/linux/sh/not-cancel.h
new file mode 100644
index 000000000..acf1a617e
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/not-cancel.h
@@ -0,0 +1 @@
+#include "../i386/not-cancel.h"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/pt-initfini.c b/libc/nptl/sysdeps/unix/sysv/linux/sh/pt-initfini.c
new file mode 100644
index 000000000..5391d5cc8
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/pt-initfini.c
@@ -0,0 +1,143 @@
+/* Special .init and .fini section support for SH. NPTL version.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it
+ and/or modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ In addition to the permissions in the GNU Library General Public
+ License, the Free Software Foundation gives you unlimited
+ permission to link the compiled version of this file with other
+ programs, and to distribute those programs without any restriction
+ coming from the use of this file. (The Library General Public
+ License restrictions do apply in other respects; for example, they
+ cover modification of the file, and distribution when not linked
+ into another program.)
+
+ 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* This file is compiled into assembly code which is then munged by a sed
+ script into two files: crti.s and crtn.s.
+
+ * crti.s puts a function prologue at the beginning of the
+ .init and .fini sections and defines global symbols for
+ those addresses, so they can be called as functions.
+
+ * crtn.s puts the corresponding function epilogues
+ in the .init and .fini sections. */
+
+__asm__ ("\n\
+\n\
+#include \"defs.h\"\n\
+\n\
+/*@HEADER_ENDS*/\n\
+\n\
+/*@TESTS_BEGIN*/\n\
+\n\
+/*@TESTS_END*/\n\
+\n\
+/*@_init_PROLOG_BEGINS*/\n\
+ .section .init\n\
+ .align 5\n\
+ .global _init\n\
+ .type _init,@function\n\
+_init:\n\
+ mov.l r12,@-r15\n\
+ mov.l r14,@-r15\n\
+ sts.l pr,@-r15\n\
+ mova .L22,r0\n\
+ mov.l .L22,r12\n\
+ add r0,r12\n\
+ mova .L24,r0\n\
+ mov.l .L24,r1\n\
+ add r0,r1\n\
+ jsr @r1\n\
+ nop\n\
+ mova .L23,r0\n\
+ mov.l .L23,r1\n\
+ add r0,r1\n\
+ jsr @r1\n\
+ mov r15,r14\n\
+ bra 1f\n\
+ nop\n\
+ .align 2\n\
+.L22:\n\
+ .long _GLOBAL_OFFSET_TABLE_\n\
+.L23:\n\
+ .long __gmon_start__@PLT\n\
+.L24:\n\
+ .long __pthread_initialize_minimal_internal@PLT\n\
+1:\n\
+ ALIGN\n\
+ END_INIT\n\
+\n\
+/*@_init_PROLOG_ENDS*/\n\
+\n\
+/*@_init_EPILOG_BEGINS*/\n\
+ .section .init\n\
+ mov r14,r15\n\
+ lds.l @r15+,pr\n\
+ mov.l @r15+,r14\n\
+ rts \n\
+ mov.l @r15+,r12\n\
+ END_INIT\n\
+ .section .text\n\
+ .align 5\n\
+ .weak __gmon_start__\n\
+ .type __gmon_start__,@function\n\
+__gmon_start__:\n\
+ mov.l r14,@-r15\n\
+ mov r15,r14\n\
+ mov r14,r15\n\
+ rts \n\
+ mov.l @r15+,r14\n\
+ \n\
+/*@_init_EPILOG_ENDS*/\n\
+\n\
+/*@_fini_PROLOG_BEGINS*/\n\
+ .section .fini\n\
+ .align 5\n\
+ .global _fini\n\
+ .type _fini,@function\n\
+_fini:\n\
+ mov.l r12,@-r15\n\
+ mov.l r14,@-r15\n\
+ sts.l pr,@-r15\n\
+ mova .L27,r0\n\
+ mov.l .L27,r12\n\
+ add r0,r12\n\
+ mov r15,r14\n\
+ ALIGN\n\
+ END_FINI\n\
+ bra 1f\n\
+ nop\n\
+ .align 2\n\
+.L27:\n\
+ .long _GLOBAL_OFFSET_TABLE_\n\
+1:\n\
+/*@_fini_PROLOG_ENDS*/\n\
+\n\
+/*@_fini_EPILOG_BEGINS*/\n\
+ .section .fini\n\
+ mov r14,r15\n\
+ lds.l @r15+,pr\n\
+ mov.l @r15+,r14\n\
+ rts \n\
+ mov.l @r15+,r12\n\
+\n\
+ END_FINI\n\
+ \n\
+/*@_fini_EPILOG_ENDS*/\n\
+\n\
+/*@TRAILER_BEGINS*/\n\
+");
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/pt-vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/sh/pt-vfork.S
new file mode 100644
index 000000000..2d1148daa
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/pt-vfork.S
@@ -0,0 +1,66 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <tcb-offsets.h>
+
+/* Clone the calling process, but without copying the whole address space.
+ The calling process is suspended until the new process exits or is
+ replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
+ and the process ID of the new process to the old process. */
+
+ENTRY (__vfork)
+ /* Save the PID value. */
+ stc gbr, r2
+ mov.w .L2, r0
+ mov.l @(r0,r2), r4
+ neg r4, r1
+ mov.l r1, @(r0,r2)
+
+ mov.w .L1, r3
+ trapa #0x10
+ mov r0, r1
+
+ /* Restore the old PID value in the parent. */
+ tst r0, r0
+ bt/s 2f
+ stc gbr, r2
+ mov.w .L2, r0
+ mov.l r4, @(r0,r2)
+ mov r1, r0
+2:
+ mov #-12, r2
+ shad r2, r1
+ not r1, r1 // r1=0 means r0 = -1 to -4095
+ tst r1, r1 // i.e. error in linux
+ bf .Lpseudo_end
+ SYSCALL_ERROR_HANDLER
+.Lpseudo_end:
+ rts
+ nop
+.L1:
+ .word __NR_vfork
+.L2:
+ .word PID - TLS_PRE_TCB_SIZE
+
+PSEUDO_END (__vfork)
+libc_hidden_def (__vfork)
+
+weak_alias (__vfork, vfork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_barrier_wait.S b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_barrier_wait.S
new file mode 100644
index 000000000..1fbb23a5a
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_barrier_wait.S
@@ -0,0 +1,196 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#include <lowlevelbarrier.h>
+#include "lowlevel-atomic.h"
+
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+
+ .text
+
+ .globl pthread_barrier_wait
+ .type pthread_barrier_wait,@function
+ .align 5
+pthread_barrier_wait:
+ mov.l r9, @-r15
+ mov.l r8, @-r15
+ sts.l pr, @-r15
+ mov r4, r8
+
+ /* Get the mutex. */
+ mov #0, r3
+ mov #1, r4
+ CMPXCHG (r3, @(MUTEX,r8), r4, r2)
+ bf 1f
+
+ /* One less waiter. If this was the last one needed wake
+ everybody. */
+2:
+ mov.l @(LEFT,r8), r0
+ add #-1, r0
+ mov.l r0, @(LEFT,r8)
+ tst r0, r0
+ bt 3f
+
+ /* There are more threads to come. */
+ mov.l @(CURR_EVENT,r8), r6
+
+ /* Release the mutex. */
+ DEC (@(MUTEX,r8), r2)
+ tst r2, r2
+ bf 6f
+7:
+ /* Wait for the remaining threads. The call will return immediately
+ if the CURR_EVENT memory has meanwhile been changed. */
+ mov r8, r4
+#if CURR_EVENT != 0
+ add #CURR_EVENT, r4
+#endif
+ mov #FUTEX_WAIT, r5
+ mov #0, r7
+8:
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+
+ /* Don't return on spurious wakeups. The syscall does not change
+ any register except r0 so there is no need to reload any of
+ them. */
+ mov.l @(CURR_EVENT,r8), r0
+ cmp/eq r0, r6
+ bt 8b
+
+ /* Increment LEFT. If this brings the count back to the
+ initial count unlock the object. */
+ mov #1, r3
+ mov.l @(INIT_COUNT,r8), r4
+ XADD (r3, @(LEFT,r8), r2)
+ add #-1, r4
+ cmp/eq r2, r4
+ bf 10f
+
+ /* Release the mutex. We cannot release the lock before
+ waking the waiting threads since otherwise a new thread might
+ arrive and gets waken up, too. */
+ DEC (@(MUTEX,r8), r2)
+ tst r2, r2
+ bf 9f
+
+10:
+ mov #0, r0 /* != PTHREAD_BARRIER_SERIAL_THREAD */
+ lds.l @r15+, pr
+ mov.l @r15+, r8
+ rts
+ mov.l @r15+, r9
+
+3:
+ /* The necessary number of threads arrived. */
+ mov.l @(CURR_EVENT,r8), r1
+ add #1, r1
+ mov.l r1, @(CURR_EVENT,r8)
+
+ /* Wake up all waiters. The count is a signed number in the kernel
+ so 0x7fffffff is the highest value. */
+ mov.l .Lall, r6
+ mov r8, r4
+#if CURR_EVENT != 0
+ add #CURR_EVENT, r4
+#endif
+ mov #0, r7
+ mov #FUTEX_WAKE, r5
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+
+ /* Increment LEFT. If this brings the count back to the
+ initial count unlock the object. */
+ mov #1, r3
+ mov.l @(INIT_COUNT,r8), r4
+ XADD (r3, @(LEFT,r8), r2)
+ add #-1, r4
+ cmp/eq r2, r4
+ bf 5f
+
+ /* Release the mutex. */
+ DEC (@(MUTEX,r8), r2)
+ tst r2, r2
+ bf 4f
+5:
+ mov #-1, r0 /* == PTHREAD_BARRIER_SERIAL_THREAD */
+ lds.l @r15+, pr
+ mov.l @r15+, r8
+ ret
+ mov.l @r15+, r9
+
+1:
+ mov r2, r4
+ mov r8, r5
+ mov.l .Lwait0, r1
+ bsrf r1
+ add #MUTEX, r5
+.Lwait0b:
+ bra 2b
+ nop
+
+4:
+ mov r8, r4
+ mov.l .Lwake0, r1
+ bsrf r1
+ add #MUTEX, r4
+.Lwake0b:
+ bra 5b
+ nop
+
+6:
+ mov r6, r9
+ mov r8, r4
+ mov.l .Lwake1, r1
+ bsrf r1
+ add #MUTEX, r4
+.Lwake1b:
+ bra 7b
+ mov r9, r6
+
+9:
+ mov r6, r9
+ mov r8, r4
+ mov.l .Lwake2, r1
+ bsrf r1
+ add #MUTEX, r4
+.Lwake2b:
+ bra 10b
+ mov r9, r6
+
+ .align 2
+.Lall:
+ .long 0x7fffffff
+.Lwait0:
+ .long __lll_mutex_lock_wait-.Lwait0b
+.Lwake0:
+ .long __lll_mutex_unlock_wake-.Lwake0b
+.Lwake1:
+ .long __lll_mutex_unlock_wake-.Lwake1b
+.Lwake2:
+ .long __lll_mutex_unlock_wake-.Lwake2b
+ .size pthread_barrier_wait,.-pthread_barrier_wait
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_cond_broadcast.S b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_cond_broadcast.S
new file mode 100644
index 000000000..6bd6e60ec
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_cond_broadcast.S
@@ -0,0 +1,213 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <lowlevelcond.h>
+#include <kernel-features.h>
+#include "lowlevel-atomic.h"
+
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+#define FUTEX_REQUEUE 3
+#define FUTEX_CMP_REQUEUE 4
+
+#define EINVAL 22
+
+ .text
+
+ /* int pthread_cond_broadcast (pthread_cond_t *cond) */
+ .globl __pthread_cond_broadcast
+ .type __pthread_cond_broadcast, @function
+ .align 5
+__pthread_cond_broadcast:
+ mov.l r10, @-r15
+ mov.l r9, @-r15
+ mov.l r8, @-r15
+ sts.l pr, @-r15
+ mov r4, r8
+
+ /* Get internal lock. */
+ mov #0, r3
+ mov #1, r4
+#if cond_lock != 0
+ CMPXCHG (r3, @(cond_lock,r8), r4, r2)
+#else
+ CMPXCHG (r3, @r8, r4, r2)
+#endif
+ bf 1f
+2:
+ mov.l @(total_seq+4,r8),r0
+ mov.l @(total_seq,r8),r1
+ mov.l @(wakeup_seq+4,r8), r2
+ cmp/hi r2, r0
+ bt 3f
+ cmp/hi r0, r2
+ bt 4f
+ mov.l @(wakeup_seq,r8), r2
+ cmp/hi r2, r1
+ bf 4f
+
+3:
+ /* Cause all currently waiting threads to recognize they are
+ woken up. */
+ mov.l r1, @(wakeup_seq,r8)
+ mov.l r0, @(wakeup_seq+4,r8)
+ mov.l r1, @(woken_seq,r8)
+ mov.l r0, @(woken_seq+4,r8)
+ mov.l @(broadcast_seq,r8), r2
+ add #1, r2
+ mov.l r2, @(broadcast_seq,r8)
+ add r1, r1
+ mov r1, r10
+ mov.l r10, @(cond_futex,r8)
+
+ /* Get the address of the mutex used. */
+ mov.l @(dep_mutex,r8), r9
+
+ /* Unlock. */
+#if cond_lock != 0
+ DEC (@(cond_lock,r8), r2)
+#else
+ DEC (@r8, r2)
+#endif
+ tst r2, r2
+ bf 7f
+
+8:
+ /* Don't use requeue for pshared condvars. */
+ mov #-1, r0
+ cmp/eq r0, r9
+ mov r8, r4
+ bt/s 9f
+ add #cond_futex, r4
+
+ /* Wake up all threads. */
+ mov #FUTEX_CMP_REQUEUE, r5
+ mov #1, r6
+ mov #-1, r7
+ shlr r7 /* r7 = 0x7fffffff */
+ mov r9, r0
+# if MUTEX_FUTEX != 0
+ add #MUTEX_FUTEX, r0
+# endif
+ mov r10, r1
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x16
+ SYSCALL_INST_PAD
+
+ /* For any kind of error, which mainly is EAGAIN, we try again
+ with WAKE. The general test also covers running on old
+ kernels. */
+ mov r0, r1
+ mov #-12, r2
+ shad r2, r1
+ not r1, r1
+ tst r1, r1
+ mov r8, r4
+ bt/s 9f
+ add #cond_futex, r4
+
+10:
+ mov #0, r0
+ lds.l @r15+, pr
+ mov.l @r15+, r8
+ mov.l @r15+, r9
+ rts
+ mov.l @r15+, r10
+
+4:
+ /* Unlock. */
+#if cond_lock != 0
+ DEC (@(cond_lock,r8), r2)
+#else
+ DEC (@r8, r2)
+#endif
+ tst r2, r2
+ bf 5f
+6:
+ mov #0, r0
+ lds.l @r15+, pr
+ mov.l @r15+, r8
+ mov.l @r15+, r9
+ rts
+ mov.l @r15+, r10
+
+1:
+ /* Initial locking failed. */
+ mov r8, r5
+#if cond_lock != 0
+ add #cond_lock, r5
+#endif
+ mov.l .Lmwait5, r1
+ bsrf r1
+ mov r2, r4
+.Lmwait5b:
+ bra 2b
+ nop
+
+5:
+ /* Unlock in loop requires wakeup. */
+ mov r8, r4
+#if cond_lock != 0
+ add #cond_lock, r4
+#endif
+ mov.l .Lmwake5, r1
+ bsrf r1
+ nop
+.Lmwake5b:
+ bra 6b
+ nop
+
+7:
+ /* Unlock in loop requires wakeup. */
+ mov r8, r4
+#if cond_lock != 0
+ add #cond_lock, r4
+#endif
+ mov.l .Lmwake6, r1
+ bsrf r1
+ nop
+.Lmwake6b:
+ bra 8b
+ nop
+
+9:
+ mov #FUTEX_WAKE, r5
+ mov #-1, r6
+ shlr r6 /* r6 = 0x7fffffff */
+ mov #0, r7
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+ bra 10b
+ nop
+
+ .align 2
+.Lmwait5:
+ .long __lll_mutex_lock_wait-.Lmwait5b
+.Lmwake5:
+ .long __lll_mutex_unlock_wake-.Lmwake5b
+.Lmwake6:
+ .long __lll_mutex_unlock_wake-.Lmwake6b
+ .size __pthread_cond_broadcast, .-__pthread_cond_broadcast
+versioned_symbol (libpthread, __pthread_cond_broadcast, pthread_cond_broadcast,
+ GLIBC_2_3_2)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_cond_signal.S b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_cond_signal.S
new file mode 100644
index 000000000..8b0196fdc
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_cond_signal.S
@@ -0,0 +1,139 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <lowlevelcond.h>
+#include <kernel-features.h>
+#include "lowlevel-atomic.h"
+
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+#define FUTEX_REQUEUE 3
+
+#define EINVAL 22
+
+ .text
+
+ /* int pthread_cond_signal (pthread_cond_t *cond) */
+ .globl __pthread_cond_signal
+ .type __pthread_cond_signal, @function
+ .align 5
+__pthread_cond_signal:
+ mov.l r8, @-r15
+ sts.l pr, @-r15
+ mov r4, r8
+
+ /* Get internal lock. */
+ mov #0, r3
+ mov #1, r4
+#if cond_lock != 0
+ CMPXCHG (r3, @(cond_lock,r8), r4, r2)
+#else
+ CMPXCHG (r3, @r8, r4, r2)
+#endif
+ bf 1f
+2:
+ mov.l @(total_seq+4,r8),r0
+ mov.l @(total_seq,r8),r1
+ mov.l @(wakeup_seq+4,r8), r2
+ cmp/hi r2, r0
+ bt 3f
+ cmp/hi r0, r2
+ bt 4f
+ mov.l @(wakeup_seq,r8), r2
+ cmp/hi r2, r1
+ bf 4f
+
+3:
+ /* Bump the wakeup number. */
+ mov #1, r2
+ mov #0, r3
+ clrt
+ mov.l @(wakeup_seq,r8),r0
+ mov.l @(wakeup_seq+4,r8),r1
+ addc r2, r0
+ addc r3, r1
+ mov.l r0,@(wakeup_seq,r8)
+ mov.l r1,@(wakeup_seq+4,r8)
+ mov.l @(cond_futex,r8),r0
+ add r2, r0
+ mov.l r0,@(cond_futex,r8)
+
+ /* Wake up one thread. */
+ mov r8, r4
+ add #cond_futex, r4
+ mov #FUTEX_WAKE, r5
+ mov #1, r6
+ mov #0, r7
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+
+4:
+ /* Unlock. */
+#if cond_lock != 0
+ DEC (@(cond_lock,r8), r2)
+#else
+ DEC (@r8, r2)
+#endif
+ tst r2, r2
+ bf 5f
+6:
+ mov #0, r0
+ lds.l @r15+, pr
+ rts
+ mov.l @r15+, r8
+
+1:
+ /* Initial locking failed. */
+ mov r8, r5
+#if cond_lock != 0
+ add #cond_lock, r5
+#endif
+ mov.l .Lmwait4, r1
+ bsrf r1
+ mov r2, r4
+.Lmwait4b:
+ bra 2b
+ nop
+
+5:
+ /* Unlock in loop requires wakeup. */
+ mov r8, r4
+#if cond_lock != 0
+ add #cond_lock, r4
+#endif
+ mov.l .Lmwake4, r1
+ bsrf r1
+ nop
+.Lmwake4b:
+ bra 6b
+ nop
+
+ .align 2
+.Lmwait4:
+ .long __lll_mutex_lock_wait-.Lmwait4b
+.Lmwake4:
+ .long __lll_mutex_unlock_wake-.Lmwake4b
+ .size __pthread_cond_signal, .-__pthread_cond_signal
+versioned_symbol (libpthread, __pthread_cond_signal, pthread_cond_signal,
+ GLIBC_2_3_2)
+
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_cond_timedwait.S b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_cond_timedwait.S
new file mode 100644
index 000000000..74206a71e
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_cond_timedwait.S
@@ -0,0 +1,770 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <lowlevelcond.h>
+#include <pthread-errnos.h>
+#include "lowlevel-atomic.h"
+
+#define SYS_gettimeofday __NR_gettimeofday
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+
+ .text
+
+/* int pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
+ const struct timespec *abstime) */
+ .globl __pthread_cond_timedwait
+ .type __pthread_cond_timedwait, @function
+ .align 5
+__pthread_cond_timedwait:
+.LSTARTCODE:
+ mov.l r8, @-r15
+.Lpush_r8:
+ mov.l r9, @-r15
+.Lpush_r9:
+ mov.l r10, @-r15
+.Lpush_r10:
+ mov.l r11, @-r15
+.Lpush_r11:
+ mov.l r12, @-r15
+.Lpush_r12:
+ mov.l r13, @-r15
+.Lpush_r13:
+ sts.l pr, @-r15
+.Lpush_pr:
+ add #-64, r15
+.Lalloc:
+ mov r4, r8
+ mov r5, r9
+ mov r6, r13
+#ifdef PIC
+ mova .Lgot0, r0
+ mov.l .Lgot0, r12
+ add r0, r12
+#endif
+
+ mov.l @(4,r13), r0
+ mov.l .L1g, r1
+ cmp/hs r1, r0
+ bf 0f
+ bra 18f
+ mov #EINVAL, r0
+0:
+ /* Get internal lock. */
+ mov #0, r3
+ mov #1, r4
+#if cond_lock != 0
+ CMPXCHG (r3, @(cond_lock,r8), r4, r2)
+#else
+ CMPXCHG (r3, @r8, r4, r2)
+#endif
+ bt 2f
+ bra 1f
+ nop
+#ifdef PIC
+ .align 2
+.Lgot0:
+ .long _GLOBAL_OFFSET_TABLE_
+#endif
+
+2:
+ /* Store the reference to the mutex. If there is already a
+ different value in there this is a bad user bug. */
+ mov.l @(dep_mutex,r8),r0
+ cmp/eq #-1, r0
+ bt 17f
+ mov.l r9, @(dep_mutex,r8)
+
+17:
+ /* Unlock the mutex. */
+ mov.l .Lmunlock1, r1
+ mov #0, r5
+ bsrf r1
+ mov r9, r4
+.Lmunlock1b:
+
+ tst r0, r0
+ bt 0f
+ bra 16f
+ nop
+0:
+ mov #1, r2
+ mov #0, r3
+
+ clrt
+ mov.l @(total_seq,r8),r0
+ mov.l @(total_seq+4,r8),r1
+ addc r2, r0
+ addc r3, r1
+ mov.l r0,@(total_seq,r8)
+ mov.l r1,@(total_seq+4,r8)
+ mov.l @(cond_futex,r8), r0
+ add r2, r0
+ mov.l r0, @(cond_futex,r8)
+ mov #(1 << clock_bits), r2
+ mov.l @(cond_nwaiters,r8), r0
+ add r2, r0
+ mov.l r0, @(cond_nwaiters,r8)
+
+ /* Get and store current wakeup_seq value. */
+ mov.l @(wakeup_seq,r8), r10
+ mov.l @(wakeup_seq+4,r8), r11
+ mov.l @(broadcast_seq,r8), r0
+ mov.l r0, @(4,r15)
+
+8:
+ /* Get current time. */
+#ifdef __NR_clock_gettime
+ /* Get the clock number. */
+ mov.l @(cond_nwaiters,r8), r4
+ mov #((1 << clock_bits) - 1), r0
+ and r0, r4
+ /* Only clocks 0 and 1 are allowed. Both are handled in the
+ kernel. */
+ mov r15, r5
+ add #16, r5
+ mov.w .L__NR_clock_gettime, r3
+ trapa #0x12
+ SYSCALL_INST_PAD
+# ifndef __ASSUME_POSIX_TIMERS
+ cmp/eq #-ENOSYS, r0
+ bt 19f
+# endif
+
+ /* Compute relative timeout. */
+ mov.l @r13, r2
+ mov.l @(4,r13), r3
+ mov.l @(16,r15), r0
+ bra 0f
+ mov.l @(20,r15), r1
+.L__NR_clock_gettime:
+ .word __NR_clock_gettime
+
+# ifndef __ASSUME_POSIX_TIMERS
+19:
+ mov r15, r4
+ add #16, r4
+ mov #0, r5
+ mov #SYS_gettimeofday, r3
+ trapa #0x12
+ SYSCALL_INST_PAD
+
+ /* Compute relative timeout. */
+ mov.l @(20,r15), r0
+ mov.w .L1k, r1
+ dmulu.l r0, r1 /* Micro seconds to nano seconds. */
+ mov.l @r13, r2
+ mov.l @(4,r13), r3
+ mov.l @(16,r15), r0
+ sts macl, r1
+#endif
+0:
+#else
+ mov r15, r4
+ add #16, r4
+ mov #0, r5
+ mov #SYS_gettimeofday, r3
+ trapa #0x12
+ SYSCALL_INST_PAD
+
+ /* Compute relative timeout. */
+ mov.l @(20,r15), r0
+ mov.w .L1k, r1
+ dmulu.l r0, r1 /* Micro seconds to nano seconds. */
+ mov.l @r13, r2
+ mov.l @(4,r13), r3
+ mov.l @(16,r15), r0
+ sts macl, r1
+#endif
+ sub r0, r2
+ clrt
+ subc r1, r3
+ bf 12f
+ mov.l .L1g, r1
+ add r1, r3
+ add #-1, r2
+12:
+ mov #-ETIMEDOUT, r1
+ mov.l r1, @(12,r15)
+ cmp/pz r2
+ bf 6f /* Time is already up. */
+
+ /* Store relative timeout. */
+ mov.l r2, @(16,r15)
+ mov.l r3, @(20,r15)
+ mov.l @(cond_futex,r8), r1
+ mov.l r1, @(8,r15)
+
+ /* Unlock. */
+#if cond_lock != 0
+ DEC (@(cond_lock,r8), r2)
+#else
+ DEC (@r8, r2)
+#endif
+ tst r2, r2
+ bt 4f
+ bra 3f
+ nop
+4:
+.LcleanupSTART:
+ mov.l .Lenable1, r1
+ bsrf r1
+ nop
+.Lenable1b:
+ mov.l r0, @r15
+
+ mov r15, r7
+ add #16, r7
+ mov #FUTEX_WAIT, r5
+ mov.l @(8,r15), r6
+ mov r8, r4
+ add #cond_futex, r4
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+ mov.l r0, @(12,r15)
+
+ mov.l .Ldisable1, r1
+ bsrf r1
+ mov.l @r15, r4
+.Ldisable1b:
+.LcleanupEND:
+
+ /* Lock. */
+ mov #0, r3
+ mov #1, r4
+#if cond_lock != 0
+ CMPXCHG (r3, @(cond_lock,r8), r4, r2)
+#else
+ CMPXCHG (r3, @r8, r4, r2)
+#endif
+ bf 5f
+6:
+ mov.l @(broadcast_seq,r8), r0
+ mov.l @(4,r15), r1
+ cmp/eq r0, r1
+ bf 23f
+
+ mov.l @(woken_seq,r8), r0
+ mov.l @(woken_seq+4,r8), r1
+
+ mov.l @(wakeup_seq,r8), r2
+ mov.l @(wakeup_seq+4,r8), r3
+
+ cmp/eq r3, r11
+ bf 7f
+ cmp/eq r2, r10
+ bt 15f
+7:
+ cmp/eq r1, r3
+ bf 9f
+ cmp/eq r0, r2
+ bf 9f
+15:
+ mov.l @(12,r15),r0
+ cmp/eq #-ETIMEDOUT, r0
+ bf 8b
+
+ mov #1, r2
+ mov #0, r3
+
+ clrt
+ mov.l @(wakeup_seq,r8),r0
+ mov.l @(wakeup_seq+4,r8),r1
+ addc r2, r0
+ addc r3, r1
+ mov.l r0,@(wakeup_seq,r8)
+ mov.l r1,@(wakeup_seq+4,r8)
+ mov.l @(cond_futex,r8),r0
+ add r2, r0
+ mov.l r0,@(cond_futex,r8)
+ mov #ETIMEDOUT, r0
+ bra 14f
+ mov.l r0, @(24,r15)
+
+23:
+ mov #0, r0
+ bra 24f
+ mov.l r0, @(24,r15)
+
+9:
+ mov #0, r0
+ mov.l r0, @(24,r15)
+14:
+ mov #1, r2
+ mov #0, r3
+
+ clrt
+ mov.l @(woken_seq,r8),r0
+ mov.l @(woken_seq+4,r8),r1
+ addc r2, r0
+ addc r3, r1
+ mov.l r0,@(woken_seq,r8)
+ mov.l r1,@(woken_seq+4,r8)
+
+24:
+ mov #(1 << clock_bits), r2
+ mov.l @(cond_nwaiters,r8),r0
+ sub r2, r0
+ mov.l r0,@(cond_nwaiters,r8)
+
+ /* Wake up a thread which wants to destroy the condvar object. */
+ mov.l @(total_seq,r8),r0
+ mov.l @(total_seq+4,r8),r1
+ and r1, r0
+ not r0, r0
+ cmp/eq #0, r0
+ bf/s 25f
+ mov #((1 << clock_bits) - 1), r1
+ not r1, r1
+ mov.l @(cond_nwaiters,r8),r0
+ tst r1, r0
+ bf 25f
+
+ mov r8, r4
+ add #cond_nwaiters, r4
+ mov #FUTEX_WAKE, r5
+ mov #1, r6
+ mov #0, r7
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+
+25:
+#if cond_lock != 0
+ DEC (@(cond_lock,r8), r2)
+#else
+ DEC (@r8, r2)
+#endif
+ tst r2, r2
+ bf 10f
+
+11:
+ mov r9, r4
+ mov.l .Lmlocki1, r1
+ bsrf r1
+ nop
+.Lmlocki1b:
+
+ /* We return the result of the mutex_lock operation if it failed. */
+ tst r0, r0
+ bf 18f
+ mov.l @(24,r15), r0
+
+18:
+ add #64, r15
+ lds.l @r15+, pr
+ mov.l @r15+, r13
+ mov.l @r15+, r12
+ mov.l @r15+, r11
+ mov.l @r15+, r10
+ mov.l @r15+, r9
+ rts
+ mov.l @r15+, r8
+
+.L1k:
+ .word 1000
+ .align 2
+.Lmunlock1:
+ .long __pthread_mutex_unlock_usercnt-.Lmunlock1b
+.Lenable1:
+ .long __pthread_enable_asynccancel-.Lenable1b
+.Ldisable1:
+ .long __pthread_disable_asynccancel-.Ldisable1b
+.Lmlocki1:
+ .long __pthread_mutex_cond_lock-.Lmlocki1b
+.L1g:
+ .long 1000000000
+
+1:
+ /* Initial locking failed. */
+ mov r8, r5
+#if cond_lock != 0
+ add #cond_lock, r5
+#endif
+ mov.l .Lmwait2, r1
+ bsrf r1
+ mov r2, r4
+.Lmwait2b:
+ bra 2b
+ nop
+
+3:
+ /* Unlock in loop requires wakeup. */
+ mov r8, r4
+#if cond_lock != 0
+ add #cond_lock, r4
+#endif
+ mov.l .Lmwake2, r1
+ bsrf r1
+ nop
+.Lmwake2b:
+ bra 4b
+ nop
+
+5:
+ /* Locking in loop failed. */
+ mov r8, r5
+#if cond_lock != 0
+ add #cond_lock, r5
+#endif
+ mov.l .Lmwait3, r1
+ bsrf r1
+ mov r2, r4
+.Lmwait3b:
+ bra 6b
+ nop
+
+10:
+ /* Unlock after loop requires wakeup. */
+ mov r8, r4
+#if cond_lock != 0
+ add #cond_lock, r4
+#endif
+ mov.l .Lmwake3, r1
+ bsrf r1
+ nop
+.Lmwake3b:
+ bra 11b
+ nop
+
+16:
+ /* The initial unlocking of the mutex failed. */
+ mov.l r0, @(24,r15)
+#if cond_lock != 0
+ DEC (@(cond_lock,r8), r2)
+#else
+ DEC (@r8, r2)
+#endif
+ tst r2, r2
+ bf 17f
+
+ mov r8, r4
+#if cond_lock != 0
+ add #cond_lock, r4
+#endif
+ mov.l .Lmwake4, r1
+ bsrf r1
+ nop
+.Lmwake4b:
+17:
+ bra 18b
+ mov.l @(24,r15), r0
+
+ .align 2
+.Lmwait2:
+ .long __lll_mutex_lock_wait-.Lmwait2b
+.Lmwake2:
+ .long __lll_mutex_unlock_wake-.Lmwake2b
+.Lmwait3:
+ .long __lll_mutex_lock_wait-.Lmwait3b
+.Lmwake3:
+ .long __lll_mutex_unlock_wake-.Lmwake3b
+.Lmwake4:
+ .long __lll_mutex_unlock_wake-.Lmwake4b
+ .size __pthread_cond_timedwait, .-__pthread_cond_timedwait
+versioned_symbol (libpthread, __pthread_cond_timedwait, pthread_cond_timedwait,
+ GLIBC_2_3_2)
+
+
+ .type __condvar_tw_cleanup, @function
+__condvar_tw_cleanup:
+ mov r4, r11
+
+ /* Get internal lock. */
+ mov #0, r3
+ mov #1, r4
+#if cond_lock != 0
+ CMPXCHG (r3, @(cond_lock,r8), r4, r2)
+#else
+ CMPXCHG (r3, @r8, r4, r2)
+#endif
+ bt 1f
+ nop
+
+ mov r8, r5
+#if cond_lock != 0
+ add #cond_lock, r5
+#endif
+ mov.l .Lmwait5, r1
+ bsrf r1
+ mov r2, r4
+.Lmwait5b:
+
+1:
+ mov.l @(broadcast_seq,r8), r0
+ mov.l @(4,r15), r1
+ cmp/eq r0, r1
+ bf 3f
+
+ mov #1, r2
+ mov #0, r3
+
+ clrt
+ mov.l @(wakeup_seq,r8),r0
+ mov.l @(wakeup_seq+4,r8),r1
+ addc r2, r0
+ addc r3, r1
+ mov.l r0,@(wakeup_seq,r8)
+ mov.l r1,@(wakeup_seq+4,r8)
+ mov.l @(cond_futex,r8),r0
+ add r2, r0
+ mov.l r0,@(cond_futex,r8)
+
+ clrt
+ mov.l @(woken_seq,r8),r0
+ mov.l @(woken_seq+4,r8),r1
+ addc r2, r0
+ addc r3, r1
+ mov.l r0,@(woken_seq,r8)
+ mov.l r1,@(woken_seq+4,r8)
+
+3:
+ mov #(1 << clock_bits), r2
+ mov.l @(cond_nwaiters,r8),r0
+ sub r2, r0
+ mov.l r0,@(cond_nwaiters,r8)
+
+ /* Wake up a thread which wants to destroy the condvar object. */
+ mov #0, r10
+ mov.l @(total_seq,r8),r0
+ mov.l @(total_seq+4,r8),r1
+ and r1, r0
+ not r0, r0
+ cmp/eq #0, r0
+ bf/s 4f
+ mov #((1 << clock_bits) - 1), r1
+ not r1, r1
+ mov.l @(cond_nwaiters,r8),r0
+ tst r1, r0
+ bf 4f
+
+ mov r8, r4
+ add #cond_nwaiters, r4
+ mov #FUTEX_WAKE, r5
+ mov #1, r6
+ mov #0, r7
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+ mov #1, r10
+
+4:
+#if cond_lock != 0
+ DEC (@(cond_lock,r8), r2)
+#else
+ DEC (@r8, r2)
+#endif
+ tst r2, r2
+ bt 2f
+
+ mov r8, r4
+#if cond_lock != 0
+ add #cond_lock, r4
+#endif
+ mov.l .Lmwake5, r1
+ bsrf r1
+ nop
+.Lmwake5b:
+
+2:
+ /* Wake up all waiters to make sure no signal gets lost. */
+ tst r10, r10
+ bf/s 5f
+ mov r8, r4
+ add #cond_futex, r4
+ mov #FUTEX_WAKE, r5
+ mov #-1, r6
+ shlr r6 /* r6 = 0x7fffffff */
+ mov #0, r7
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+
+5:
+ mov.l .Lmlocki5, r1
+ bsrf r1
+ mov r9, r4
+.Lmlocki5b:
+
+.LcallUR:
+ mov.l .Lresume, r1
+#ifdef PIC
+ add r12, r1
+#endif
+ jsr @r1
+ mov r11, r4
+ sleep
+
+ .align 2
+.Lmwait5:
+ .long __lll_mutex_lock_wait-.Lmwait5b
+.Lmwake5:
+ .long __lll_mutex_unlock_wake-.Lmwake5b
+.Lmlocki5:
+ .long __pthread_mutex_cond_lock-.Lmlocki5b
+.Lresume:
+#ifdef PIC
+ .long _Unwind_Resume@GOTOFF
+#else
+ .long _Unwind_Resume
+#endif
+.LENDCODE:
+ .size __condvar_tw_cleanup, .-__condvar_tw_cleanup
+
+
+ .section .gcc_except_table,"a",@progbits
+.LexceptSTART:
+ .byte 0xff ! @LPStart format (omit)
+ .byte 0xff ! @TType format (omit)
+ .byte 0x0b ! call-site format
+ ! DW_EH_PE_sdata4
+ .uleb128 .Lcstend-.Lcstbegin
+.Lcstbegin:
+ .ualong .LcleanupSTART-.LSTARTCODE
+ .ualong .LcleanupEND-.LcleanupSTART
+ .ualong __condvar_tw_cleanup-.LSTARTCODE
+ .uleb128 0
+ .ualong .LcallUR-.LSTARTCODE
+ .ualong .LENDCODE-.LcallUR
+ .ualong 0
+ .uleb128 0
+.Lcstend:
+
+ .section .eh_frame,"a",@progbits
+.LSTARTFRAME:
+ .ualong .LENDCIE-.LSTARTCIE ! Length of the CIE.
+.LSTARTCIE:
+ .ualong 0 ! CIE ID.
+ .byte 1 ! Version number.
+#ifdef SHARED
+ .string "zPLR" ! NUL-terminated augmentation
+ ! string.
+#else
+ .string "zPL" ! NUL-terminated augmentation
+ ! string.
+#endif
+ .uleb128 1 ! Code alignment factor.
+ .sleb128 -4 ! Data alignment factor.
+ .byte 0x11 ! Return address register
+ ! column.
+#ifdef SHARED
+ .uleb128 7 ! Augmentation value length.
+ .byte 0x9b ! Personality: DW_EH_PE_pcrel
+ ! + DW_EH_PE_sdata4
+ ! + DW_EH_PE_indirect
+ .ualong DW.ref.__gcc_personality_v0-.
+ .byte 0x1b ! LSDA Encoding: DW_EH_PE_pcrel
+ ! + DW_EH_PE_sdata4.
+ .byte 0x1b ! FDE Encoding: DW_EH_PE_pcrel
+ ! + DW_EH_PE_sdata4.
+#else
+ .uleb128 6 ! Augmentation value length.
+ .byte 0x0 ! Personality: absolute
+ .ualong __gcc_personality_v0
+ .byte 0x0 ! LSDA Encoding: absolute
+#endif
+ .byte 0x0c ! DW_CFA_def_cfa
+ .uleb128 0xf
+ .uleb128 0
+ .align 2
+.LENDCIE:
+
+ .ualong .LENDFDE-.LSTARTFDE ! Length of the FDE.
+.LSTARTFDE:
+ .ualong .LSTARTFDE-.LSTARTFRAME ! CIE pointer.
+#ifdef SHARED
+ .ualong .LSTARTCODE-. ! PC-relative start address
+ ! of the code.
+#else
+ .ualong .LSTARTCODE ! Start address of the code.
+#endif
+ .ualong .LENDCODE-.LSTARTCODE ! Length of the code.
+ .uleb128 4 ! Augmentation size
+#ifdef SHARED
+ .ualong .LexceptSTART-.
+#else
+ .ualong .LexceptSTART
+#endif
+ .byte 0x4
+ .ualong .Lpush_r8-.LSTARTCODE
+ .byte 0xe
+ .uleb128 4
+ .byte 0x88
+ .uleb128 1
+ .byte 0x4
+ .ualong .Lpush_r9-.Lpush_r8
+ .byte 0xe
+ .uleb128 8
+ .byte 0x89
+ .uleb128 2
+ .byte 0x4
+ .ualong .Lpush_r10-.Lpush_r9
+ .byte 0xe
+ .uleb128 12
+ .byte 0x8a
+ .uleb128 3
+ .byte 0x4
+ .ualong .Lpush_r11-.Lpush_r10
+ .byte 0xe
+ .uleb128 16
+ .byte 0x8b
+ .uleb128 4
+ .byte 0x4
+ .ualong .Lpush_r12-.Lpush_r11
+ .byte 0xe
+ .uleb128 20
+ .byte 0x8c
+ .uleb128 5
+ .byte 0x4
+ .ualong .Lpush_r13-.Lpush_r12
+ .byte 0xe
+ .uleb128 24
+ .byte 0x8d
+ .uleb128 6
+ .byte 0x4
+ .ualong .Lpush_pr-.Lpush_r13
+ .byte 0xe
+ .uleb128 28
+ .byte 0x91
+ .uleb128 7
+ .byte 0x4
+ .ualong .Lalloc-.Lpush_pr
+ .byte 0xe
+ .uleb128 92
+ .align 2
+.LENDFDE:
+
+#ifdef SHARED
+ .hidden DW.ref.__gcc_personality_v0
+ .weak DW.ref.__gcc_personality_v0
+ .section .gnu.linkonce.d.DW.ref.__gcc_personality_v0,"aw",@progbits
+ .align 4
+ .type DW.ref.__gcc_personality_v0, @object
+ .size DW.ref.__gcc_personality_v0, 4
+DW.ref.__gcc_personality_v0:
+ .long __gcc_personality_v0
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_cond_wait.S b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_cond_wait.S
new file mode 100644
index 000000000..2d6b68566
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_cond_wait.S
@@ -0,0 +1,628 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <lowlevelcond.h>
+#include "lowlevel-atomic.h"
+
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+
+ .text
+
+/* int pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex) */
+ .globl __pthread_cond_wait
+ .type __pthread_cond_wait, @function
+ .align 5
+__pthread_cond_wait:
+.LSTARTCODE:
+ mov.l r8, @-r15
+.Lpush_r8:
+ mov.l r9, @-r15
+.Lpush_r9:
+ mov.l r10, @-r15
+.Lpush_r10:
+ mov.l r11, @-r15
+.Lpush_r11:
+ mov.l r12, @-r15
+.Lpush_r12:
+ sts.l pr, @-r15
+.Lpush_pr:
+ add #-48, r15
+.Lalloc:
+ mov r4, r8
+ mov r5, r9
+#ifdef PIC
+ mova .Lgot0, r0
+ mov.l .Lgot0, r12
+ add r0, r12
+#endif
+
+ /* Get internal lock. */
+ mov #0, r3
+ mov #1, r4
+#if cond_lock != 0
+ CMPXCHG (r3, @(cond_lock,r8), r4, r2)
+#else
+ CMPXCHG (r3, @r8, r4, r2)
+#endif
+ bt 2f
+ bra 1f
+ nop
+#ifdef PIC
+ .align 2
+.Lgot0:
+ .long _GLOBAL_OFFSET_TABLE_
+#endif
+
+2:
+ /* Store the reference to the mutex. If there is already a
+ different value in there this is a bad user bug. */
+ mov.l @(dep_mutex,r8),r0
+ cmp/eq #-1, r0
+ bt 15f
+ mov.l r9, @(dep_mutex,r8)
+
+15:
+ /* Unlock the mutex. */
+ mov.l .Lmunlock0, r1
+ mov #0, r5
+ bsrf r1
+ mov r9, r4
+.Lmunlock0b:
+
+ tst r0, r0
+ bt 0f
+ bra 12f
+ nop
+0:
+ mov #1, r2
+ mov #0, r3
+
+ clrt
+ mov.l @(total_seq,r8),r0
+ mov.l @(total_seq+4,r8),r1
+ addc r2, r0
+ addc r3, r1
+ mov.l r0,@(total_seq,r8)
+ mov.l r1,@(total_seq+4,r8)
+ mov.l @(cond_futex,r8),r0
+ add r2, r0
+ mov.l r0,@(cond_futex,r8)
+ mov #(1 << clock_bits), r2
+ mov.l @(cond_nwaiters,r8), r0
+ add r2, r0
+ mov.l r0, @(cond_nwaiters,r8)
+
+ /* Get and store current wakeup_seq value. */
+ mov.l @(wakeup_seq,r8), r10
+ mov.l @(wakeup_seq+4,r8), r11
+ mov.l @(broadcast_seq,r8), r0
+ mov.l r0, @(4,r15)
+
+8:
+ mov.l @(cond_futex,r8),r0
+ mov.l r0, @(8,r15)
+
+ /* Unlock. */
+#if cond_lock != 0
+ DEC (@(cond_lock,r8), r2)
+#else
+ DEC (@r8, r2)
+#endif
+ tst r2, r2
+ bf 3f
+4:
+.LcleanupSTART:
+ mov.l .Lenable0, r1
+ bsrf r1
+ nop
+.Lenable0b:
+ mov.l r0, @r15
+
+ mov #0, r7
+ mov #FUTEX_WAIT, r5
+ mov.l @(8,r15), r6
+ mov r8, r4
+ add #cond_futex, r4
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+
+ mov.l .Ldisable0, r1
+ bsrf r1
+ mov.l @r15, r4
+.Ldisable0b:
+.LcleanupEND:
+
+ /* Lock. */
+ mov #0, r3
+ mov #1, r4
+#if cond_lock != 0
+ CMPXCHG (r3, @(cond_lock,r8), r4, r2)
+#else
+ CMPXCHG (r3, @r8, r4, r2)
+#endif
+ bf 5f
+6:
+ mov.l @(broadcast_seq,r8), r0
+ mov.l @(4,r15), r1
+ cmp/eq r0, r1
+ bf 16f
+
+ mov.l @(woken_seq,r8), r0
+ mov.l @(woken_seq+4,r8), r1
+
+ mov.l @(wakeup_seq,r8), r2
+ mov.l @(wakeup_seq+4,r8), r3
+
+ cmp/eq r3, r11
+ bf 7f
+ cmp/eq r2, r10
+ bt 8b
+7:
+ cmp/eq r1, r3
+ bf 9f
+ cmp/eq r0, r2
+ bt 8b
+9:
+ mov #1, r2
+ mov #0, r3
+
+ clrt
+ mov.l @(woken_seq,r8),r0
+ mov.l @(woken_seq+4,r8),r1
+ addc r2, r0
+ addc r3, r1
+ mov.l r0,@(woken_seq,r8)
+ mov.l r1,@(woken_seq+4,r8)
+
+16:
+ mov #(1 << clock_bits), r2
+ mov.l @(cond_nwaiters,r8),r0
+ sub r2, r0
+ mov.l r0,@(cond_nwaiters,r8)
+
+ /* Wake up a thread which wants to destroy the condvar object. */
+ mov.l @(total_seq,r8),r0
+ mov.l @(total_seq+4,r8),r1
+ and r1, r0
+ not r0, r0
+ cmp/eq #0, r0
+ bf/s 17f
+ mov #((1 << clock_bits) - 1), r1
+ not r1, r1
+ mov.l @(cond_nwaiters,r8),r0
+ tst r1, r0
+ bf 17f
+
+ mov r8, r4
+ add #cond_nwaiters, r4
+ mov #FUTEX_WAKE, r5
+ mov #1, r6
+ mov #0, r7
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+
+17:
+#if cond_lock != 0
+ DEC (@(cond_lock,r8), r2)
+#else
+ DEC (@r8, r2)
+#endif
+ tst r2, r2
+ bf 10f
+
+11:
+ mov.l .Lmlocki0, r1
+ bsrf r1
+ mov r9, r4
+.Lmlocki0b:
+ /* We return the result of the mutex_lock operation. */
+
+14:
+ add #48, r15
+ lds.l @r15+, pr
+ mov.l @r15+, r12
+ mov.l @r15+, r11
+ mov.l @r15+, r10
+ mov.l @r15+, r9
+ rts
+ mov.l @r15+, r8
+
+ .align 2
+.Lmunlock0:
+ .long __pthread_mutex_unlock_usercnt-.Lmunlock0b
+.Lenable0:
+ .long __pthread_enable_asynccancel-.Lenable0b
+.Ldisable0:
+ .long __pthread_disable_asynccancel-.Ldisable0b
+.Lmlocki0:
+ .long __pthread_mutex_cond_lock-.Lmlocki0b
+
+1:
+ /* Initial locking failed. */
+ mov r8, r5
+#if cond_lock != 0
+ add #cond_lock, r5
+#endif
+ mov.l .Lmwait0, r1
+ bsrf r1
+ mov r2, r4
+.Lmwait0b:
+ bra 2b
+ nop
+3:
+ /* Unlock in loop requires waekup. */
+ mov r8, r4
+#if cond_lock != 0
+ add #cond_lock, r4
+#endif
+ mov.l .Lmwake0, r1
+ bsrf r1
+ nop
+.Lmwake0b:
+ bra 4b
+ nop
+
+5:
+ /* Locking in loop failed. */
+ mov r8, r5
+#if cond_lock != 0
+ add #cond_lock, r5
+#endif
+ mov.l .Lmwait1, r1
+ bsrf r1
+ mov r2, r4
+.Lmwait1b:
+ bra 6b
+ nop
+
+10:
+ /* Unlock after loop requires wakeup. */
+ mov r8, r4
+#if cond_lock != 0
+ add #cond_lock, r4
+#endif
+ mov.l .Lmwake1, r1
+ bsrf r1
+ nop
+.Lmwake1b:
+ bra 11b
+ nop
+
+12:
+ /* The initial unlocking of the mutex failed. */
+ mov.l r0, @(12,r15)
+#if cond_lock != 0
+ DEC (@(cond_lock,r8), r2)
+#else
+ DEC (@r8, r2)
+#endif
+ tst r2, r2
+ bf 13f
+
+ mov r8, r4
+#if cond_lock != 0
+ add #cond_lock, r4
+#endif
+ mov.l .Lmwake2, r1
+ bsrf r1
+ nop
+.Lmwake2b:
+
+13:
+ bra 14b
+ mov.l @(12,r15), r0
+
+ .align 2
+.Lmwait0:
+ .long __lll_mutex_lock_wait-.Lmwait0b
+.Lmwake0:
+ .long __lll_mutex_unlock_wake-.Lmwake0b
+.Lmwait1:
+ .long __lll_mutex_lock_wait-.Lmwait1b
+.Lmwake1:
+ .long __lll_mutex_unlock_wake-.Lmwake1b
+.Lmwake2:
+ .long __lll_mutex_unlock_wake-.Lmwake2b
+ .size __pthread_cond_wait, .-__pthread_cond_wait
+versioned_symbol (libpthread, __pthread_cond_wait, pthread_cond_wait,
+ GLIBC_2_3_2)
+
+
+ .type __condvar_w_cleanup, @function
+__condvar_w_cleanup:
+ mov r4, r11
+
+ /* Get internal lock. */
+ mov #0, r3
+ mov #1, r4
+#if cond_lock != 0
+ CMPXCHG (r3, @(cond_lock,r8), r4, r2)
+#else
+ CMPXCHG (r3, @r8, r4, r2)
+#endif
+ bt 1f
+ nop
+
+ mov r8, r5
+#if cond_lock != 0
+ add #cond_lock, r5
+#endif
+ mov.l .Lmwait3, r1
+ bsrf r1
+ mov r2, r4
+.Lmwait3b:
+
+1:
+ mov.l @(broadcast_seq,r8), r0
+ mov.l @(4,r15), r1
+ cmp/eq r0, r1
+ bf 3f
+
+ mov #1, r2
+ mov #0, r3
+
+ clrt
+ mov.l @(wakeup_seq,r8),r0
+ mov.l @(wakeup_seq+4,r8),r1
+ addc r2, r0
+ addc r3, r1
+ mov.l r0,@(wakeup_seq,r8)
+ mov.l r1,@(wakeup_seq+4,r8)
+ mov.l @(cond_futex,r8),r0
+ add r2, r0
+ mov.l r0,@(cond_futex,r8)
+
+ clrt
+ mov.l @(woken_seq,r8),r0
+ mov.l @(woken_seq+4,r8),r1
+ addc r2, r0
+ addc r3, r1
+ mov.l r0,@(woken_seq,r8)
+ mov.l r1,@(woken_seq+4,r8)
+
+3:
+ mov #(1 << clock_bits), r2
+ mov.l @(cond_nwaiters,r8),r0
+ sub r2, r0
+ mov.l r0,@(cond_nwaiters,r8)
+
+ /* Wake up a thread which wants to destroy the condvar object. */
+ mov #0, r10
+ mov.l @(total_seq,r8),r0
+ mov.l @(total_seq+4,r8),r1
+ and r1, r0
+ not r0, r0
+ cmp/eq #0, r0
+ bf/s 4f
+ mov #((1 << clock_bits) - 1), r1
+ not r1, r1
+ mov.l @(cond_nwaiters,r8),r0
+ tst r1, r0
+ bf 4f
+
+ mov r8, r4
+ add #cond_nwaiters, r4
+ mov #FUTEX_WAKE, r5
+ mov #1, r6
+ mov #0, r7
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+ mov #1, r10
+
+4:
+#if cond_lock != 0
+ DEC (@(cond_lock,r8), r2)
+#else
+ DEC (@r8, r2)
+#endif
+ tst r2, r2
+ bt 2f
+
+ mov r8, r4
+#if cond_lock != 0
+ add #cond_lock, r4
+#endif
+ mov.l .Lmwake3, r1
+ bsrf r1
+ nop
+.Lmwake3b:
+
+2:
+ /* Wake up all waiters to make sure no signal gets lost. */
+ tst r10, r10
+ bf/s 5f
+ mov r8, r4
+ add #cond_futex, r4
+ mov #FUTEX_WAKE, r5
+ mov #-1, r6
+ shlr r6 /* r6 = 0x7fffffff */
+ mov #0, r7
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+
+5:
+ mov.l .Lmlocki3, r1
+ bsrf r1
+ mov r9, r4
+.Lmlocki3b:
+
+.LcallUR:
+ mov.l .Lresume, r1
+#ifdef PIC
+ add r12, r1
+#endif
+ jsr @r1
+ mov r11, r4
+ sleep
+
+ .align 2
+.Lmwait3:
+ .long __lll_mutex_lock_wait-.Lmwait3b
+.Lmwake3:
+ .long __lll_mutex_unlock_wake-.Lmwake3b
+.Lmlocki3:
+ .long __pthread_mutex_cond_lock-.Lmlocki3b
+.Lresume:
+#ifdef PIC
+ .long _Unwind_Resume@GOTOFF
+#else
+ .long _Unwind_Resume
+#endif
+.LENDCODE:
+ .size __condvar_w_cleanup, .-__condvar_w_cleanup
+
+
+ .section .gcc_except_table,"a",@progbits
+.LexceptSTART:
+ .byte 0xff ! @LPStart format (omit)
+ .byte 0xff ! @TType format (omit)
+ .byte 0x0b ! call-site format
+ ! DW_EH_PE_sdata4
+ .uleb128 .Lcstend-.Lcstbegin
+.Lcstbegin:
+ .ualong .LcleanupSTART-.LSTARTCODE
+ .ualong .LcleanupEND-.LcleanupSTART
+ .ualong __condvar_w_cleanup-.LSTARTCODE
+ .uleb128 0
+ .ualong .LcallUR-.LSTARTCODE
+ .ualong .LENDCODE-.LcallUR
+ .ualong 0
+ .uleb128 0
+.Lcstend:
+
+ .section .eh_frame,"a",@progbits
+.LSTARTFRAME:
+ .ualong .LENDCIE-.LSTARTCIE ! Length of the CIE.
+.LSTARTCIE:
+ .ualong 0 ! CIE ID.
+ .byte 1 ! Version number.
+#ifdef SHARED
+ .string "zPLR" ! NUL-terminated augmentation
+ ! string.
+#else
+ .string "zPL" ! NUL-terminated augmentation
+ ! string.
+#endif
+ .uleb128 1 ! Code alignment factor.
+ .sleb128 -4 ! Data alignment factor.
+ .byte 0x11 ! Return address register
+ ! column.
+#ifdef SHARED
+ .uleb128 7 ! Augmentation value length.
+ .byte 0x9b ! Personality: DW_EH_PE_pcrel
+ ! + DW_EH_PE_sdata4
+ ! + DW_EH_PE_indirect
+ .ualong DW.ref.__gcc_personality_v0-.
+ .byte 0x1b ! LSDA Encoding: DW_EH_PE_pcrel
+ ! + DW_EH_PE_sdata4.
+ .byte 0x1b ! FDE Encoding: DW_EH_PE_pcrel
+ ! + DW_EH_PE_sdata4.
+#else
+ .uleb128 6 ! Augmentation value length.
+ .byte 0x0 ! Personality: absolute
+ .ualong __gcc_personality_v0
+ .byte 0x0 ! LSDA Encoding: absolute
+#endif
+ .byte 0x0c ! DW_CFA_def_cfa
+ .uleb128 0xf
+ .uleb128 0
+ .align 2
+.LENDCIE:
+
+ .ualong .LENDFDE-.LSTARTFDE ! Length of the FDE.
+.LSTARTFDE:
+ .ualong .LSTARTFDE-.LSTARTFRAME ! CIE pointer.
+#ifdef SHARED
+ .ualong .LSTARTCODE-. ! PC-relative start address
+ ! of the code.
+#else
+ .ualong .LSTARTCODE ! Start address of the code.
+#endif
+ .ualong .LENDCODE-.LSTARTCODE ! Length of the code.
+ .uleb128 4 ! Augmentation size
+#ifdef SHARED
+ .ualong .LexceptSTART-.
+#else
+ .ualong .LexceptSTART
+#endif
+ .byte 0x4
+ .ualong .Lpush_r8-.LSTARTCODE
+ .byte 0xe
+ .uleb128 4
+ .byte 0x88
+ .uleb128 1
+ .byte 0x4
+ .ualong .Lpush_r9-.Lpush_r8
+ .byte 0xe
+ .uleb128 8
+ .byte 0x89
+ .uleb128 2
+ .byte 0x4
+ .ualong .Lpush_r10-.Lpush_r9
+ .byte 0xe
+ .uleb128 12
+ .byte 0x8a
+ .uleb128 3
+ .byte 0x4
+ .ualong .Lpush_r11-.Lpush_r10
+ .byte 0xe
+ .uleb128 16
+ .byte 0x8b
+ .uleb128 4
+ .byte 0x4
+ .ualong .Lpush_r12-.Lpush_r11
+ .byte 0xe
+ .uleb128 20
+ .byte 0x8c
+ .uleb128 5
+ .byte 0x4
+ .ualong .Lpush_pr-.Lpush_r12
+ .byte 0xe
+ .uleb128 24
+ .byte 0x91
+ .uleb128 6
+ .byte 0x4
+ .ualong .Lalloc-.Lpush_pr
+ .byte 0xe
+ .uleb128 72
+ .align 2
+.LENDFDE:
+
+#ifdef SHARED
+ .hidden DW.ref.__gcc_personality_v0
+ .weak DW.ref.__gcc_personality_v0
+ .section .gnu.linkonce.d.DW.ref.__gcc_personality_v0,"aw",@progbits
+ .align 4
+ .type DW.ref.__gcc_personality_v0, @object
+ .size DW.ref.__gcc_personality_v0, 4
+DW.ref.__gcc_personality_v0:
+ .long __gcc_personality_v0
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_once.S b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_once.S
new file mode 100644
index 000000000..02af56b4c
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_once.S
@@ -0,0 +1,246 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <unwindbuf.h>
+#include <sysdep.h>
+#include "lowlevel-atomic.h"
+
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+ .comm __fork_generation, 4, 4
+
+ .text
+ .globl __pthread_once
+ .type __pthread_once,@function
+ .align 5
+ cfi_startproc
+__pthread_once:
+ mov.l @r4, r0
+ tst #2, r0
+ bt 1f
+ rts
+ mov #0, r0
+
+1:
+ mov.l r12, @-r15
+ cfi_adjust_cfa_offset (4)
+ cfi_rel_offset (r12, 0)
+ mov.l r9, @-r15
+ cfi_adjust_cfa_offset (4)
+ cfi_rel_offset (r9, 0)
+ mov.l r8, @-r15
+ cfi_adjust_cfa_offset (4)
+ cfi_rel_offset (r8, 0)
+ sts.l pr, @-r15
+ cfi_adjust_cfa_offset (4)
+ cfi_rel_offset (pr, 0)
+ mov r5, r8
+ mov r4, r9
+
+ /* Not yet initialized or initialization in progress.
+ Get the fork generation counter now. */
+6:
+ mov.l @r4, r1
+ mova .Lgot, r0
+ mov.l .Lgot, r12
+ add r0, r12
+
+5:
+ mov r1, r0
+
+ tst #2, r0
+ bf 4f
+
+ and #3, r0
+ mov.l .Lfgen, r2
+#ifdef PIC
+ add r12, r2
+#endif
+ mov.l @r2, r3
+ or r3, r0
+ or #1, r0
+ mov r0, r3
+ mov r1, r5
+
+ CMPXCHG (r5, @r4, r3, r2)
+ bf 5b
+
+ /* Check whether another thread already runs the initializer. */
+ mov r2, r0
+ tst #1, r0
+ bt 3f /* No -> do it. */
+
+ /* Check whether the initializer execution was interrupted
+ by a fork. */
+ xor r3, r0
+ mov #-4, r1 /* -4 = 0xfffffffc */
+ tst r1, r0
+ bf 3f /* Different for generation -> run initializer. */
+
+ /* Somebody else got here first. Wait. */
+ mov #FUTEX_WAIT, r5
+ mov r3, r6
+ mov #0, r7
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+ bra 6b
+ nop
+
+ .align 2
+.Lgot:
+ .long _GLOBAL_OFFSET_TABLE_
+#ifdef PIC
+.Lfgen:
+ .long __fork_generation@GOTOFF
+#else
+.Lfgen:
+ .long __fork_generation
+#endif
+
+3:
+ /* Call the initializer function after setting up the
+ 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. */
+ add #-UNWINDBUFSIZE, r15
+ cfi_adjust_cfa_offset (UNWINDBUFSIZE)
+
+ mov.l .Lsigsetjmp, r1
+ mov #UWJMPBUF, r4
+ add r15, r4
+ bsrf r1
+ mov #0, r5
+.Lsigsetjmp0:
+ tst r0, r0
+ bf 7f
+
+ mov.l .Lcpush, r1
+ bsrf r1
+ mov r15, r4
+.Lcpush0:
+
+ /* Call the user-provided initialization function. */
+ jsr @r8
+ nop
+
+ /* Pop the cleanup handler. */
+ mov.l .Lcpop, r1
+ bsrf r1
+ mov r15, r4
+.Lcpop0:
+
+ add #UNWINDBUFSIZE, r15
+ cfi_adjust_cfa_offset (-UNWINDBUFSIZE)
+
+ /* Sucessful run of the initializer. Signal that we are done. */
+ INC (@r9, r2)
+ /* Wake up all other threads. */
+ mov r9, r4
+ mov #FUTEX_WAKE, r5
+ mov #-1, r6
+ shlr r6 /* r6 = 0x7fffffff */
+ mov #0, r7
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+
+4:
+ lds.l @r15+, pr
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (pr)
+ mov.l @r15+, r8
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (r8)
+ mov.l @r15+, r9
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (r9)
+ mov.l @r15+, r12
+ cfi_adjust_cfa_offset (-4)
+ cfi_restore (r12)
+ rts
+ mov #0, r0
+
+7:
+ /* __sigsetjmp returned for the second time. */
+ cfi_adjust_cfa_offset (UNWINDBUFSIZE+16)
+ cfi_offset (r12, -4)
+ cfi_offset (r9, -8)
+ cfi_offset (r8, -12)
+ cfi_offset (pr, -16)
+ mov #0, r7
+ mov.l r7, @r9
+ mov r9, r4
+ mov #FUTEX_WAKE, r5
+ mov #-1, r6
+ shlr r6 /* r6 = 0x7fffffff */
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+
+ mov.l .Lunext, r1
+ bsrf r1
+ mov r15, r4
+.Lunext0:
+ /* NOTREACHED */
+ sleep
+ cfi_endproc
+
+ .align 2
+.Lsigsetjmp:
+ .long __sigsetjmp@PLT-(.Lsigsetjmp0-.)
+.Lcpush:
+ .long HIDDEN_JUMPTARGET(__pthread_register_cancel)-.Lcpush0
+.Lcpop:
+ .long HIDDEN_JUMPTARGET(__pthread_unregister_cancel)-.Lcpop0
+.Lunext:
+ .long HIDDEN_JUMPTARGET(__pthread_unwind_next)-.Lunext0
+ .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 5
+clear_once_control:
+ mov #0, r0
+ mov.l r0, @r4
+
+ mov #FUTEX_WAKE, r5
+ mov #-1, r6
+ shlr r6 /* r6 = 0x7fffffff */
+ mov #0, r7
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+
+ rts
+ nop
+ .size clear_once_control,.-clear_once_control
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_rdlock.S b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_rdlock.S
new file mode 100644
index 000000000..f64c7217c
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_rdlock.S
@@ -0,0 +1,221 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#include <lowlevelrwlock.h>
+#include <pthread-errnos.h>
+#include <tcb-offsets.h>
+#include "lowlevel-atomic.h"
+
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+
+ .text
+
+ .globl __pthread_rwlock_rdlock
+ .type __pthread_rwlock_rdlock,@function
+ .align 5
+__pthread_rwlock_rdlock:
+ mov.l r12, @-r15
+ mov.l r9, @-r15
+ mov.l r8, @-r15
+ sts.l pr, @-r15
+ mov r4, r8
+
+ /* Get the lock. */
+ mov #0, r3
+ mov #1, r4
+#if MUTEX == 0
+ CMPXCHG (r3, @r8, r4, r2)
+#else
+ CMPXCHG (r3, @(MUTEX,r8), r4, r2)
+#endif
+ bf 1f
+2:
+ mov.l @(WRITER,r8), r0
+ tst r0, r0
+ bf 14f
+ mov.l @(WRITERS_QUEUED,r8), r0
+ tst r0, r0
+ bt 5f
+ mov.l @(FLAGS,r8), r0
+ tst r0, r0
+ bt 5f
+3:
+ mov.l @(READERS_QUEUED,r8), r0
+ add #1, r0
+ mov.l r0, @(READERS_QUEUED,r8)
+ tst r0, r0
+ bt 4f
+
+ mov.l @(READERS_WAKEUP,r8), r9
+
+#if MUTEX == 0
+ DEC (@r8, r2)
+#else
+ DEC (@(MUTEX,r8), r2)
+#endif
+ tst r2, r2
+ bf 10f
+11:
+ mov r8, r4
+ add #READERS_WAKEUP, r4
+ mov #FUTEX_WAIT, r5
+ mov r9, r6
+ mov #0, r7
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+
+ /* Reget the lock. */
+ mov #0, r3
+ mov #1, r4
+#if MUTEX == 0
+ CMPXCHG (r3, @r8, r4, r2)
+#else
+ CMPXCHG (r3, @(MUTEX,r8), r4, r2)
+#endif
+ bf 12f
+13:
+ mov.l @(READERS_QUEUED,r8), r0
+ add #-1, r0
+ bra 2b
+ mov.l r0, @(READERS_QUEUED,r8)
+
+5:
+ mov #0, r3
+ mov.l @(NR_READERS,r8), r0
+ add #1, r0
+ mov.l r0, @(NR_READERS,r8)
+ tst r0, r0
+ bt 8f
+
+9:
+#if MUTEX == 0
+ DEC (@r8, r2)
+#else
+ DEC (@(MUTEX,r8), r2)
+#endif
+ tst r2, r2
+ bf 6f
+7:
+ lds.l @r15+, pr
+ mov.l @r15+, r8
+ mov.l @r15+, r9
+ mov.l @r15+, r12
+ rts
+ mov r3, r0
+
+1:
+ mov r8, r5
+#if MUTEX != 0
+ add #MUTEX, r5
+#endif
+ mov r2, r4
+ mov.l .Lwait0, r1
+ bsrf r1
+ nop
+.Lwait0b:
+ bra 2b
+ nop
+14:
+ stc gbr, r1
+ mov.w .Ltidoff, r2
+ add r2, r1
+ mov.l @r1, r1
+ cmp/eq r1, r0
+ bf 3b
+ /* Deadlock detected. */
+ bra 9b
+ mov #EDEADLK, r3
+
+.Ltidoff:
+ .word TID - TLS_PRE_TCB_SIZE
+
+6:
+ mov r8, r4
+#if MUTEX != 0
+ add #MUTEX, r4
+#endif
+ mov.l .Lwake0, r1
+ bsrf r1
+ nop
+.Lwake0b:
+ bra 7b
+ mov #0, r3
+
+8:
+ /* Overflow. */
+ mov.l @(NR_READERS,r8), r1
+ add #-1, r1
+ mov.l r1, @(NR_READERS,r8)
+ bra 9b
+ mov #EAGAIN, r3
+
+4:
+ /* Overflow. */
+ mov.l @(READERS_QUEUED,r8), r1
+ add #-1, r1
+ mov.l r1, @(READERS_QUEUED,r8)
+ bra 9b
+ mov #EAGAIN, r3
+
+10:
+ mov r8, r4
+#if MUTEX != 0
+ add #MUTEX, r4
+#endif
+ mov.l .Lwake1, r1
+ bsrf r1
+ nop
+.Lwake1b:
+ bra 11b
+ nop
+
+12:
+ mov r8, r5
+#if MUTEX != 0
+ add #MUTEX, r5
+#endif
+ mov r2, r4
+ mov.l .Lwait1, r1
+ bsrf r1
+ nop
+.Lwait1b:
+ bra 13b
+ nop
+
+ .align 2
+.Lwait0:
+ .long __lll_mutex_lock_wait-.Lwait0b
+.Lwake0:
+ .long __lll_mutex_unlock_wake-.Lwake0b
+.Lwait1:
+ .long __lll_mutex_lock_wait-.Lwait1b
+.Lwake1:
+ .long __lll_mutex_unlock_wake-.Lwake1b
+ .size __pthread_rwlock_rdlock,.-__pthread_rwlock_rdlock
+
+ .globl pthread_rwlock_rdlock
+pthread_rwlock_rdlock = __pthread_rwlock_rdlock
+
+ .globl __pthread_rwlock_rdlock_internal
+__pthread_rwlock_rdlock_internal = __pthread_rwlock_rdlock
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedrdlock.S b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedrdlock.S
new file mode 100644
index 000000000..633a14b1a
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedrdlock.S
@@ -0,0 +1,281 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#include <lowlevelrwlock.h>
+#include <pthread-errnos.h>
+#include <tcb-offsets.h>
+#include "lowlevel-atomic.h"
+
+#define SYS_gettimeofday __NR_gettimeofday
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+
+ .text
+
+ .globl pthread_rwlock_timedrdlock
+ .type pthread_rwlock_timedrdlock,@function
+ .align 5
+pthread_rwlock_timedrdlock:
+ mov.l r12, @-r15
+ mov.l r10, @-r15
+ mov.l r9, @-r15
+ mov.l r8, @-r15
+ sts.l pr, @-r15
+ add #-8, r15
+ mov r4, r8
+ mov r5, r9
+
+ /* Get the lock. */
+ mov #0, r3
+ mov #1, r4
+#if MUTEX == 0
+ CMPXCHG (r3, @r8, r4, r2)
+#else
+ CMPXCHG (r3, @(MUTEX,r8), r4, r2)
+#endif
+ bf 1f
+2:
+ mov.l @(WRITER,r8), r0
+ tst r0, r0
+ bf 14f
+ mov.l @(WRITERS_QUEUED,r8), r0
+ tst r0, r0
+ bt 5f
+ mov.l @(FLAGS,r8), r0
+ tst r0, r0
+ bt 5f
+3:
+ /* Check the value of the timeout parameter. */
+ mov.l .L1g0, r1
+ mov.l @(4,r9), r0
+ cmp/hs r1, r0
+ bt 19f
+
+ mov.l @(READERS_QUEUED,r8), r0
+ add #1, r0
+ mov.l r0, @(READERS_QUEUED,r8)
+ tst r0, r0
+ bt 4f
+
+ mov.l @(READERS_WAKEUP,r8), r10
+
+#if MUTEX == 0
+ DEC (@r8, r2)
+#else
+ DEC (@(MUTEX,r8), r2)
+#endif
+ tst r2, r2
+ bf 10f
+
+11:
+ /* Get current time. */
+ mov r15, r4
+ mov #0, r5
+ mov #SYS_gettimeofday, r3
+ trapa #0x12
+ SYSCALL_INST_PAD
+
+ mov.l @(4,r15), r0
+ mov.w .L1k0, r1
+ dmulu.l r0, r1 /* Milli seconds to nano seconds. */
+ mov.l @r9, r2
+ mov.l @(4,r9), r3
+ mov.l @r15, r0
+ sts macl, r1
+ sub r0, r2
+ clrt
+ subc r1, r3
+ bf 15f
+ mov.l .L1g0, r1
+ add r1, r3
+ add #-1, r2
+15:
+ cmp/pz r2
+ bf 16f /* Time is already up. */
+
+ /* Store relative timeout. */
+ mov.l r2, @r15
+ mov.l r3, @(4,r15)
+
+ /* Futex call. */
+ mov r15, r7
+ mov #FUTEX_WAIT, r5
+ mov r10, r6
+ mov r8, r4
+ add #READERS_WAKEUP, r4
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+ mov r0, r3
+
+17:
+ /* Reget the lock. */
+ mov #0, r5
+ mov #1, r4
+#if MUTEX == 0
+ CMPXCHG (r5, @r8, r4, r2)
+#else
+ CMPXCHG (r5, @(MUTEX,r8), r4, r2)
+#endif
+ bf 12f
+
+13:
+ mov.l @(READERS_QUEUED,r8), r0
+ add #-1, r0
+ mov.l r0, @(READERS_QUEUED,r8)
+ mov #-ETIMEDOUT, r0
+ cmp/eq r0, r3
+ bf 2b
+
+18:
+ bra 9f
+ mov #ETIMEDOUT, r3
+
+5:
+ mov #0, r3
+ mov.l @(NR_READERS,r8), r0
+ add #1, r0
+ mov.l r0, @(NR_READERS,r8)
+ tst r0, r0
+ bt 8f
+
+9:
+#if MUTEX == 0
+ DEC (@r8, r2)
+#else
+ DEC (@(MUTEX,r8), r2)
+#endif
+ tst r2, r2
+ bf 6f
+7:
+ add #8,r15
+ lds.l @r15+, pr
+ mov.l @r15+, r8
+ mov.l @r15+, r9
+ mov.l @r15+, r10
+ mov.l @r15+, r12
+ rts
+ mov r3, r0
+
+ .align 2
+.L1k0:
+ .long 1000
+.L1g0:
+ .long 1000000000
+
+1:
+ mov r8, r5
+#if MUTEX != 0
+ add #MUTEX, r5
+#endif
+ mov r2, r4
+ mov.l .Lwait2, r1
+ bsrf r1
+ nop
+.Lwait2b:
+ bra 2b
+ nop
+14:
+ stc gbr, r1
+ mov.w .Ltidoff, r2
+ add r2, r1
+ mov.l @r1, r1
+ cmp/eq r1, r0
+ bf 3b
+ /* Deadlock detected. */
+ bra 9b
+ mov #EDEADLK, r3
+
+.Ltidoff:
+ .word TID - TLS_PRE_TCB_SIZE
+
+6:
+ mov r8, r4
+#if MUTEX != 0
+ add #MUTEX, r4
+#endif
+ mov.l .Lwake2, r1
+ bsrf r1
+ nop
+.Lwake2b:
+ bra 7b
+ mov #0, r3
+
+8:
+ /* Overflow. */
+ mov.l @(NR_READERS,r8), r1
+ add #-1, r1
+ mov.l r1, @(NR_READERS,r8)
+ bra 9b
+ mov #EAGAIN, r3
+
+4:
+ /* Overflow. */
+ mov.l @(READERS_QUEUED,r8), r1
+ add #-1, r1
+ mov.l r1, @(READERS_QUEUED,r8)
+ bra 9b
+ mov #EAGAIN, r3
+
+10:
+ mov r8, r4
+#if MUTEX != 0
+ add #MUTEX, r4
+#endif
+ mov.l .Lwake3, r1
+ bsrf r1
+ nop
+.Lwake3b:
+ bra 11b
+ nop
+
+12:
+ mov r8, r5
+#if MUTEX != 0
+ add #MUTEX, r5
+#endif
+ mov r2, r4
+ mov.l .Lwait3, r1
+ bsrf r1
+ nop
+.Lwait3b:
+ bra 13b
+ nop
+
+16:
+ bra 17b
+ mov #-ETIMEDOUT, r3
+
+19:
+ bra 9b
+ mov #EINVAL, r3
+
+ .align 2
+.Lwait2:
+ .long __lll_mutex_lock_wait-.Lwait2b
+.Lwake2:
+ .long __lll_mutex_unlock_wake-.Lwake2b
+.Lwait3:
+ .long __lll_mutex_lock_wait-.Lwait3b
+.Lwake3:
+ .long __lll_mutex_unlock_wake-.Lwake3b
+ .size pthread_rwlock_timedrdlock,.-pthread_rwlock_timedrdlock
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedwrlock.S b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedwrlock.S
new file mode 100644
index 000000000..29e29b6f6
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedwrlock.S
@@ -0,0 +1,266 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#include <lowlevelrwlock.h>
+#include <pthread-errnos.h>
+#include <tcb-offsets.h>
+#include "lowlevel-atomic.h"
+
+#define SYS_gettimeofday __NR_gettimeofday
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+
+ .text
+
+ .globl pthread_rwlock_timedwrlock
+ .type pthread_rwlock_timedwrlock,@function
+ .align 5
+pthread_rwlock_timedwrlock:
+ mov.l r12, @-r15
+ mov.l r10, @-r15
+ mov.l r9, @-r15
+ mov.l r8, @-r15
+ sts.l pr, @-r15
+ add #-8, r15
+ mov r4, r8
+ mov r5, r9
+
+ /* Get the lock. */
+ mov #0, r3
+ mov #1, r4
+#if MUTEX == 0
+ CMPXCHG (r3, @r8, r4, r2)
+#else
+ CMPXCHG (r3, @(MUTEX,r8), r4, r2)
+#endif
+ bf 1f
+2:
+ mov.l @(WRITER,r8), r0
+ tst r0, r0
+ bf 14f
+ mov.l @(NR_READERS,r8), r0
+ tst r0, r0
+ bt 5f
+3:
+ /* Check the value of the timeout parameter. */
+ mov.l .L1g1, r1
+ mov.l @(4,r9), r0
+ cmp/hs r1, r0
+ bt 19f
+
+ mov.l @(WRITERS_QUEUED,r8), r0
+ add #1, r0
+ mov.l r0, @(WRITERS_QUEUED,r8)
+ tst r0, r0
+ bt 4f
+
+ mov.l @(WRITERS_WAKEUP,r8), r10
+
+#if MUTEX == 0
+ DEC (@r8, r2)
+#else
+ DEC (@(MUTEX,r8), r2)
+#endif
+ tst r2, r2
+ bf 10f
+
+11:
+ /* Get current time. */
+ mov r15, r4
+ mov #0, r5
+ mov #SYS_gettimeofday, r3
+ trapa #0x12
+ SYSCALL_INST_PAD
+
+ mov.l @(4,r15), r0
+ mov.w .L1k1, r1
+ dmulu.l r0, r1 /* Milli seconds to nano seconds. */
+ mov.l @r9, r2
+ mov.l @(4,r9), r3
+ mov.l @r15, r0
+ sts macl, r1
+ sub r0, r2
+ clrt
+ subc r1, r3
+ bf 15f
+ mov.l .L1g1, r1
+ add r1, r3
+ add #-1, r2
+15:
+ cmp/pz r2
+ bf 16f /* Time is already up. */
+
+ /* Store relative timeout. */
+ mov.l r2, @r15
+ mov.l r3, @(4,r15)
+
+ /* Futex call. */
+ mov r15, r7
+ mov #FUTEX_WAIT, r5
+ mov r10, r6
+ mov r8, r4
+ add #WRITERS_WAKEUP, r4
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+ mov r0, r3
+
+17:
+ /* Reget the lock. */
+ mov #0, r5
+ mov #1, r4
+#if MUTEX == 0
+ CMPXCHG (r5, @r8, r4, r2)
+#else
+ CMPXCHG (r5, @(MUTEX,r8), r4, r2)
+#endif
+ bf 12f
+
+13:
+ mov.l @(WRITERS_QUEUED,r8), r0
+ add #-1, r0
+ mov.l r0, @(WRITERS_QUEUED,r8)
+ mov #-ETIMEDOUT, r0
+ cmp/eq r0, r3
+ bf 2b
+
+18:
+ bra 9f
+ mov #ETIMEDOUT, r3
+
+19:
+ bra 9f
+ mov #EINVAL, r3
+
+5:
+ mov #0, r3
+ stc gbr, r0
+ mov.w .Ltidoff, r1
+ mov.l @(r0,r1), r0
+ mov.l r0, @(WRITER,r8)
+9:
+#if MUTEX == 0
+ DEC (@r8, r2)
+#else
+ DEC (@(MUTEX,r8), r2)
+#endif
+ tst r2, r2
+ bf 6f
+7:
+ add #8,r15
+ lds.l @r15+, pr
+ mov.l @r15+, r8
+ mov.l @r15+, r9
+ mov.l @r15+, r10
+ mov.l @r15+, r12
+ rts
+ mov r3, r0
+
+.L1k1:
+ .word 1000
+ .align 2
+.L1g1:
+ .long 1000000000
+
+1:
+ mov r8, r5
+#if MUTEX != 0
+ add #MUTEX, r5
+#endif
+ mov r2, r4
+ mov.l .Lwait6, r1
+ bsrf r1
+ nop
+.Lwait6b:
+ bra 2b
+ nop
+14:
+ stc gbr, r1
+ mov.w .Ltidoff, r2
+ add r2, r1
+ mov.l @r1, r1
+ cmp/eq r1, r0
+ bf 3b
+ bra 9b
+ mov #EDEADLK, r3
+6:
+ mov r8, r4
+#if MUTEX != 0
+ add #MUTEX, r4
+#endif
+ mov.l .Lwake6, r1
+ bsrf r1
+ nop
+.Lwake6b:
+ bra 7b
+ mov #0, r3
+
+.Ltidoff:
+ .word TID - TLS_PRE_TCB_SIZE
+
+4:
+ /* Overflow. */
+ mov.l @(WRITERS_QUEUED,r8), r1
+ add #-1, r1
+ mov.l r1, @(WRITERS_QUEUED,r8)
+ bra 9b
+ mov #EAGAIN, r3
+
+10:
+ mov r8, r4
+#if MUTEX != 0
+ add #MUTEX, r4
+#endif
+ mov.l .Lwake7, r1
+ bsrf r1
+ nop
+.Lwake7b:
+ bra 11b
+ nop
+
+12:
+ mov r8, r5
+#if MUTEX != 0
+ add #MUTEX, r5
+#endif
+ mov r2, r4
+ mov.l .Lwait7, r1
+ bsrf r1
+ nop
+.Lwait7b:
+ bra 13b
+ nop
+
+16:
+ bra 17b
+ mov #-ETIMEDOUT, r3
+
+ .align 2
+.Lwait6:
+ .long __lll_mutex_lock_wait-.Lwait6b
+.Lwake6:
+ .long __lll_mutex_unlock_wake-.Lwake6b
+.Lwait7:
+ .long __lll_mutex_lock_wait-.Lwait7b
+.Lwake7:
+ .long __lll_mutex_unlock_wake-.Lwake7b
+ .size pthread_rwlock_timedwrlock,.-pthread_rwlock_timedwrlock
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_unlock.S b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_unlock.S
new file mode 100644
index 000000000..172689bec
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_unlock.S
@@ -0,0 +1,170 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#include <lowlevelrwlock.h>
+#include "lowlevel-atomic.h"
+
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+
+ .text
+
+ .globl __pthread_rwlock_unlock
+ .type __pthread_rwlock_unlock,@function
+ .align 5
+__pthread_rwlock_unlock:
+ mov.l r12, @-r15
+ mov.l r8, @-r15
+ sts.l pr, @-r15
+ mov r4, r8
+
+ /* Get the lock. */
+ mov #0, r3
+ mov #1, r4
+#if MUTEX == 0
+ CMPXCHG (r3, @r8, r4, r2)
+#else
+ CMPXCHG (r3, @(MUTEX,r8), r4, r2)
+#endif
+ bf 1f
+2:
+ mov.l @(WRITER,r8), r0
+ tst r0, r0
+ bf 5f
+ mov.l @(NR_READERS,r8), r0
+ add #-1, r0
+ mov.l r0, @(NR_READERS,r8)
+ tst r0, r0
+ bf 6f
+5:
+ mov #0, r0
+ mov.l r0, @(WRITER,r8)
+ mov #1, r6
+ mov r8, r4
+ add #WRITERS_WAKEUP, r4
+ mov.l @(WRITERS_QUEUED,r8), r0
+ tst r0, r0
+ bf 0f
+
+ /* If also no readers waiting nothing to do. */
+ mov.l @(READERS_QUEUED,r8), r0
+ tst r0, r0
+ bt 6f
+
+ mov #-1, r6
+ shlr r6 /* r6 = 0x7fffffff */
+ mov r8, r4
+ add #READERS_WAKEUP, r4
+
+0:
+ mov.l @r4, r0
+ add #1, r0
+ mov.l r0, @r4
+#if MUTEX == 0
+ DEC (@r8, r2)
+#else
+ DEC (@(MUTEX,r8), r2)
+#endif
+ tst r2, r2
+ bf 7f
+
+8:
+ mov #FUTEX_WAKE, r5
+ mov #SYS_futex, r3
+ mov #0, r7
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+
+ lds.l @r15+, pr
+ mov.l @r15+, r8
+ mov.l @r15+, r12
+ rts
+ mov #0, r0
+6:
+#if MUTEX == 0
+ DEC (@r8, r2)
+#else
+ DEC (@(MUTEX,r8), r2)
+#endif
+ tst r2, r2
+ bf 3f
+4:
+ lds.l @r15+, pr
+ mov.l @r15+, r8
+ mov.l @r15+, r12
+ rts
+ mov #0, r0
+
+1:
+ mov r8, r5
+#if MUTEX != 0
+ add #MUTEX, r5
+#endif
+ mov r2, r4
+ mov.l .Lwait8, r1
+ bsrf r1
+ nop
+.Lwait8b:
+ bra 2b
+ nop
+3:
+ mov r8, r4
+#if MUTEX != 0
+ add #MUTEX, r4
+#endif
+ mov.l .Lwake8, r1
+ bsrf r1
+ nop
+.Lwake8b:
+ bra 4b
+ nop
+
+7:
+ mov.l r4, @-r15
+ mov.l r6, @-r15
+ mov r8, r4
+#if MUTEX != 0
+ add #MUTEX, r4
+#endif
+ mov.l .Lwake9, r1
+ bsrf r1
+ nop
+.Lwake9b:
+
+ mov.l @r15+, r6
+ bra 8b
+ mov.l @r15+, r4
+
+ .align 2
+.Lwait8:
+ .long __lll_mutex_lock_wait-.Lwait8b
+.Lwake8:
+ .long __lll_mutex_unlock_wake-.Lwake8b
+.Lwake9:
+ .long __lll_mutex_unlock_wake-.Lwake9b
+ .size __pthread_rwlock_unlock,.-__pthread_rwlock_unlock
+
+ .globl pthread_rwlock_unlock
+pthread_rwlock_unlock = __pthread_rwlock_unlock
+
+ .globl __pthread_rwlock_unlock_internal
+__pthread_rwlock_unlock_internal = __pthread_rwlock_unlock
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_wrlock.S b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_wrlock.S
new file mode 100644
index 000000000..995d823e8
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/pthread_rwlock_wrlock.S
@@ -0,0 +1,203 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#include <lowlevelrwlock.h>
+#include <pthread-errnos.h>
+#include <tcb-offsets.h>
+#include "lowlevel-atomic.h"
+
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+
+ .text
+
+ .globl __pthread_rwlock_wrlock
+ .type __pthread_rwlock_wrlock,@function
+ .align 5
+__pthread_rwlock_wrlock:
+ mov.l r12, @-r15
+ mov.l r9, @-r15
+ mov.l r8, @-r15
+ sts.l pr, @-r15
+ mov r4, r8
+
+ /* Get the lock. */
+ mov #0, r3
+ mov #1, r4
+#if MUTEX == 0
+ CMPXCHG (r3, @r8, r4, r2)
+#else
+ CMPXCHG (r3, @(MUTEX,r8), r4, r2)
+#endif
+ bf 1f
+2:
+ mov.l @(WRITER,r8), r0
+ tst r0, r0
+ bf 14f
+ mov.l @(NR_READERS,r8), r0
+ tst r0, r0
+ bt 5f
+3:
+ mov.l @(WRITERS_QUEUED,r8), r0
+ add #1, r0
+ mov.l r0, @(WRITERS_QUEUED,r8)
+ tst r0, r0
+ bt 4f
+
+ mov.l @(WRITERS_WAKEUP,r8), r9
+
+#if MUTEX == 0
+ DEC (@r8, r2)
+#else
+ DEC (@(MUTEX,r8), r2)
+#endif
+ tst r2, r2
+ bf 10f
+11:
+ mov r8, r4
+ add #WRITERS_WAKEUP, r4
+ mov #FUTEX_WAIT, r5
+ mov r9, r6
+ mov #0, r7
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+
+ /* Reget the lock. */
+ mov #0, r3
+ mov #1, r4
+#if MUTEX == 0
+ CMPXCHG (r3, @r8, r4, r2)
+#else
+ CMPXCHG (r3, @(MUTEX,r8), r4, r2)
+#endif
+ bf 12f
+13:
+ mov.l @(WRITERS_QUEUED,r8), r0
+ add #-1, r0
+ bra 2b
+ mov.l r0, @(WRITERS_QUEUED,r8)
+
+5:
+ mov #0, r3
+ stc gbr, r0
+ mov.w .Ltidoff, r1
+ mov.l @(r0,r1), r0
+ mov.l r0, @(WRITER,r8)
+9:
+#if MUTEX == 0
+ DEC (@r8, r2)
+#else
+ DEC (@(MUTEX,r8), r2)
+#endif
+ tst r2, r2
+ bf 6f
+7:
+ lds.l @r15+, pr
+ mov.l @r15+, r8
+ mov.l @r15+, r9
+ mov.l @r15+, r12
+ rts
+ mov r3, r0
+
+1:
+ mov r8, r5
+#if MUTEX != 0
+ add #MUTEX, r5
+#endif
+ mov r2, r4
+ mov.l .Lwait4, r1
+ bsrf r1
+ nop
+.Lwait4b:
+ bra 2b
+ nop
+14:
+ stc gbr, r1
+ mov.w .Ltidoff, r2
+ add r2, r1
+ mov.l @r1, r1
+ cmp/eq r1, r0
+ bf 3b
+ bra 9b
+ mov #EDEADLK, r3
+6:
+ mov r8, r4
+#if MUTEX != 0
+ add #MUTEX, r4
+#endif
+ mov.l .Lwake4, r1
+ bsrf r1
+ nop
+.Lwake4b:
+ bra 7b
+ mov #0, r3
+
+.Ltidoff:
+ .word TID - TLS_PRE_TCB_SIZE
+
+4:
+ mov.l @(WRITERS_QUEUED,r8), r1
+ add #-1, r1
+ mov.l r1, @(WRITERS_QUEUED,r8)
+ bra 9b
+ mov #EAGAIN, r3
+
+10:
+ mov r8, r4
+#if MUTEX != 0
+ add #MUTEX, r4
+#endif
+ mov.l .Lwake5, r1
+ bsrf r1
+ nop
+.Lwake5b:
+ bra 11b
+ nop
+
+12:
+ mov r8, r5
+#if MUTEX != 0
+ add #MUTEX, r5
+#endif
+ mov r2, r4
+ mov.l .Lwait5, r1
+ bsrf r1
+ nop
+.Lwait5b:
+ bra 13b
+ nop
+
+ .align 2
+.Lwait4:
+ .long __lll_mutex_lock_wait-.Lwait4b
+.Lwake4:
+ .long __lll_mutex_unlock_wake-.Lwake4b
+.Lwait5:
+ .long __lll_mutex_lock_wait-.Lwait5b
+.Lwake5:
+ .long __lll_mutex_unlock_wake-.Lwake5b
+ .globl pthread_rwlock_wrlock
+pthread_rwlock_wrlock = __pthread_rwlock_wrlock
+
+ .globl __pthread_rwlock_wrlock_internal
+__pthread_rwlock_wrlock_internal = __pthread_rwlock_wrlock
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/sem_post.S b/libc/nptl/sysdeps/unix/sysv/linux/sh/sem_post.S
new file mode 100644
index 000000000..9bc12da7e
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/sem_post.S
@@ -0,0 +1,87 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <pthread-errnos.h>
+#include "lowlevel-atomic.h"
+
+
+#define SYS_gettimeofday __NR_gettimeofday
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+ .text
+
+ .globl __new_sem_post
+ .type __new_sem_post,@function
+ .align 5
+__new_sem_post:
+ mov #1, r3
+ XADD (r3, @r4, r2)
+
+ mov #FUTEX_WAKE, r5
+ mov r2, r6
+ add #1, r6
+ mov #0, r7
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+
+ cmp/pz r0
+ bf 1f
+ rts
+ mov #0, r0
+
+1:
+ mov #EINVAL, r2
+ mova .Lgot3, r0
+ mov.l .Lgot3, r12
+ add r0, r12
+
+#if USE___THREAD
+ mov.l .Lerrno3, r0
+ stc gbr, r1
+ mov.l @(r0, r12), r0
+ add r1, r0
+#else
+ mov.l .Lerrloc3, r1
+ bsrf r1
+ nop
+.Lerrloc3b:
+#endif
+ mov.l r2, @r0
+ lds.l @r15+, pr
+ mov.l @r15+, r12
+ rts
+ mov #-1, r0
+
+ .align 2
+.Lgot3:
+ .long _GLOBAL_OFFSET_TABLE_
+#if USE___THREAD
+.Lerrno3:
+ .long errno@GOTTPOFF
+#else
+.Lerrloc3:
+ .long __errno_location@PLT-(.Lerrloc3b-.)
+#endif
+ .size __new_sem_post,.-__new_sem_post
+ versioned_symbol(libpthread, __new_sem_post, sem_post, GLIBC_2_1)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/sem_timedwait.S b/libc/nptl/sysdeps/unix/sysv/linux/sh/sem_timedwait.S
new file mode 100644
index 000000000..acb7d0f78
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/sem_timedwait.S
@@ -0,0 +1,241 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <pthread-errnos.h>
+#include <tcb-offsets.h>
+#include "lowlevel-atomic.h"
+
+
+#define SYS_gettimeofday __NR_gettimeofday
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+ .text
+
+ .globl sem_timedwait
+ .type sem_timedwait,@function
+ .align 5
+ cfi_startproc
+sem_timedwait:
+ /* First check for cancellation. */
+ stc gbr, r0
+ mov.w .Lchand, r1
+ mov.l @(r0,r1), r0
+ mov #0xf9, r1
+ and r1, r0
+ cmp/eq #8, r0
+ bf 0f
+ bra 10f
+ stc gbr, r0
+0:
+ mov.l @r4, r0
+2:
+ tst r0, r0
+ bt 1f
+ mov r0, r3
+ mov r0, r6
+ add #-1, r3
+ CMPXCHG (r6, @r4, r3, r2)
+ bf/s 2b
+ mov r2, r0
+ rts
+ mov #0, r0
+
+1:
+ /* Check whether the timeout value is valid. */
+ mov.l r8, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r8, 0)
+ mov.l r9, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r9, 0)
+ mov.l r10, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r10, 0)
+ mov.l r12, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r12, 0)
+ sts.l pr, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (pr, 0)
+ add #-8, r15
+ cfi_adjust_cfa_offset(8)
+ mov r4, r8
+ mov r5, r9
+
+ /* Check for invalid nanosecond field. */
+ mov.l @(4,r9), r0
+ mov.l .L1g, r1
+ cmp/hs r1, r0
+ bt/s 6f
+ mov #EINVAL, r0
+7:
+ mov.l .Lenable0, r1
+ bsrf r1
+ nop
+.Lenable0b:
+ mov r0, r10
+
+ /* Compute relative timeout. */
+ mov r15, r4
+ mov #0, r5
+ mov #SYS_gettimeofday, r3
+ trapa #0x12
+ SYSCALL_INST_PAD
+
+ mov.l @(4,r15), r0
+ mov.w .L1k, r1
+ dmulu.l r0, r1 /* Milli seconds to nano seconds. */
+ mov.l @r9, r2
+ mov.l @(4,r9), r3
+ mov.l @r15, r0
+ sts macl, r1
+ sub r0, r2
+ clrt
+ subc r1, r3
+ bf 5f
+ mov.l .L1g, r1
+ add r1, r3
+ add #-1, r2
+5:
+ cmp/pz r2
+ bf/s 6f /* Time is already up. */
+ mov #ETIMEDOUT, r0
+
+ /* Store relative timeout. */
+ mov.l r2, @r15
+ mov.l r3, @(4,r15)
+
+ /* Futex call. */
+ mov r8, r4
+ mov #FUTEX_WAIT, r5
+ mov #0, r6
+ mov r15, r7
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+
+ mov.l .Ldisable0, r1
+ mov r10, r4
+ bsrf r1
+ mov r0, r10
+.Ldisable0b:
+ mov r10, r0
+
+ tst r0, r0
+ bt 9f
+ cmp/eq #-EWOULDBLOCK, r0
+ bf 3f
+9:
+ mov.l @r8, r0
+8:
+ tst r0, r0
+ bt 7b
+
+ mov r0, r3
+ mov r0, r4
+ add #-1, r3
+ CMPXCHG (r4, @r8, r3, r2)
+ bf/s 8b
+ mov r2, r0
+
+ add #8, r15
+ lds.l @r15+, pr
+ mov.l @r15+, r12
+ mov.l @r15+, r10
+ mov.l @r15+, r9
+ mov.l @r15+, r8
+ rts
+ mov #0, r0
+
+3:
+ neg r0, r0
+6:
+ mov r0, r8
+ mova .Lgot2, r0
+ mov.l .Lgot2, r12
+ add r0, r12
+
+#if USE___THREAD
+ mov.l .Lerrno2, r0
+ stc gbr, r1
+ mov.l @(r0, r12), r0
+ add r1, r0
+ mov.l r8, @r0
+#else
+ mov.l .Lerrloc2, r1
+ bsrf r1
+ nop
+.Lerrloc2b:
+ mov.l r8, @r0
+#endif
+ add #8, r15
+ lds.l @r15+, pr
+ mov.l @r15+, r12
+ mov.l @r15+, r10
+ mov.l @r15+, r9
+ mov.l @r15+, r8
+ rts
+ mov #-1, r0
+
+10:
+ /* Canceled. */
+ mov.w .Lresult, r1
+ mov #-1, r2
+ mov.l r2, @(r0,r1)
+ mov.w .Lchand, r0
+ or.b #0x10, @(r0,gbr)
+ stc gbr, r0
+ mov.w .Lclbuf, r1
+ mov.l .Lunwind, r2
+ braf r2
+ mov.l @(r0,r1), r4
+.Lunwindb:
+ cfi_endproc
+
+.L1k:
+ .word 1000
+.Lchand:
+ .word CANCELHANDLING - TLS_PRE_TCB_SIZE
+.Lresult:
+ .word RESULT - TLS_PRE_TCB_SIZE
+.Lclbuf:
+ .word CLEANUP_JMP_BUF - TLS_PRE_TCB_SIZE
+ .align 2
+.L1g:
+ .long 1000000000
+.Lgot2:
+ .long _GLOBAL_OFFSET_TABLE_
+#if USE___THREAD
+.Lerrno2:
+ .long errno@GOTTPOFF
+#else
+.Lerrloc2:
+ .long __errno_location@PLT-(.Lerrloc2b-.)
+#endif
+.Lenable0:
+ .long __pthread_enable_asynccancel-.Lenable0b
+.Ldisable0:
+ .long __pthread_disable_asynccancel-.Ldisable0b
+.Lunwind:
+ .long HIDDEN_JUMPTARGET (__pthread_unwind)-.Lunwindb
+ .size sem_timedwait,.-sem_timedwait
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/sem_trywait.S b/libc/nptl/sysdeps/unix/sysv/linux/sh/sem_trywait.S
new file mode 100644
index 000000000..ccdf3a0db
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/sem_trywait.S
@@ -0,0 +1,89 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <pthread-errnos.h>
+#include "lowlevel-atomic.h"
+
+
+ .text
+
+ .globl __new_sem_trywait
+ .type __new_sem_trywait,@function
+ .align 5
+__new_sem_trywait:
+ mov.l r12, @-r15
+ mov.l r8, @-r15
+ sts.l pr, @-r15
+ mov r4, r8
+ mov.l @r8, r0
+2:
+ tst r0, r0
+ bt 1f
+
+ mov r0, r3
+ mov r0, r4
+ add #-1, r3
+ CMPXCHG (r4, @r8, r3, r2)
+ bf/s 2b
+ mov r2, r0
+
+ lds.l @r15+, pr
+ mov.l @r15+, r8
+ mov.l @r15+, r12
+ rts
+ mov #0, r0
+
+1:
+ mov #EAGAIN, r8
+ mova .Lgot1, r0
+ mov.l .Lgot1, r12
+ add r0, r12
+
+#if USE___THREAD
+ mov.l .Lerrno1, r0
+ stc gbr, r1
+ mov.l @(r0, r12), r0
+ add r1, r0
+ mov.l r8, @r0
+#else
+ mov.l .Lerrloc1, r1
+ bsrf r1
+ nop
+.Lerrloc1b:
+ mov.l r8, @r0
+#endif
+ lds.l @r15+, pr
+ mov.l @r15+, r8
+ mov.l @r15+, r12
+ rts
+ mov #-1, r0
+
+ .align 2
+.Lgot1:
+ .long _GLOBAL_OFFSET_TABLE_
+#if USE___THREAD
+.Lerrno1:
+ .long errno@GOTTPOFF
+#else
+.Lerrloc1:
+ .long __errno_location@PLT-(.Lerrloc1b-.)
+#endif
+ .size __new_sem_trywait,.-__new_sem_trywait
+ versioned_symbol(libpthread, __new_sem_trywait, sem_trywait, GLIBC_2_1)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/sem_wait.S b/libc/nptl/sysdeps/unix/sysv/linux/sh/sem_wait.S
new file mode 100644
index 000000000..9ceb8f1c2
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/sem_wait.S
@@ -0,0 +1,167 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <pthread-errnos.h>
+#include <tcb-offsets.h>
+#include "lowlevel-atomic.h"
+
+
+#define SYS_gettimeofday __NR_gettimeofday
+#define SYS_futex 240
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+ .text
+
+ .globl __new_sem_wait
+ .type __new_sem_wait,@function
+ .align 5
+ cfi_startproc
+__new_sem_wait:
+ /* First check for cancellation. */
+ stc gbr, r0
+ mov.w .Lchand, r1
+ mov.l @(r0,r1), r0
+ mov #0xf9, r1
+ and r1, r0
+ cmp/eq #8, r0
+ bt 5f
+
+ mov.l r8, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r8, 0)
+ mov.l r10, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r10, 0)
+ mov.l r12, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (r12, 0)
+ sts.l pr, @-r15
+ cfi_adjust_cfa_offset(4)
+ cfi_rel_offset (pr, 0)
+ mov r4, r8
+3:
+ mov.l @r8, r0
+2:
+ tst r0, r0
+ bt 1f
+ mov r0, r3
+ mov r0, r4
+ add #-1, r3
+ CMPXCHG (r4, @r8, r3, r2)
+ bf/s 2b
+ mov r2, r0
+ bra 9f
+ mov #0, r0
+
+1:
+ mov.l .Lenable0, r1
+ bsrf r1
+ nop
+.Lenable0b:
+ mov r0, r10
+
+ mov r8, r4
+ mov #FUTEX_WAIT, r5
+ mov #0, r6
+ mov #0, r7
+ mov #SYS_futex, r3
+ extu.b r3, r3
+ trapa #0x14
+ SYSCALL_INST_PAD
+
+ mov.l .Ldisable0, r1
+ mov r10, r4
+ bsrf r1
+ mov r0, r10
+.Ldisable0b:
+ mov r10, r0
+
+ tst r0, r0
+ bt 3b
+ cmp/eq #-EWOULDBLOCK, r0
+ bt 3b
+ neg r0, r0
+
+ mov r0, r8
+ mova .Lgot0, r0
+ mov.l .Lgot0, r12
+ add r0, r12
+
+#if USE___THREAD
+ mov.l .Lerrno0, r0
+ stc gbr, r1
+ mov.l @(r0, r12), r0
+ add r1, r0
+ mov.l r8, @r0
+#else
+ mov.l .Lerrloc0, r1
+ bsrf r1
+ nop
+.Lerrloc0b:
+ mov.l r8, @r0
+#endif
+ mov #-1, r0
+9:
+ lds.l @r15+, pr
+ mov.l @r15+, r12
+ mov.l @r15+, r10
+ rts
+ mov.l @r15+, r8
+5:
+ /* Canceled. */
+ stc gbr, r0
+ mov.w .Lresult, r1
+ mov #-1, r2
+ mov.l r2, @(r0,r1)
+ mov.w .Lchand, r0
+ or.b #0x10, @(r0,gbr)
+ stc gbr, r0
+ mov.w .Lclbuf, r1
+ mov.l .Lunwind, r2
+ braf r2
+ mov.l @(r0,r1), r4
+.Lunwindb:
+ cfi_endproc
+
+.Lchand:
+ .word CANCELHANDLING - TLS_PRE_TCB_SIZE
+.Lresult:
+ .word RESULT - TLS_PRE_TCB_SIZE
+.Lclbuf:
+ .word CLEANUP_JMP_BUF - TLS_PRE_TCB_SIZE
+ .align 2
+.Lgot0:
+ .long _GLOBAL_OFFSET_TABLE_
+#if USE___THREAD
+.Lerrno0:
+ .long errno@GOTTPOFF
+#else
+.Lerrloc0:
+ .long __errno_location@PLT-(.Lerrloc0b-.)
+#endif
+.Lenable0:
+ .long __pthread_enable_asynccancel-.Lenable0b
+.Ldisable0:
+ .long __pthread_disable_asynccancel-.Ldisable0b
+.Lunwind:
+ .long HIDDEN_JUMPTARGET (__pthread_unwind)-.Lunwindb
+ .size __new_sem_wait,.-__new_sem_wait
+ versioned_symbol(libpthread, __new_sem_wait, sem_wait, GLIBC_2_1)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/sh4/lowlevellock.h b/libc/nptl/sysdeps/unix/sysv/linux/sh/sh4/lowlevellock.h
new file mode 100644
index 000000000..90be7bd8d
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/sh4/lowlevellock.h
@@ -0,0 +1,4 @@
+/* 4 instruction cycles not accessing cache and TLB are needed after
+ trapa instruction to avoid an SH-4 silicon bug. */
+#define NEED_SYSCALL_INST_PAD
+#include_next <lowlevellock.h>
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/smp.h b/libc/nptl/sysdeps/unix/sysv/linux/sh/smp.h
new file mode 100644
index 000000000..2c0cbe99a
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/smp.h
@@ -0,0 +1,24 @@
+/* Determine whether the host has multiple processors. SH version.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+static inline int
+is_smp_system (void)
+{
+ return 0;
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h b/libc/nptl/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h
new file mode 100644
index 000000000..9a967eaf5
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h
@@ -0,0 +1,163 @@
+/* Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#include <tls.h>
+#ifndef __ASSEMBLER__
+# include <nptl/pthreadP.h>
+#endif
+
+#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
+
+# define _IMM12 #-12
+# define _IMM16 #-16
+# define _IMP16 #16
+# undef PSEUDO
+# define PSEUDO(name, syscall_name, args) \
+ .text; \
+ ENTRY (name); \
+ .Lpseudo_start: \
+ SINGLE_THREAD_P; \
+ bf .Lpseudo_cancel; \
+ .type __##syscall_name##_nocancel,@function; \
+ .globl __##syscall_name##_nocancel; \
+ __##syscall_name##_nocancel: \
+ DO_CALL (syscall_name, args); \
+ mov r0,r1; \
+ mov _IMM12,r2; \
+ shad r2,r1; \
+ not r1,r1; \
+ tst r1,r1; \
+ bt .Lsyscall_error; \
+ bra .Lpseudo_end; \
+ nop; \
+ .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
+ .Lpseudo_cancel: \
+ sts.l pr,@-r15; \
+ cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (pr, 0); \
+ add _IMM16,r15; \
+ cfi_adjust_cfa_offset (16); \
+ SAVE_ARGS_##args; \
+ CENABLE; \
+ LOAD_ARGS_##args; \
+ add _IMP16,r15; \
+ cfi_adjust_cfa_offset (-16); \
+ lds.l @r15+,pr; \
+ cfi_adjust_cfa_offset (-4); \
+ cfi_restore (pr); \
+ DO_CALL(syscall_name, args); \
+ SYSCALL_INST_PAD; \
+ sts.l pr,@-r15; \
+ cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (pr, 0); \
+ mov.l r0,@-r15; \
+ cfi_adjust_cfa_offset (4); \
+ cfi_rel_offset (r0, 0); \
+ CDISABLE; \
+ mov.l @r15+,r0; \
+ cfi_adjust_cfa_offset (-4); \
+ lds.l @r15+,pr; \
+ cfi_adjust_cfa_offset (-4); \
+ cfi_restore (pr); \
+ mov r0,r1; \
+ mov _IMM12,r2; \
+ shad r2,r1; \
+ not r1,r1; \
+ tst r1,r1; \
+ bf .Lpseudo_end; \
+ .Lsyscall_error: \
+ SYSCALL_ERROR_HANDLER; \
+ .Lpseudo_end:
+
+# undef PSEUDO_END
+# define PSEUDO_END(sym) \
+ END (sym)
+
+# define SAVE_ARGS_0 /* Nothing. */
+# define SAVE_ARGS_1 SAVE_ARGS_0; mov.l r4,@(0,r15); cfi_offset (r4,-4)
+# define SAVE_ARGS_2 SAVE_ARGS_1; mov.l r5,@(4,r15); cfi_offset (r5,-8)
+# define SAVE_ARGS_3 SAVE_ARGS_2; mov.l r6,@(8,r15); cfi_offset (r6,-12)
+# define SAVE_ARGS_4 SAVE_ARGS_3; mov.l r7,@(12,r15); cfi_offset (r7,-16)
+# define SAVE_ARGS_5 SAVE_ARGS_4
+# define SAVE_ARGS_6 SAVE_ARGS_5
+
+# define LOAD_ARGS_0 /* Nothing. */
+# define LOAD_ARGS_1 LOAD_ARGS_0; mov.l @(0,r15),r4
+# define LOAD_ARGS_2 LOAD_ARGS_1; mov.l @(4,r15),r5
+# define LOAD_ARGS_3 LOAD_ARGS_2; mov.l @(8,r15),r6
+# define LOAD_ARGS_4 LOAD_ARGS_3; mov.l @(12,r15),r7
+# define LOAD_ARGS_5 LOAD_ARGS_4
+# define LOAD_ARGS_6 LOAD_ARGS_5
+
+# ifdef IS_IN_libpthread
+# define __local_enable_asynccancel __pthread_enable_asynccancel
+# define __local_disable_asynccancel __pthread_disable_asynccancel
+# elif !defined NOT_IN_libc
+# define __local_enable_asynccancel __libc_enable_asynccancel
+# define __local_disable_asynccancel __libc_disable_asynccancel
+# elif defined IS_IN_librt
+# define __local_enable_asynccancel __librt_enable_asynccancel
+# define __local_disable_asynccancel __librt_disable_asynccancel
+# else
+# error Unsupported library
+# endif
+
+# define CENABLE \
+ mov.l 1f,r0; \
+ bsrf r0; \
+ nop; \
+ 0: bra 2f; \
+ mov r0,r2; \
+ .align 2; \
+ 1: .long __local_enable_asynccancel - 0b; \
+ 2:
+
+# define CDISABLE \
+ mov.l 1f,r0; \
+ bsrf r0; \
+ mov r2,r4; \
+ 0: bra 2f; \
+ nop; \
+ .align 2; \
+ 1: .long __local_disable_asynccancel - 0b; \
+ 2:
+
+# ifndef __ASSEMBLER__
+# define SINGLE_THREAD_P \
+ __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+ header.multiple_threads) == 0, 1)
+# else
+# define SINGLE_THREAD_P \
+ stc gbr,r0; \
+ mov.w 0f,r1; \
+ sub r1,r0; \
+ mov.l @(MULTIPLE_THREADS_OFFSET,r0),r0; \
+ bra 1f; \
+ tst r0,r0; \
+ 0: .word TLS_PRE_TCB_SIZE; \
+ 1:
+
+# endif
+
+#elif !defined __ASSEMBLER__
+
+# define SINGLE_THREAD_P (1)
+# define NO_CANCELLATION 1
+
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sh/vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/sh/vfork.S
new file mode 100644
index 000000000..5433eacbe
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sh/vfork.S
@@ -0,0 +1,71 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+#include <tcb-offsets.h>
+
+/* Clone the calling process, but without copying the whole address space.
+ The calling process is suspended until the new process exits or is
+ replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
+ and the process ID of the new process to the old process. */
+
+ENTRY (__vfork)
+ /* Save the PID value. */
+ stc gbr, r2
+ mov.w .L2, r0
+ mov.l @(r0,r2), r4
+ neg r4, r1
+ tst r1, r1
+ bf 1f
+ mov #1, r1
+ rotr r1
+1:
+ mov.l r1, @(r0,r2)
+
+ mov.w .L1, r3
+ trapa #0x10
+ mov r0, r1
+
+ /* Restore the old PID value in the parent. */
+ tst r0, r0
+ bt.s 2f
+ stc gbr, r2
+ mov.w .L2, r0
+ mov.l r4, @(r0,r2)
+ mov r1, r0
+2:
+ mov #-12, r2
+ shad r2, r1
+ not r1, r1 // r1=0 means r0 = -1 to -4095
+ tst r1, r1 // i.e. error in linux
+ bf .Lpseudo_end
+ SYSCALL_ERROR_HANDLER
+.Lpseudo_end:
+ rts
+ nop
+.L1:
+ .word __NR_vfork
+.L2:
+ .word PID - TLS_PRE_TCB_SIZE
+ .align 2
+PSEUDO_END (__vfork)
+libc_hidden_def (__vfork)
+
+weak_alias (__vfork, vfork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sigtimedwait.c b/libc/nptl/sysdeps/unix/sysv/linux/sigtimedwait.c
new file mode 100644
index 000000000..8560e8b40
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sigtimedwait.c
@@ -0,0 +1,2 @@
+#include <nptl/pthreadP.h>
+#include "../../../../../sysdeps/unix/sysv/linux/sigtimedwait.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sigwait.c b/libc/nptl/sysdeps/unix/sysv/linux/sigwait.c
new file mode 100644
index 000000000..c358bfbee
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sigwait.c
@@ -0,0 +1,2 @@
+#include <nptl/pthreadP.h>
+#include "../../../../../sysdeps/unix/sysv/linux/sigwait.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sigwaitinfo.c b/libc/nptl/sysdeps/unix/sysv/linux/sigwaitinfo.c
new file mode 100644
index 000000000..a4f9fe8f5
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sigwaitinfo.c
@@ -0,0 +1,2 @@
+#include <nptl/pthreadP.h>
+#include "../../../../../sysdeps/unix/sysv/linux/sigwaitinfo.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sleep.c b/libc/nptl/sysdeps/unix/sysv/linux/sleep.c
new file mode 100644
index 000000000..2dce3210c
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sleep.c
@@ -0,0 +1,10 @@
+/* We want an #include_next, but we are the main source file.
+ So, #include ourselves and in that incarnation we can use #include_next. */
+#ifndef INCLUDED_SELF
+# define INCLUDED_SELF
+# include <sleep.c>
+#else
+/* This defines the CANCELLATION_P macro, which sleep.c checks for. */
+# include <pthreadP.h>
+# include_next <sleep.c>
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/smp.h b/libc/nptl/sysdeps/unix/sysv/linux/smp.h
new file mode 100644
index 000000000..fcc34f768
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/smp.h
@@ -0,0 +1,28 @@
+/* Determine whether the host has multiple processors. Linux version.
+ Copyright (C) 1996, 2002, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* Test whether the machine has more than one processor. This is not the
+ best test but good enough. More complicated tests would require `malloc'
+ which is not available at that time. */
+static inline int
+is_smp_system (void)
+{
+ /* Assume all machines are SMP and/or CMT and/or SMT. */
+ return 1;
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/Makefile b/libc/nptl/sysdeps/unix/sysv/linux/sparc/Makefile
new file mode 100644
index 000000000..e98c9bd86
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/Makefile
@@ -0,0 +1,2 @@
+# pull in __syscall_error routine
+libpthread-routines += sysdep
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/Versions b/libc/nptl/sysdeps/unix/sysv/linux/sparc/Versions
new file mode 100644
index 000000000..d10277248
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/Versions
@@ -0,0 +1,6 @@
+libpthread {
+ GLIBC_2.3.3 {
+ # Changed PTHREAD_STACK_MIN.
+ pthread_attr_setstack; pthread_attr_setstacksize;
+ }
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/aio_cancel.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/aio_cancel.c
new file mode 100644
index 000000000..0d6da8291
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/aio_cancel.c
@@ -0,0 +1,33 @@
+#include <shlib-compat.h>
+
+#define aio_cancel64 XXX
+#include <aio.h>
+#undef aio_cancel64
+#include <errno.h>
+
+extern __typeof (aio_cancel) __new_aio_cancel;
+extern __typeof (aio_cancel) __old_aio_cancel;
+
+#define aio_cancel __new_aio_cancel
+
+#include <sysdeps/pthread/aio_cancel.c>
+
+#undef aio_cancel
+strong_alias (__new_aio_cancel, __new_aio_cancel64);
+versioned_symbol (librt, __new_aio_cancel, aio_cancel, GLIBC_2_3);
+versioned_symbol (librt, __new_aio_cancel64, aio_cancel64, GLIBC_2_3);
+
+#if SHLIB_COMPAT (librt, GLIBC_2_1, GLIBC_2_3)
+
+#undef ECANCELED
+#define aio_cancel __old_aio_cancel
+#define ECANCELED 125
+
+#include <sysdeps/pthread/aio_cancel.c>
+
+#undef aio_cancel
+strong_alias (__old_aio_cancel, __old_aio_cancel64);
+compat_symbol (librt, __old_aio_cancel, aio_cancel, GLIBC_2_1);
+compat_symbol (librt, __old_aio_cancel64, aio_cancel64, GLIBC_2_1);
+
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/bits/local_lim.h b/libc/nptl/sysdeps/unix/sysv/linux/sparc/bits/local_lim.h
new file mode 100644
index 000000000..e082ea8f0
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/bits/local_lim.h
@@ -0,0 +1,89 @@
+/* Minimum guaranteed maximum values for system limits. Linux/SPARC version.
+ Copyright (C) 1993-1998,2000,2002,2003,2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* The kernel header pollutes the namespace with the NR_OPEN symbol
+ and defines LINK_MAX although filesystems have different maxima. A
+ similar thing is true for OPEN_MAX: the limit can be changed at
+ runtime and therefore the macro must not be defined. Remove this
+ after including the header if necessary. */
+#ifndef NR_OPEN
+# define __undef_NR_OPEN
+#endif
+#ifndef LINK_MAX
+# define __undef_LINK_MAX
+#endif
+#ifndef OPEN_MAX
+# define __undef_OPEN_MAX
+#endif
+
+/* The kernel sources contain a file with all the needed information. */
+#include <linux/limits.h>
+
+/* Have to remove NR_OPEN? */
+#ifdef __undef_NR_OPEN
+# undef NR_OPEN
+# undef __undef_NR_OPEN
+#endif
+/* Have to remove LINK_MAX? */
+#ifdef __undef_LINK_MAX
+# undef LINK_MAX
+# undef __undef_LINK_MAX
+#endif
+/* Have to remove OPEN_MAX? */
+#ifdef __undef_OPEN_MAX
+# undef OPEN_MAX
+# undef __undef_OPEN_MAX
+#endif
+
+/* The number of data keys per process. */
+#define _POSIX_THREAD_KEYS_MAX 128
+/* This is the value this implementation supports. */
+#define PTHREAD_KEYS_MAX 1024
+
+/* Controlling the iterations of destructors for thread-specific data. */
+#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
+/* Number of iterations this implementation does. */
+#define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS
+
+/* The number of threads per process. */
+#define _POSIX_THREAD_THREADS_MAX 64
+/* We have no predefined limit on the number of threads. */
+#undef PTHREAD_THREADS_MAX
+
+/* Maximum amount by which a process can descrease its asynchronous I/O
+ priority level. */
+#define AIO_PRIO_DELTA_MAX 20
+
+/* Minimum size for a thread. We are free to choose a reasonable value. */
+#define PTHREAD_STACK_MIN 24576
+
+/* Maximum number of timer expiration overruns. */
+#define DELAYTIMER_MAX 2147483647
+
+/* Maximum tty name length. */
+#define TTY_NAME_MAX 32
+
+/* Maximum login name length. This is arbitrary. */
+#define LOGIN_NAME_MAX 256
+
+/* Maximum host name length. */
+#define HOST_NAME_MAX 64
+
+/* Maximum message queue priority level. */
+#define MQ_PRIO_MAX 32768
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/bits/pthreadtypes.h b/libc/nptl/sysdeps/unix/sysv/linux/sparc/bits/pthreadtypes.h
new file mode 100644
index 000000000..e734c1205
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/bits/pthreadtypes.h
@@ -0,0 +1,218 @@
+/* Machine-specific pthread type layouts. SPARC version.
+ Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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. */
+
+#ifndef _BITS_PTHREADTYPES_H
+#define _BITS_PTHREADTYPES_H 1
+
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+# define __SIZEOF_PTHREAD_ATTR_T 56
+# define __SIZEOF_PTHREAD_MUTEX_T 40
+# define __SIZEOF_PTHREAD_MUTEXATTR_T 4
+# define __SIZEOF_PTHREAD_COND_T 48
+# define __SIZEOF_PTHREAD_CONDATTR_T 4
+# define __SIZEOF_PTHREAD_RWLOCK_T 56
+# define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
+# define __SIZEOF_PTHREAD_BARRIER_T 32
+# define __SIZEOF_PTHREAD_BARRIERATTR_T 4
+#else
+# define __SIZEOF_PTHREAD_ATTR_T 36
+# define __SIZEOF_PTHREAD_MUTEX_T 24
+# define __SIZEOF_PTHREAD_MUTEXATTR_T 4
+# define __SIZEOF_PTHREAD_COND_T 48
+# define __SIZEOF_PTHREAD_CONDATTR_T 4
+# define __SIZEOF_PTHREAD_RWLOCK_T 32
+# define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
+# define __SIZEOF_PTHREAD_BARRIER_T 20
+# define __SIZEOF_PTHREAD_BARRIERATTR_T 4
+#endif
+
+
+/* Thread identifiers. The structure of the attribute type is
+ deliberately not exposed. */
+typedef unsigned long int pthread_t;
+
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_ATTR_T];
+ long int __align;
+} pthread_attr_t;
+
+
+#if __WORDSIZE == 64
+typedef struct __pthread_internal_list
+{
+ struct __pthread_internal_list *__prev;
+ struct __pthread_internal_list *__next;
+} __pthread_list_t;
+#else
+typedef struct __pthread_internal_slist
+{
+ struct __pthread_internal_slist *__next;
+} __pthread_slist_t;
+#endif
+
+
+/* Data structures for mutex handling. The structure of the attribute
+ type is deliberately not exposed. */
+typedef union
+{
+ struct __pthread_mutex_s
+ {
+ int __lock;
+ unsigned int __count;
+ int __owner;
+#if __WORDSIZE == 64
+ unsigned int __nusers;
+#endif
+ /* KIND must stay at this position in the structure to maintain
+ binary compatibility. */
+ int __kind;
+#if __WORDSIZE == 64
+ int __spins;
+ __pthread_list_t __list;
+# define __PTHREAD_MUTEX_HAVE_PREV 1
+#else
+ unsigned int __nusers;
+ __extension__ union
+ {
+ int __spins;
+ __pthread_slist_t __list;
+ };
+#endif
+ } __data;
+ char __size[__SIZEOF_PTHREAD_MUTEX_T];
+ long int __align;
+} pthread_mutex_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_MUTEXATTR_T];
+ int __align;
+} pthread_mutexattr_t;
+
+
+/* Data structure for conditional variable handling. The structure of
+ the attribute type is deliberately not exposed. */
+typedef union
+{
+ struct
+ {
+ int __lock;
+ unsigned int __futex;
+ __extension__ unsigned long long int __total_seq;
+ __extension__ unsigned long long int __wakeup_seq;
+ __extension__ unsigned long long int __woken_seq;
+ void *__mutex;
+ unsigned int __nwaiters;
+ unsigned int __broadcast_seq;
+ } __data;
+ char __size[__SIZEOF_PTHREAD_COND_T];
+ __extension__ long long int __align;
+} pthread_cond_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_CONDATTR_T];
+ int __align;
+} pthread_condattr_t;
+
+
+/* Keys for thread-specific data */
+typedef unsigned int pthread_key_t;
+
+
+/* Once-only execution */
+typedef int pthread_once_t;
+
+
+#if defined __USE_UNIX98 || defined __USE_XOPEN2K
+/* Data structure for read-write lock variable handling. The
+ structure of the attribute type is deliberately not exposed. */
+typedef union
+{
+# if __WORDSIZE == 64
+ struct
+ {
+ int __lock;
+ unsigned int __nr_readers;
+ unsigned int __readers_wakeup;
+ unsigned int __writer_wakeup;
+ unsigned int __nr_readers_queued;
+ unsigned int __nr_writers_queued;
+ int __writer;
+ int __pad1;
+ unsigned long int __pad2;
+ unsigned long int __pad3;
+ /* FLAGS must stay at this position in the structure to maintain
+ binary compatibility. */
+ unsigned int __flags;
+ } __data;
+# else
+ struct
+ {
+ int __lock;
+ unsigned int __nr_readers;
+ unsigned int __readers_wakeup;
+ unsigned int __writer_wakeup;
+ unsigned int __nr_readers_queued;
+ unsigned int __nr_writers_queued;
+ /* FLAGS must stay at this position in the structure to maintain
+ binary compatibility. */
+ unsigned int __flags;
+ int __writer;
+ } __data;
+# endif
+ char __size[__SIZEOF_PTHREAD_RWLOCK_T];
+ long int __align;
+} pthread_rwlock_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_RWLOCKATTR_T];
+ long int __align;
+} pthread_rwlockattr_t;
+#endif
+
+
+#ifdef __USE_XOPEN2K
+/* POSIX spinlock data type. */
+typedef volatile int pthread_spinlock_t;
+
+
+/* POSIX barriers data type. The structure of the type is
+ deliberately not exposed. */
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_BARRIER_T];
+ long int __align;
+} pthread_barrier_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_BARRIERATTR_T];
+ int __align;
+} pthread_barrierattr_t;
+#endif
+
+
+#endif /* bits/pthreadtypes.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/bits/semaphore.h b/libc/nptl/sysdeps/unix/sysv/linux/sparc/bits/semaphore.h
new file mode 100644
index 000000000..7f3a32832
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/bits/semaphore.h
@@ -0,0 +1,44 @@
+/* Machine-specific POSIX semaphore type layouts. SPARC version.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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. */
+
+#ifndef _SEMAPHORE_H
+# error "Never use <bits/semaphore.h> directly; include <semaphore.h> instead."
+#endif
+
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+# define __SIZEOF_SEM_T 32
+#else
+# define __SIZEOF_SEM_T 16
+#endif
+
+/* Value returned if `sem_open' failed. */
+#define SEM_FAILED ((sem_t *) 0)
+
+/* Maximum value the semaphore can have. */
+#define SEM_VALUE_MAX (2147483647)
+
+
+typedef union
+{
+ char __size[__SIZEOF_SEM_T];
+ long int __align;
+} sem_t;
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/fork.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/fork.c
new file mode 100644
index 000000000..1cd79110a
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/fork.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 <sched.h>
+#include <signal.h>
+#include <sysdep.h>
+#include <tls.h>
+
+#define ARCH_FORK() \
+ INLINE_CLONE_SYSCALL (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, \
+ 0, NULL, NULL, &THREAD_SELF->tid)
+
+#include "../fork.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/lowlevellock.h b/libc/nptl/sysdeps/unix/sysv/linux/sparc/lowlevellock.h
new file mode 100644
index 000000000..5013922a2
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/lowlevellock.h
@@ -0,0 +1,301 @@
+/* Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 Libr \ary; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _LOWLEVELLOCK_H
+#define _LOWLEVELLOCK_H 1
+
+#include <time.h>
+#include <sys/param.h>
+#include <bits/pthreadtypes.h>
+#include <atomic.h>
+
+
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+#define FUTEX_REQUEUE 3
+#define FUTEX_CMP_REQUEUE 4
+#define FUTEX_WAKE_OP 5
+#define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE ((4 << 24) | 1)
+#define FUTEX_LOCK_PI 6
+#define FUTEX_UNLOCK_PI 7
+#define FUTEX_TRYLOCK_PI 8
+
+/* Initializer for compatibility lock. */
+#define LLL_MUTEX_LOCK_INITIALIZER (0)
+
+#define lll_futex_wait(futexp, val) \
+ ({ \
+ INTERNAL_SYSCALL_DECL (__err); \
+ long int __ret; \
+ \
+ __ret = INTERNAL_SYSCALL (futex, __err, 4, \
+ (futexp), FUTEX_WAIT, (val), 0); \
+ __ret; \
+ })
+
+#define lll_futex_timed_wait(futexp, val, timespec) \
+ ({ \
+ INTERNAL_SYSCALL_DECL (__err); \
+ long int __ret; \
+ \
+ __ret = INTERNAL_SYSCALL (futex, __err, 4, \
+ (futexp), FUTEX_WAIT, (val), (timespec)); \
+ __ret; \
+ })
+
+#define lll_futex_wake(futexp, nr) \
+ ({ \
+ INTERNAL_SYSCALL_DECL (__err); \
+ long int __ret; \
+ \
+ __ret = INTERNAL_SYSCALL (futex, __err, 4, \
+ (futexp), FUTEX_WAKE, (nr), 0); \
+ __ret; \
+ })
+
+/* Returns non-zero if error happened, zero if success. */
+#define lll_futex_requeue(futexp, nr_wake, nr_move, mutex, val) \
+ ({ \
+ INTERNAL_SYSCALL_DECL (__err); \
+ long int __ret; \
+ \
+ __ret = INTERNAL_SYSCALL (futex, __err, 6, \
+ (futexp), FUTEX_CMP_REQUEUE, (nr_wake), \
+ (nr_move), (mutex), (val)); \
+ INTERNAL_SYSCALL_ERROR_P (__ret, __err); \
+ })
+
+#define lll_robust_mutex_dead(futexv) \
+ do \
+ { \
+ int *__futexp = &(futexv); \
+ atomic_or (__futexp, FUTEX_OWNER_DIED); \
+ lll_futex_wake (__futexp, 1); \
+ } \
+ while (0)
+
+/* Returns non-zero if error happened, zero if success. */
+#ifdef __sparc32_atomic_do_lock
+/* Avoid FUTEX_WAKE_OP if supporting pre-v9 CPUs. */
+# define lll_futex_wake_unlock(futexp, nr_wake, nr_wake2, futexp2) 1
+#else
+# define lll_futex_wake_unlock(futexp, nr_wake, nr_wake2, futexp2) \
+ ({ \
+ INTERNAL_SYSCALL_DECL (__err); \
+ long int __ret; \
+ \
+ __ret = INTERNAL_SYSCALL (futex, __err, 6, \
+ (futexp), FUTEX_WAKE_OP, (nr_wake), \
+ (nr_wake2), (futexp2), \
+ FUTEX_OP_CLEAR_WAKE_IF_GT_ONE); \
+ INTERNAL_SYSCALL_ERROR_P (__ret, __err); \
+ })
+#endif
+
+static inline int
+__attribute__ ((always_inline))
+__lll_mutex_trylock (int *futex)
+{
+ return atomic_compare_and_exchange_val_24_acq (futex, 1, 0) != 0;
+}
+#define lll_mutex_trylock(futex) __lll_mutex_trylock (&(futex))
+
+static inline int
+__attribute__ ((always_inline))
+__lll_mutex_cond_trylock (int *futex)
+{
+ return atomic_compare_and_exchange_val_24_acq (futex, 2, 0) != 0;
+}
+#define lll_mutex_cond_trylock(futex) __lll_mutex_cond_trylock (&(futex))
+
+static inline int
+__attribute__ ((always_inline))
+__lll_robust_mutex_trylock (int *futex, int id)
+{
+ return atomic_compare_and_exchange_val_acq (futex, id, 0) != 0;
+}
+#define lll_robust_mutex_trylock(futex, id) \
+ __lll_robust_mutex_trylock (&(futex), id)
+
+
+extern void __lll_lock_wait (int *futex) attribute_hidden;
+extern int __lll_robust_lock_wait (int *futex) attribute_hidden;
+
+static inline void
+__attribute__ ((always_inline))
+__lll_mutex_lock (int *futex)
+{
+ int val = atomic_compare_and_exchange_val_24_acq (futex, 1, 0);
+
+ if (__builtin_expect (val != 0, 0))
+ __lll_lock_wait (futex);
+}
+#define lll_mutex_lock(futex) __lll_mutex_lock (&(futex))
+
+static inline int
+__attribute__ ((always_inline))
+__lll_robust_mutex_lock (int *futex, int id)
+{
+ int result = 0;
+ if (atomic_compare_and_exchange_bool_acq (futex, id, 0) != 0)
+ result = __lll_robust_lock_wait (futex);
+ return result;
+}
+#define lll_robust_mutex_lock(futex, id) \
+ __lll_robust_mutex_lock (&(futex), id)
+
+static inline void
+__attribute__ ((always_inline))
+__lll_mutex_cond_lock (int *futex)
+{
+ int val = atomic_compare_and_exchange_val_24_acq (futex, 2, 0);
+
+ if (__builtin_expect (val != 0, 0))
+ __lll_lock_wait (futex);
+}
+#define lll_mutex_cond_lock(futex) __lll_mutex_cond_lock (&(futex))
+
+#define lll_robust_mutex_cond_lock(futex, id) \
+ __lll_robust_mutex_lock (&(futex), (id) | FUTEX_WAITERS)
+
+
+extern int __lll_timedlock_wait (int *futex, const struct timespec *)
+ attribute_hidden;
+extern int __lll_robust_timedlock_wait (int *futex, const struct timespec *)
+ attribute_hidden;
+
+static inline int
+__attribute__ ((always_inline))
+__lll_mutex_timedlock (int *futex, const struct timespec *abstime)
+{
+ int val = atomic_compare_and_exchange_val_24_acq (futex, 1, 0);
+ int result = 0;
+
+ if (__builtin_expect (val != 0, 0))
+ result = __lll_timedlock_wait (futex, abstime);
+ return result;
+}
+#define lll_mutex_timedlock(futex, abstime) \
+ __lll_mutex_timedlock (&(futex), abstime)
+
+static inline int
+__attribute__ ((always_inline))
+__lll_robust_mutex_timedlock (int *futex, const struct timespec *abstime,
+ int id)
+{
+ int result = 0;
+ if (atomic_compare_and_exchange_bool_acq (futex, id, 0) != 0)
+ result = __lll_robust_timedlock_wait (futex, abstime);
+ return result;
+}
+#define lll_robust_mutex_timedlock(futex, abstime, id) \
+ __lll_robust_mutex_timedlock (&(futex), abstime, id)
+
+#define lll_mutex_unlock(lock) \
+ ((void) ({ \
+ int *__futex = &(lock); \
+ int __val = atomic_exchange_24_rel (__futex, 0); \
+ if (__builtin_expect (__val > 1, 0)) \
+ lll_futex_wake (__futex, 1); \
+ }))
+
+#define lll_robust_mutex_unlock(lock) \
+ ((void) ({ \
+ int *__futex = &(lock); \
+ int __val = atomic_exchange_rel (__futex, 0); \
+ if (__builtin_expect (__val & FUTEX_WAITERS, 0)) \
+ lll_futex_wake (__futex, 1); \
+ }))
+
+#define lll_mutex_unlock_force(lock) \
+ ((void) ({ \
+ int *__futex = &(lock); \
+ (void) atomic_exchange_24_rel (__futex, 0); \
+ lll_futex_wake (__futex, 1); \
+ }))
+
+#define lll_mutex_islocked(futex) \
+ (futex != 0)
+
+
+/* We have a separate internal lock implementation which is not tied
+ to binary compatibility. We can use the lll_mutex_*. */
+
+/* Type for lock object. */
+typedef int lll_lock_t;
+
+extern int lll_unlock_wake_cb (int *__futex) attribute_hidden;
+
+/* Initializers for lock. */
+#define LLL_LOCK_INITIALIZER (0)
+#define LLL_LOCK_INITIALIZER_LOCKED (1)
+
+#define lll_trylock(futex) lll_mutex_trylock (futex)
+#define lll_lock(futex) lll_mutex_lock (futex)
+#define lll_unlock(futex) lll_mutex_unlock (futex)
+#define lll_islocked(futex) lll_mutex_islocked (futex)
+
+
+/* The kernel notifies a process with uses CLONE_CLEARTID via futex
+ wakeup when the clone terminates. The memory location contains the
+ thread ID while the clone is running and is reset to zero
+ afterwards. */
+#define lll_wait_tid(tid) \
+ do \
+ { \
+ __typeof (tid) __tid; \
+ while ((__tid = (tid)) != 0) \
+ lll_futex_wait (&(tid), __tid); \
+ } \
+ while (0)
+
+extern int __lll_timedwait_tid (int *, const struct timespec *)
+ attribute_hidden;
+
+#define lll_timedwait_tid(tid, abstime) \
+ ({ \
+ int __res = 0; \
+ if ((tid) != 0) \
+ __res = __lll_timedwait_tid (&(tid), (abstime)); \
+ __res; \
+ })
+
+
+/* Conditional variable handling. */
+
+extern void __lll_cond_wait (pthread_cond_t *cond)
+ attribute_hidden;
+extern int __lll_cond_timedwait (pthread_cond_t *cond,
+ const struct timespec *abstime)
+ attribute_hidden;
+extern void __lll_cond_wake (pthread_cond_t *cond)
+ attribute_hidden;
+extern void __lll_cond_broadcast (pthread_cond_t *cond)
+ attribute_hidden;
+
+#define lll_cond_wait(cond) \
+ __lll_cond_wait (cond)
+#define lll_cond_timedwait(cond, abstime) \
+ __lll_cond_timedwait (cond, abstime)
+#define lll_cond_wake(cond) \
+ __lll_cond_wake (cond)
+#define lll_cond_broadcast(cond) \
+ __lll_cond_broadcast (cond)
+
+#endif /* lowlevellock.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/not-cancel.h b/libc/nptl/sysdeps/unix/sysv/linux/sparc/not-cancel.h
new file mode 100644
index 000000000..acf1a617e
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/not-cancel.h
@@ -0,0 +1 @@
+#include "../i386/not-cancel.h"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/pthread_once.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/pthread_once.c
new file mode 100644
index 000000000..3b07cc127
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/pthread_once.c
@@ -0,0 +1,94 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 "pthreadP.h"
+#include <lowlevellock.h>
+
+
+unsigned long int __fork_generation attribute_hidden;
+
+
+static void
+clear_once_control (void *arg)
+{
+ pthread_once_t *once_control = (pthread_once_t *) arg;
+
+ *once_control = 0;
+ lll_futex_wake (once_control, INT_MAX);
+}
+
+
+int
+__pthread_once (once_control, init_routine)
+ pthread_once_t *once_control;
+ void (*init_routine) (void);
+{
+ while (1)
+ {
+ int oldval, val, newval;
+
+ val = *once_control;
+ do
+ {
+ /* Check if the initialized has already been done. */
+ if ((val & 2) != 0)
+ return 0;
+
+ oldval = val;
+ newval = (oldval & 3) | __fork_generation | 1;
+ val = atomic_compare_and_exchange_val_acq (once_control, newval,
+ oldval);
+ }
+ while (__builtin_expect (val != oldval, 0));
+
+ /* Check if another thread already runs the initializer. */
+ if ((oldval & 1) != 0)
+ {
+ /* Check whether the initializer execution was interrupted
+ by a fork. */
+ if (((oldval ^ newval) & -4) == 0)
+ {
+ /* Same generation, some other thread was faster. Wait. */
+ lll_futex_wait (once_control, newval);
+ continue;
+ }
+ }
+
+ /* This thread is the first here. Do the initialization.
+ Register a cleanup handler so that in case the thread gets
+ interrupted the initialization can be restarted. */
+ pthread_cleanup_push (clear_once_control, once_control);
+
+ init_routine ();
+
+ pthread_cleanup_pop (0);
+
+
+ /* Add one to *once_control. */
+ atomic_increment (once_control);
+
+ /* Wake up all other threads. */
+ lll_futex_wake (once_control, INT_MAX);
+ break;
+ }
+
+ return 0;
+}
+weak_alias (__pthread_once, pthread_once)
+strong_alias (__pthread_once, __pthread_once_internal)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/clone.S b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/clone.S
new file mode 100644
index 000000000..675a997e9
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/clone.S
@@ -0,0 +1,9 @@
+/* We want an #include_next, but we are the main source file.
+ So, #include ourselves and in that incarnation we can use #include_next. */
+#ifndef INCLUDED_SELF
+# define INCLUDED_SELF
+# include <clone.S>
+#else
+# define RESET_PID
+# include_next <clone.S>
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/lowlevellock.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/lowlevellock.c
new file mode 100644
index 000000000..a7611d6a8
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/lowlevellock.c
@@ -0,0 +1,131 @@
+/* low level locking for pthread library. SPARC version.
+ Copyright (C) 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus@au.ibm.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 <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <sys/time.h>
+
+
+void
+__lll_lock_wait (int *futex)
+{
+ do
+ {
+ int oldval = atomic_compare_and_exchange_val_24_acq (futex, 2, 1);
+ if (oldval != 0)
+ lll_futex_wait (futex, 2);
+ }
+ while (atomic_compare_and_exchange_val_24_acq (futex, 2, 0) != 0);
+}
+
+
+int
+__lll_timedlock_wait (int *futex, const struct timespec *abstime)
+{
+ /* Reject invalid timeouts. */
+ if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)
+ return EINVAL;
+
+ do
+ {
+ struct timeval tv;
+ struct timespec rt;
+
+ /* Get the current time. */
+ (void) __gettimeofday (&tv, NULL);
+
+ /* Compute relative timeout. */
+ rt.tv_sec = abstime->tv_sec - tv.tv_sec;
+ rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
+ if (rt.tv_nsec < 0)
+ {
+ rt.tv_nsec += 1000000000;
+ --rt.tv_sec;
+ }
+
+ /* Already timed out? */
+ if (rt.tv_sec < 0)
+ return ETIMEDOUT;
+
+ /* Wait. */
+ int oldval = atomic_compare_and_exchange_val_24_acq (futex, 2, 1);
+ if (oldval != 0)
+ lll_futex_timed_wait (futex, 2, &rt);
+ }
+ while (atomic_compare_and_exchange_val_24_acq (futex, 2, 0) != 0);
+
+ return 0;
+}
+
+
+/* These don't get included in libc.so */
+#ifdef IS_IN_libpthread
+int
+lll_unlock_wake_cb (int *futex)
+{
+ int val = atomic_exchange_24_rel (futex, 0);
+
+ if (__builtin_expect (val > 1, 0))
+ lll_futex_wake (futex, 1);
+
+ return 0;
+}
+
+
+int
+__lll_timedwait_tid (int *tidp, const struct timespec *abstime)
+{
+ int tid;
+
+ if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)
+ return EINVAL;
+
+ /* Repeat until thread terminated. */
+ while ((tid = *tidp) != 0)
+ {
+ struct timeval tv;
+ struct timespec rt;
+
+ /* Get the current time. */
+ (void) __gettimeofday (&tv, NULL);
+
+ /* Compute relative timeout. */
+ rt.tv_sec = abstime->tv_sec - tv.tv_sec;
+ rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
+ if (rt.tv_nsec < 0)
+ {
+ rt.tv_nsec += 1000000000;
+ --rt.tv_sec;
+ }
+
+ /* Already timed out? */
+ if (rt.tv_sec < 0)
+ return ETIMEDOUT;
+
+ /* Wait until thread terminates. */
+ if (lll_futex_timed_wait (tidp, tid, &rt) == -ETIMEDOUT)
+ return ETIMEDOUT;
+ }
+
+ return 0;
+}
+
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/pt-vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/pt-vfork.S
new file mode 100644
index 000000000..fb01242b5
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/pt-vfork.S
@@ -0,0 +1,45 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
+
+ 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 <sysdep.h>
+#include <tcb-offsets.h>
+
+ .text
+ .globl __syscall_error
+ENTRY(__vfork)
+ ld [%g7 + PID], %o5
+ sub %g0, %o5, %o4
+ st %o4, [%g7 + PID]
+
+ LOADSYSCALL(vfork)
+ ta 0x10
+ bcc 2f
+ mov %o7, %g1
+ st %o5, [%g7 + PID]
+ call __syscall_error
+ mov %g1, %o7
+2: sub %o1, 1, %o1
+ andcc %o0, %o1, %o0
+ bne,a 1f
+ st %o5, [%g7 + PID]
+1: retl
+ nop
+END(__vfork)
+
+weak_alias (__vfork, vfork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/pthread_barrier_init.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/pthread_barrier_init.c
new file mode 100644
index 000000000..bbd08d004
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/pthread_barrier_init.c
@@ -0,0 +1,62 @@
+/* Copyright (C) 2002, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include "pthreadP.h"
+#include <lowlevellock.h>
+
+struct sparc_pthread_barrier
+{
+ struct pthread_barrier b;
+ unsigned char left_lock;
+ unsigned char pshared;
+};
+
+int
+pthread_barrier_init (barrier, attr, count)
+ pthread_barrier_t *barrier;
+ const pthread_barrierattr_t *attr;
+ unsigned int count;
+{
+ struct sparc_pthread_barrier *ibarrier;
+
+ if (__builtin_expect (count == 0, 0))
+ return EINVAL;
+
+ struct pthread_barrierattr *iattr = (struct pthread_barrierattr *) attr;
+ if (iattr != NULL)
+ {
+ if (iattr->pshared != PTHREAD_PROCESS_PRIVATE
+ && __builtin_expect (iattr->pshared != PTHREAD_PROCESS_SHARED, 0))
+ /* Invalid attribute. */
+ return EINVAL;
+ }
+
+ ibarrier = (struct sparc_pthread_barrier *) barrier;
+
+ /* Initialize the individual fields. */
+ ibarrier->b.lock = LLL_LOCK_INITIALIZER;
+ ibarrier->b.left = count;
+ ibarrier->b.init_count = count;
+ ibarrier->b.curr_event = 0;
+ ibarrier->left_lock = 0;
+ ibarrier->pshared = (iattr && iattr->pshared == PTHREAD_PROCESS_SHARED);
+
+ return 0;
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/pthread_barrier_wait.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/pthread_barrier_wait.c
new file mode 100644
index 000000000..4dfd11dcb
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/pthread_barrier_wait.c
@@ -0,0 +1,100 @@
+/* Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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 <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <pthreadP.h>
+
+struct sparc_pthread_barrier
+{
+ struct pthread_barrier b;
+ unsigned char left_lock;
+ unsigned char pshared;
+};
+
+/* Wait on barrier. */
+int
+pthread_barrier_wait (barrier)
+ pthread_barrier_t *barrier;
+{
+ struct sparc_pthread_barrier *ibarrier
+ = (struct sparc_pthread_barrier *) barrier;
+ int result = 0;
+
+ /* Make sure we are alone. */
+ lll_lock (ibarrier->b.lock);
+
+ /* One more arrival. */
+ --ibarrier->b.left;
+
+ /* Are these all? */
+ if (ibarrier->b.left == 0)
+ {
+ /* Yes. Increment the event counter to avoid invalid wake-ups and
+ tell the current waiters that it is their turn. */
+ ++ibarrier->b.curr_event;
+
+ /* Wake up everybody. */
+ lll_futex_wake (&ibarrier->b.curr_event, INT_MAX);
+
+ /* This is the thread which finished the serialization. */
+ result = PTHREAD_BARRIER_SERIAL_THREAD;
+ }
+ else
+ {
+ /* The number of the event we are waiting for. The barrier's event
+ number must be bumped before we continue. */
+ unsigned int event = ibarrier->b.curr_event;
+
+ /* Before suspending, make the barrier available to others. */
+ lll_unlock (ibarrier->b.lock);
+
+ /* Wait for the event counter of the barrier to change. */
+ do
+ lll_futex_wait (&ibarrier->b.curr_event, event);
+ while (event == ibarrier->b.curr_event);
+ }
+
+ /* Make sure the init_count is stored locally or in a register. */
+ unsigned int init_count = ibarrier->b.init_count;
+
+ /* If this was the last woken thread, unlock. */
+ if (__atomic_is_v9 || ibarrier->pshared == 0)
+ {
+ if (atomic_increment_val (&ibarrier->b.left) == init_count)
+ /* We are done. */
+ lll_unlock (ibarrier->b.lock);
+ }
+ else
+ {
+ unsigned int left;
+ /* Slightly more complicated. On pre-v9 CPUs, atomic_increment_val
+ is only atomic for threads within the same process, not for
+ multiple processes. */
+ __sparc32_atomic_do_lock24 (&ibarrier->left_lock);
+ left = ++ibarrier->b.left;
+ __sparc32_atomic_do_unlock24 (&ibarrier->left_lock);
+ if (left == init_count)
+ /* We are done. */
+ lll_unlock (ibarrier->b.lock);
+ }
+
+ return result;
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sem_init.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sem_init.c
new file mode 100644
index 000000000..dffd8c7ef
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sem_init.c
@@ -0,0 +1,63 @@
+/* Copyright (C) 2002, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <semaphore.h>
+#include <lowlevellock.h>
+#include <shlib-compat.h>
+#include "semaphoreP.h"
+
+struct sparc_sem
+{
+ struct sem s;
+ unsigned char lock;
+};
+
+
+int
+__new_sem_init (sem, pshared, value)
+ sem_t *sem;
+ int pshared;
+ unsigned int value;
+{
+ /* Parameter sanity check. */
+ if (__builtin_expect (value > SEM_VALUE_MAX, 0))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ /* Map to the internal type. */
+ struct sparc_sem *isem = (struct sparc_sem *) sem;
+
+ /* Use the value the user provided. */
+ isem->s.count = value;
+
+ isem->lock = 0;
+
+ /* We can completely ignore the PSHARED parameter since inter-process
+ use needs no special preparation. */
+
+ return 0;
+}
+versioned_symbol (libpthread, __new_sem_init, sem_init, GLIBC_2_1);
+#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1)
+strong_alias (__new_sem_init, __old_sem_init)
+compat_symbol (libpthread, __old_sem_init, sem_init, GLIBC_2_0);
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sem_post.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sem_post.c
new file mode 100644
index 000000000..be1cc60b1
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sem_post.c
@@ -0,0 +1,54 @@
+/* sem_post -- post to a POSIX semaphore. SPARC version.
+ Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <internaltypes.h>
+#include <semaphore.h>
+
+#include <shlib-compat.h>
+
+int
+__new_sem_post (sem_t *sem)
+{
+ int *futex = (int *) sem, nr;
+
+ if (__atomic_is_v9)
+ nr = atomic_increment_val (futex);
+ else
+ {
+ __sparc32_atomic_do_lock24 (futex + 1);
+ nr = ++*futex;
+ __sparc32_atomic_do_unlock24 (futex + 1);
+ }
+ int err = lll_futex_wake (futex, nr);
+ if (__builtin_expect (err, 0) < 0)
+ {
+ __set_errno (-err);
+ return -1;
+ }
+ return 0;
+}
+versioned_symbol (libpthread, __new_sem_post, sem_post, GLIBC_2_1);
+#if SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_1)
+strong_alias (__new_sem_post, __old_sem_post)
+compat_symbol (libpthread, __old_sem_post, sem_post, GLIBC_2_0);
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sem_timedwait.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sem_timedwait.c
new file mode 100644
index 000000000..efcc9e9aa
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sem_timedwait.c
@@ -0,0 +1,117 @@
+/* sem_timedwait -- wait on a semaphore. SPARC version.
+ Copyright (C) 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus@au.ibm.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 <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <internaltypes.h>
+#include <semaphore.h>
+
+#include <pthreadP.h>
+#include <shlib-compat.h>
+
+
+int
+sem_timedwait (sem_t *sem, const struct timespec *abstime)
+{
+ /* First check for cancellation. */
+ CANCELLATION_P (THREAD_SELF);
+
+ int *futex = (int *) sem;
+ int val;
+ int err;
+
+ if (*futex > 0)
+ {
+ if (__atomic_is_v9)
+ val = atomic_decrement_if_positive (futex);
+ else
+ {
+ __sparc32_atomic_do_lock24 (futex + 1);
+ val = *futex;
+ if (val > 0)
+ *futex = val - 1;
+ __sparc32_atomic_do_unlock24 (futex + 1);
+ }
+ if (val > 0)
+ return 0;
+ }
+
+ err = -EINVAL;
+ if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)
+ goto error_return;
+
+ do
+ {
+ struct timeval tv;
+ struct timespec rt;
+ int sec, nsec;
+
+ /* Get the current time. */
+ __gettimeofday (&tv, NULL);
+
+ /* Compute relative timeout. */
+ sec = abstime->tv_sec - tv.tv_sec;
+ nsec = abstime->tv_nsec - tv.tv_usec * 1000;
+ if (nsec < 0)
+ {
+ nsec += 1000000000;
+ --sec;
+ }
+
+ /* Already timed out? */
+ err = -ETIMEDOUT;
+ if (sec < 0)
+ goto error_return;
+
+ /* Do wait. */
+ rt.tv_sec = sec;
+ rt.tv_nsec = nsec;
+
+ /* Enable asynchronous cancellation. Required by the standard. */
+ int oldtype = __pthread_enable_asynccancel ();
+
+ err = lll_futex_timed_wait (futex, 0, &rt);
+
+ /* Disable asynchronous cancellation. */
+ __pthread_disable_asynccancel (oldtype);
+
+ if (err != 0 && err != -EWOULDBLOCK)
+ goto error_return;
+
+ if (__atomic_is_v9)
+ val = atomic_decrement_if_positive (futex);
+ else
+ {
+ __sparc32_atomic_do_lock24 (futex + 1);
+ val = *futex;
+ if (val > 0)
+ *futex = val - 1;
+ __sparc32_atomic_do_unlock24 (futex + 1);
+ }
+ }
+ while (val <= 0);
+
+ return 0;
+
+ error_return:
+ __set_errno (-err);
+ return -1;
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sem_trywait.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sem_trywait.c
new file mode 100644
index 000000000..429494e25
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sem_trywait.c
@@ -0,0 +1,59 @@
+/* sem_trywait -- wait on a semaphore. SPARC version.
+ Copyright (C) 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus@au.ibm.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 <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <internaltypes.h>
+#include <semaphore.h>
+
+#include <shlib-compat.h>
+
+
+int
+__new_sem_trywait (sem_t *sem)
+{
+ int *futex = (int *) sem;
+ int val;
+
+ if (*futex > 0)
+ {
+ if (__atomic_is_v9)
+ val = atomic_decrement_if_positive (futex);
+ else
+ {
+ __sparc32_atomic_do_lock24 (futex + 1);
+ val = *futex;
+ if (val > 0)
+ *futex = val - 1;
+ __sparc32_atomic_do_unlock24 (futex + 1);
+ }
+ if (val > 0)
+ return 0;
+ }
+
+ __set_errno (EAGAIN);
+ return -1;
+}
+versioned_symbol (libpthread, __new_sem_trywait, sem_trywait, GLIBC_2_1);
+#if SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_1)
+strong_alias (__new_sem_trywait, __old_sem_trywait)
+compat_symbol (libpthread, __old_sem_trywait, sem_trywait, GLIBC_2_0);
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sem_wait.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sem_wait.c
new file mode 100644
index 000000000..d9fcdcd4e
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sem_wait.c
@@ -0,0 +1,74 @@
+/* sem_wait -- wait on a semaphore. SPARC version.
+ Copyright (C) 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus@au.ibm.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 <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <internaltypes.h>
+#include <semaphore.h>
+
+#include <pthreadP.h>
+#include <shlib-compat.h>
+
+
+int
+__new_sem_wait (sem_t *sem)
+{
+ /* First check for cancellation. */
+ CANCELLATION_P (THREAD_SELF);
+
+ int *futex = (int *) sem;
+ int err;
+
+ do
+ {
+ int val;
+ if (__atomic_is_v9)
+ val = atomic_decrement_if_positive (futex);
+ else
+ {
+ __sparc32_atomic_do_lock24 (futex + 1);
+ val = *futex;
+ if (val > 0)
+ *futex = val - 1;
+ __sparc32_atomic_do_unlock24 (futex + 1);
+ }
+ if (val > 0)
+ return 0;
+
+ /* Enable asynchronous cancellation. Required by the standard. */
+ int oldtype = __pthread_enable_asynccancel ();
+
+ err = lll_futex_wait (futex, 0);
+
+ /* Disable asynchronous cancellation. */
+ __pthread_disable_asynccancel (oldtype);
+ }
+ while (err == 0 || err == -EWOULDBLOCK);
+
+ __set_errno (-err);
+ return -1;
+}
+
+versioned_symbol (libpthread, __new_sem_wait, sem_wait, GLIBC_2_1);
+#if SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_1)
+strong_alias (__new_sem_wait, __old_sem_wait)
+compat_symbol (libpthread, __old_sem_wait, sem_wait, GLIBC_2_0);
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/pthread_barrier_init.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/pthread_barrier_init.c
new file mode 100644
index 000000000..b2b842336
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/pthread_barrier_init.c
@@ -0,0 +1 @@
+#include "../../../../../../../pthread_barrier_init.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/pthread_barrier_wait.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/pthread_barrier_wait.c
new file mode 100644
index 000000000..7613863bb
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/pthread_barrier_wait.c
@@ -0,0 +1 @@
+#include "../../../../../../pthread/pthread_barrier_wait.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_init.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_init.c
new file mode 100644
index 000000000..b2ebc4cbb
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_init.c
@@ -0,0 +1 @@
+#include "../../../../../../../sem_init.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_post.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_post.c
new file mode 100644
index 000000000..4a6eac88f
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_post.c
@@ -0,0 +1 @@
+#include "../../../sem_post.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_timedwait.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_timedwait.c
new file mode 100644
index 000000000..b2526db02
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_timedwait.c
@@ -0,0 +1 @@
+#include "../../../sem_timedwait.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_trywait.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_trywait.c
new file mode 100644
index 000000000..aae46f725
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_trywait.c
@@ -0,0 +1 @@
+#include "../../../sem_trywait.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_wait.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_wait.c
new file mode 100644
index 000000000..31157f636
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/sem_wait.c
@@ -0,0 +1 @@
+#include "../../../sem_wait.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep-cancel.h b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep-cancel.h
new file mode 100644
index 000000000..75a4eb946
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep-cancel.h
@@ -0,0 +1,106 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <tls.h>
+#ifndef __ASSEMBLER__
+# include <nptl/pthreadP.h>
+#endif
+
+#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
+
+# undef PSEUDO
+# define PSEUDO(name, syscall_name, args) \
+ .text; \
+ .globl __syscall_error; \
+ENTRY(name) \
+ ld [%g7 + MULTIPLE_THREADS_OFFSET], %g1;\
+ cmp %g1, 0; \
+ bne 1f; \
+.type __##syscall_name##_nocancel,@function; \
+.globl __##syscall_name##_nocancel; \
+__##syscall_name##_nocancel: \
+ mov SYS_ify(syscall_name), %g1; \
+ ta 0x10; \
+ bcc 8f; \
+ mov %o7, %g1; \
+ call __syscall_error; \
+ mov %g1, %o7; \
+8: jmpl %o7 + 8, %g0; \
+ nop; \
+.size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel;\
+1: save %sp, -96, %sp; \
+ cfi_def_cfa_register(%fp); \
+ cfi_window_save; \
+ cfi_register(%o7, %i7); \
+ CENABLE; \
+ nop; \
+ mov %o0, %l0; \
+ COPY_ARGS_##args \
+ mov SYS_ify(syscall_name), %g1; \
+ ta 0x10; \
+ bcc 1f; \
+ mov %o0, %l1; \
+ CDISABLE; \
+ mov %l0, %o0; \
+ call __syscall_error; \
+ mov %l1, %o0; \
+ b 2f; \
+ mov -1, %l1; \
+1: CDISABLE; \
+ mov %l0, %o0; \
+2: jmpl %i7 + 8, %g0; \
+ restore %g0, %l1, %o0;
+
+
+# ifdef IS_IN_libpthread
+# define CENABLE call __pthread_enable_asynccancel
+# define CDISABLE call __pthread_disable_asynccancel
+# elif !defined NOT_IN_libc
+# define CENABLE call __libc_enable_asynccancel
+# define CDISABLE call __libc_disable_asynccancel
+# elif defined IS_IN_librt
+# define CENABLE call __librt_enable_asynccancel
+# define CDISABLE call __librt_disable_asynccancel
+# else
+# error Unsupported library
+# endif
+
+#define COPY_ARGS_0 /* Nothing */
+#define COPY_ARGS_1 COPY_ARGS_0 mov %i0, %o0;
+#define COPY_ARGS_2 COPY_ARGS_1 mov %i1, %o1;
+#define COPY_ARGS_3 COPY_ARGS_2 mov %i2, %o2;
+#define COPY_ARGS_4 COPY_ARGS_3 mov %i3, %o3;
+#define COPY_ARGS_5 COPY_ARGS_4 mov %i4, %o4;
+#define COPY_ARGS_6 COPY_ARGS_5 mov %i5, %o5;
+
+# ifndef __ASSEMBLER__
+# define SINGLE_THREAD_P \
+ __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+ header.multiple_threads) == 0, 1)
+# else
+# define SINGLE_THREAD_P ld [%g7 + MULTIPLE_THREADS_OFFSET], %g1
+# endif
+
+#elif !defined __ASSEMBLER__
+
+# define SINGLE_THREAD_P (1)
+# define NO_CANCELLATION 1
+
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S
new file mode 100644
index 000000000..a8e4dd5a4
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S
@@ -0,0 +1,49 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
+
+ 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 <sysdep.h>
+#include <tcb-offsets.h>
+
+ .text
+ .globl __syscall_error
+ENTRY(__vfork)
+ ld [%g7 + PID], %o5
+ cmp %o5, 0
+ bne 1f
+ sub %g0, %o5, %o4
+ sethi %hi(0x80000000), %o4
+1: st %o4, [%g7 + PID]
+
+ LOADSYSCALL(vfork)
+ ta 0x10
+ bcc 2f
+ mov %o7, %g1
+ st %o5, [%g7 + PID]
+ call __syscall_error
+ mov %g1, %o7
+2: sub %o1, 1, %o1
+ andcc %o0, %o1, %o0
+ bne,a 1f
+ st %o5, [%g7 + PID]
+1: retl
+ nop
+END(__vfork)
+
+libc_hidden_def (__vfork)
+weak_alias (__vfork, vfork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/Versions b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/Versions
new file mode 100644
index 000000000..3b111ddb5
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/Versions
@@ -0,0 +1,7 @@
+librt {
+ GLIBC_2.3.3 {
+ # Changed timer_t.
+ timer_create; timer_delete; timer_getoverrun; timer_gettime;
+ timer_settime;
+ }
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/clone.S b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/clone.S
new file mode 100644
index 000000000..675a997e9
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/clone.S
@@ -0,0 +1,9 @@
+/* We want an #include_next, but we are the main source file.
+ So, #include ourselves and in that incarnation we can use #include_next. */
+#ifndef INCLUDED_SELF
+# define INCLUDED_SELF
+# include <clone.S>
+#else
+# define RESET_PID
+# include_next <clone.S>
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/pt-vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/pt-vfork.S
new file mode 100644
index 000000000..8941043c3
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/pt-vfork.S
@@ -0,0 +1,45 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
+
+ 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 <sysdep.h>
+#include <tcb-offsets.h>
+
+ .text
+ .globl __syscall_error
+ENTRY(__vfork)
+ ld [%g7 + PID], %o5
+ sub %g0, %o5, %o4
+ st %o4, [%g7 + PID]
+
+ LOADSYSCALL(vfork)
+ ta 0x6d
+ bcc,pt %xcc, 2f
+ mov %o7, %g1
+ st %o5, [%g7 + PID]
+ call __syscall_error
+ mov %g1, %o7
+2: sub %o1, 1, %o1
+ andcc %o0, %o1, %o0
+ bne,a,pt %icc, 1f
+ st %o5, [%g7 + PID]
+1: retl
+ nop
+END(__vfork)
+
+weak_alias (__vfork, vfork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep-cancel.h b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep-cancel.h
new file mode 100644
index 000000000..dd263a597
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep-cancel.h
@@ -0,0 +1,104 @@
+/* Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <tls.h>
+#ifndef __ASSEMBLER__
+# include <nptl/pthreadP.h>
+#endif
+
+#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
+
+# undef PSEUDO
+# define PSEUDO(name, syscall_name, args) \
+ .text; \
+ .globl __syscall_error; \
+ENTRY(name) \
+ ld [%g7 + MULTIPLE_THREADS_OFFSET], %g1;\
+ brnz,pn %g1, 1f; \
+.type __##syscall_name##_nocancel,@function; \
+.globl __##syscall_name##_nocancel; \
+__##syscall_name##_nocancel: \
+ mov SYS_ify(syscall_name), %g1; \
+ ta 0x6d; \
+ bcc,pt %xcc, 8f; \
+ mov %o7, %g1; \
+ call __syscall_error; \
+ mov %g1, %o7; \
+8: jmpl %o7 + 8, %g0; \
+ nop; \
+.size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel;\
+1: save %sp, -192, %sp; \
+ cfi_def_cfa_register(%fp); \
+ cfi_window_save; \
+ cfi_register(%o7, %i7); \
+ CENABLE; \
+ nop; \
+ mov %o0, %l0; \
+ COPY_ARGS_##args \
+ mov SYS_ify(syscall_name), %g1; \
+ ta 0x6d; \
+ bcc,pt %xcc, 1f; \
+ mov %o0, %l1; \
+ CDISABLE; \
+ mov %l0, %o0; \
+ call __syscall_error; \
+ mov %l1, %o0; \
+ ba,pt %xcc, 2f; \
+ mov -1, %l1; \
+1: CDISABLE; \
+ mov %l0, %o0; \
+2: jmpl %i7 + 8, %g0; \
+ restore %g0, %l1, %o0;
+
+# ifdef IS_IN_libpthread
+# define CENABLE call __pthread_enable_asynccancel
+# define CDISABLE call __pthread_disable_asynccancel
+# elif !defined NOT_IN_libc
+# define CENABLE call __libc_enable_asynccancel
+# define CDISABLE call __libc_disable_asynccancel
+# elif defined IS_IN_librt
+# define CENABLE call __librt_enable_asynccancel
+# define CDISABLE call __librt_disable_asynccancel
+# else
+# error Unsupported library
+# endif
+
+#define COPY_ARGS_0 /* Nothing */
+#define COPY_ARGS_1 COPY_ARGS_0 mov %i0, %o0;
+#define COPY_ARGS_2 COPY_ARGS_1 mov %i1, %o1;
+#define COPY_ARGS_3 COPY_ARGS_2 mov %i2, %o2;
+#define COPY_ARGS_4 COPY_ARGS_3 mov %i3, %o3;
+#define COPY_ARGS_5 COPY_ARGS_4 mov %i4, %o4;
+#define COPY_ARGS_6 COPY_ARGS_5 mov %i5, %o5;
+
+# ifndef __ASSEMBLER__
+# define SINGLE_THREAD_P \
+ __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+ header.multiple_threads) == 0, 1)
+# else
+# define SINGLE_THREAD_P ld [%g7 + MULTIPLE_THREADS_OFFSET], %g1
+# endif
+
+#elif !defined __ASSEMBLER__
+
+# define SINGLE_THREAD_P (1)
+# define NO_CANCELLATION 1
+
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/timer_create.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/timer_create.c
new file mode 100644
index 000000000..0a9c3372b
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/timer_create.c
@@ -0,0 +1 @@
+#include "../../x86_64/timer_create.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/timer_delete.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/timer_delete.c
new file mode 100644
index 000000000..f0d4fd21d
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/timer_delete.c
@@ -0,0 +1 @@
+#include "../../x86_64/timer_delete.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/timer_getoverr.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/timer_getoverr.c
new file mode 100644
index 000000000..82121a7a2
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/timer_getoverr.c
@@ -0,0 +1 @@
+#include "../../x86_64/timer_getoverr.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/timer_gettime.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/timer_gettime.c
new file mode 100644
index 000000000..313c05fea
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/timer_gettime.c
@@ -0,0 +1 @@
+#include "../../x86_64/timer_gettime.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/timer_settime.c b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/timer_settime.c
new file mode 100644
index 000000000..76f549cb4
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/timer_settime.c
@@ -0,0 +1 @@
+#include "../../x86_64/timer_settime.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S
new file mode 100644
index 000000000..559757430
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S
@@ -0,0 +1,49 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
+
+ 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 <sysdep.h>
+#include <tcb-offsets.h>
+
+ .text
+ .globl __syscall_error
+ENTRY(__vfork)
+ ld [%g7 + PID], %o5
+ sethi %hi(0x80000000), %o3
+ cmp %o5, 0
+ sub %g0, %o5, %o4
+ move %icc, %o3, %o4
+ st %o4, [%g7 + PID]
+
+ LOADSYSCALL(vfork)
+ ta 0x6d
+ bcc,pt %xcc, 2f
+ mov %o7, %g1
+ st %o5, [%g7 + PID]
+ call __syscall_error
+ mov %g1, %o7
+2: sub %o1, 1, %o1
+ andcc %o0, %o1, %o0
+ bne,a,pt %icc, 1f
+ st %o5, [%g7 + PID]
+1: retl
+ nop
+END(__vfork)
+
+libc_hidden_def (__vfork)
+weak_alias (__vfork, vfork)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/timer_create.c b/libc/nptl/sysdeps/unix/sysv/linux/timer_create.c
new file mode 100644
index 000000000..5e9951395
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/timer_create.c
@@ -0,0 +1,236 @@
+/* Copyright (C) 2003,2004 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <sysdep.h>
+#include <kernel-features.h>
+#include <internaltypes.h>
+#include <nptl/pthreadP.h>
+#include "kernel-posix-timers.h"
+#include "kernel-posix-cpu-timers.h"
+
+
+#ifdef __NR_timer_create
+# ifndef __ASSUME_POSIX_TIMERS
+static int compat_timer_create (clockid_t clock_id, struct sigevent *evp,
+ timer_t *timerid);
+# define timer_create static compat_timer_create
+# include <nptl/sysdeps/pthread/timer_create.c>
+# undef timer_create
+
+/* Nonzero if the system calls are not available. */
+int __no_posix_timers attribute_hidden;
+# endif
+
+# ifdef timer_create_alias
+# define timer_create timer_create_alias
+# endif
+
+
+int
+timer_create (clock_id, evp, timerid)
+ clockid_t clock_id;
+ struct sigevent *evp;
+ timer_t *timerid;
+{
+# undef timer_create
+# ifndef __ASSUME_POSIX_TIMERS
+ if (__no_posix_timers >= 0)
+# endif
+ {
+ clockid_t syscall_clockid = (clock_id == CLOCK_PROCESS_CPUTIME_ID
+ ? MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED)
+ : clock_id == CLOCK_THREAD_CPUTIME_ID
+ ? MAKE_THREAD_CPUCLOCK (0, CPUCLOCK_SCHED)
+ : clock_id);
+
+ /* If the user wants notification via a thread we need to handle
+ this special. */
+ if (evp == NULL
+ || __builtin_expect (evp->sigev_notify != SIGEV_THREAD, 1))
+ {
+ struct sigevent local_evp;
+
+ /* We avoid allocating too much memory by basically
+ using struct timer as a derived class with the
+ first two elements being in the superclass. We only
+ need these two elements here. */
+ struct timer *newp = (struct timer *) malloc (offsetof (struct timer,
+ thrfunc));
+ if (newp == NULL)
+ /* No more memory. */
+ return -1;
+
+ if (evp == NULL)
+ {
+ /* The kernel has to pass up the timer ID which is a
+ userlevel object. Therefore we cannot leave it up to
+ the kernel to determine it. */
+ local_evp.sigev_notify = SIGEV_SIGNAL;
+ local_evp.sigev_signo = SIGALRM;
+ local_evp.sigev_value.sival_ptr = newp;
+
+ evp = &local_evp;
+ }
+
+ kernel_timer_t ktimerid;
+ int retval = INLINE_SYSCALL (timer_create, 3, syscall_clockid, evp,
+ &ktimerid);
+
+# ifndef __ASSUME_POSIX_TIMERS
+ if (retval != -1 || errno != ENOSYS)
+# endif
+ {
+# ifndef __ASSUME_POSIX_TIMERS
+ __no_posix_timers = 1;
+# endif
+
+ if (retval != -1)
+ {
+ newp->sigev_notify = (evp != NULL
+ ? evp->sigev_notify : SIGEV_SIGNAL);
+ newp->ktimerid = ktimerid;
+
+ *timerid = (timer_t) newp;
+ }
+ else
+ {
+ /* Cannot allocate the timer, fail. */
+ free (newp);
+ retval = -1;
+ }
+
+ return retval;
+ }
+
+ free (newp);
+
+# ifndef __ASSUME_POSIX_TIMERS
+ /* When we come here the syscall does not exist. Make sure we
+ do not try to use it again. */
+ __no_posix_timers = -1;
+# endif
+ }
+ else
+ {
+# ifndef __ASSUME_POSIX_TIMERS
+ /* Make sure we have the necessary kernel support. */
+ if (__no_posix_timers == 0)
+ {
+ INTERNAL_SYSCALL_DECL (err);
+ struct timespec ts;
+ int res;
+ res = INTERNAL_SYSCALL (clock_getres, err, 2,
+ CLOCK_REALTIME, &ts);
+ __no_posix_timers = (INTERNAL_SYSCALL_ERROR_P (res, err)
+ ? -1 : 1);
+ }
+
+ if (__no_posix_timers > 0)
+# endif
+ {
+ /* Create the helper thread. */
+ pthread_once (&__helper_once, __start_helper_thread);
+ if (__helper_tid == 0)
+ {
+ /* No resources to start the helper thread. */
+ __set_errno (EAGAIN);
+ return -1;
+ }
+
+ struct timer *newp;
+ newp = (struct timer *) malloc (sizeof (struct timer));
+ if (newp == NULL)
+ return -1;
+
+ /* Copy the thread parameters the user provided. */
+ newp->sival = evp->sigev_value;
+ newp->thrfunc = evp->sigev_notify_function;
+
+ /* We cannot simply copy the thread attributes since the
+ implementation might keep internal information for
+ each instance. */
+ (void) pthread_attr_init (&newp->attr);
+ if (evp->sigev_notify_attributes != NULL)
+ {
+ struct pthread_attr *nattr;
+ struct pthread_attr *oattr;
+
+ nattr = (struct pthread_attr *) &newp->attr;
+ oattr = (struct pthread_attr *) evp->sigev_notify_attributes;
+
+ nattr->schedparam = oattr->schedparam;
+ nattr->schedpolicy = oattr->schedpolicy;
+ nattr->flags = oattr->flags;
+ nattr->guardsize = oattr->guardsize;
+ nattr->stackaddr = oattr->stackaddr;
+ nattr->stacksize = oattr->stacksize;
+ }
+
+ /* In any case set the detach flag. */
+ (void) pthread_attr_setdetachstate (&newp->attr,
+ PTHREAD_CREATE_DETACHED);
+
+ /* Create the event structure for the kernel timer. */
+ struct sigevent sev;
+ sev.sigev_value.sival_ptr = newp;
+ sev.sigev_signo = SIGTIMER;
+ sev.sigev_notify = SIGEV_SIGNAL | SIGEV_THREAD_ID;
+ /* This is the thread ID of the helper thread. */
+ sev._sigev_un._pad[0] = __helper_tid;
+
+ /* Create the timer. */
+ INTERNAL_SYSCALL_DECL (err);
+ int res;
+ res = INTERNAL_SYSCALL (timer_create, err, 3,
+ syscall_clockid, &sev, &newp->ktimerid);
+ if (! INTERNAL_SYSCALL_ERROR_P (res, err))
+ {
+ *timerid = (timer_t) newp;
+ return 0;
+ }
+
+ /* Free the resources. */
+ free (newp);
+
+ __set_errno (INTERNAL_SYSCALL_ERRNO (res, err));
+
+ return -1;
+ }
+ }
+ }
+
+# ifndef __ASSUME_POSIX_TIMERS
+ /* Compatibility code. */
+ return compat_timer_create (clock_id, evp, timerid);
+# endif
+}
+#else
+# ifdef timer_create_alias
+# define timer_create timer_create_alias
+# endif
+/* The new system calls are not available. Use the userlevel
+ implementation. */
+# include <nptl/sysdeps/pthread/timer_create.c>
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/timer_delete.c b/libc/nptl/sysdeps/unix/sysv/linux/timer_delete.c
new file mode 100644
index 000000000..35055212a
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/timer_delete.c
@@ -0,0 +1,94 @@
+/* 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sysdep.h>
+#include <kernel-features.h>
+#include "kernel-posix-timers.h"
+
+
+#ifdef __NR_timer_delete
+# ifndef __ASSUME_POSIX_TIMERS
+static int compat_timer_delete (timer_t timerid);
+# define timer_delete static compat_timer_delete
+# include <nptl/sysdeps/pthread/timer_delete.c>
+# undef timer_delete
+# endif
+
+# ifdef timer_delete_alias
+# define timer_delete timer_delete_alias
+# endif
+
+
+int
+timer_delete (timerid)
+ timer_t timerid;
+{
+# undef timer_delete
+# ifndef __ASSUME_POSIX_TIMERS
+ if (__no_posix_timers >= 0)
+# endif
+ {
+ struct timer *kt = (struct timer *) timerid;
+
+ /* Delete the kernel timer object. */
+ int res = INLINE_SYSCALL (timer_delete, 1, kt->ktimerid);
+
+ if (res == 0)
+ {
+# ifndef __ASSUME_POSIX_TIMERS
+ /* We know the syscall support is available. */
+ __no_posix_timers = 1;
+# endif
+
+ /* Free the memory. */
+ (void) free (kt);
+
+ return 0;
+ }
+
+ /* The kernel timer is not known or something else bad happened.
+ Return the error. */
+# ifndef __ASSUME_POSIX_TIMERS
+ if (errno != ENOSYS)
+ {
+ __no_posix_timers = 1;
+# endif
+ return -1;
+# ifndef __ASSUME_POSIX_TIMERS
+ }
+
+ __no_posix_timers = -1;
+# endif
+ }
+
+# ifndef __ASSUME_POSIX_TIMERS
+ return compat_timer_delete (timerid);
+# endif
+}
+#else
+# ifdef timer_delete_alias
+# define timer_delete timer_delete_alias
+# endif
+/* The new system calls are not available. Use the userlevel
+ implementation. */
+# include <nptl/sysdeps/pthread/timer_delete.c>
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/timer_getoverr.c b/libc/nptl/sysdeps/unix/sysv/linux/timer_getoverr.c
new file mode 100644
index 000000000..fdbdaa7c8
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/timer_getoverr.c
@@ -0,0 +1,81 @@
+/* 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <time.h>
+#include <sysdep.h>
+#include <kernel-features.h>
+#include "kernel-posix-timers.h"
+
+
+#ifdef __NR_timer_getoverrun
+# ifndef __ASSUME_POSIX_TIMERS
+static int compat_timer_getoverrun (timer_t timerid);
+# define timer_getoverrun static compat_timer_getoverrun
+# include <nptl/sysdeps/pthread/timer_getoverr.c>
+# undef timer_getoverrun
+# endif
+
+# ifdef timer_getoverrun_alias
+# define timer_getoverrun timer_getoverrun_alias
+# endif
+
+
+int
+timer_getoverrun (timerid)
+ timer_t timerid;
+{
+# undef timer_getoverrun
+# ifndef __ASSUME_POSIX_TIMERS
+ if (__no_posix_timers >= 0)
+# endif
+ {
+ struct timer *kt = (struct timer *) timerid;
+
+ /* Get the information from the kernel. */
+ int res = INLINE_SYSCALL (timer_getoverrun, 1, kt->ktimerid);
+
+# ifndef __ASSUME_POSIX_TIMERS
+ if (res != -1 || errno != ENOSYS)
+ {
+ /* We know the syscall support is available. */
+ __no_posix_timers = 1;
+# endif
+ return res;
+# ifndef __ASSUME_POSIX_TIMERS
+ }
+# endif
+
+# ifndef __ASSUME_POSIX_TIMERS
+ __no_posix_timers = -1;
+# endif
+ }
+
+# ifndef __ASSUME_POSIX_TIMERS
+ return compat_timer_getoverrun (timerid);
+# endif
+}
+#else
+# ifdef timer_getoverrun_alias
+# define timer_getoverrun timer_getoverrun_alias
+# endif
+/* The new system calls are not available. Use the userlevel
+ implementation. */
+# include <nptl/sysdeps/pthread/timer_getoverr.c>
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/timer_gettime.c b/libc/nptl/sysdeps/unix/sysv/linux/timer_gettime.c
new file mode 100644
index 000000000..a2fcfd1b5
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/timer_gettime.c
@@ -0,0 +1,83 @@
+/* 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sysdep.h>
+#include <kernel-features.h>
+#include "kernel-posix-timers.h"
+
+
+#ifdef __NR_timer_gettime
+# ifndef __ASSUME_POSIX_TIMERS
+static int compat_timer_gettime (timer_t timerid, struct itimerspec *value);
+# define timer_gettime static compat_timer_gettime
+# include <nptl/sysdeps/pthread/timer_gettime.c>
+# undef timer_gettime
+# endif
+
+# ifdef timer_gettime_alias
+# define timer_gettime timer_gettime_alias
+# endif
+
+
+int
+timer_gettime (timerid, value)
+ timer_t timerid;
+ struct itimerspec *value;
+{
+# undef timer_gettime
+# ifndef __ASSUME_POSIX_TIMERS
+ if (__no_posix_timers >= 0)
+# endif
+ {
+ struct timer *kt = (struct timer *) timerid;
+
+ /* Delete the kernel timer object. */
+ int res = INLINE_SYSCALL (timer_gettime, 2, kt->ktimerid, value);
+
+# ifndef __ASSUME_POSIX_TIMERS
+ if (res != -1 || errno != ENOSYS)
+ {
+ /* We know the syscall support is available. */
+ __no_posix_timers = 1;
+# endif
+ return res;
+# ifndef __ASSUME_POSIX_TIMERS
+ }
+# endif
+
+# ifndef __ASSUME_POSIX_TIMERS
+ __no_posix_timers = -1;
+# endif
+ }
+
+# ifndef __ASSUME_POSIX_TIMERS
+ return compat_timer_gettime (timerid, value);
+# endif
+}
+#else
+# ifdef timer_gettime_alias
+# define timer_gettime timer_gettime_alias
+# endif
+/* The new system calls are not available. Use the userlevel
+ implementation. */
+# include <nptl/sysdeps/pthread/timer_gettime.c>
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/timer_routines.c b/libc/nptl/sysdeps/unix/sysv/linux/timer_routines.c
new file mode 100644
index 000000000..a5eb44225
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/timer_routines.c
@@ -0,0 +1,181 @@
+/* Copyright (C) 2003, 2004, 2005, 2006 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <sysdep.h>
+#include <kernel-features.h>
+#include <nptl/pthreadP.h>
+#include "kernel-posix-timers.h"
+
+
+struct thread_start_data
+{
+ void (*thrfunc) (sigval_t);
+ sigval_t sival;
+};
+
+
+#ifdef __NR_timer_create
+/* Helper thread to call the user-provided function. */
+static void *
+timer_sigev_thread (void *arg)
+{
+ /* The parent thread has all signals blocked. This is a bit
+ surprising for user code, although valid. We unblock all
+ signals. */
+ sigset_t ss;
+ sigemptyset (&ss);
+ INTERNAL_SYSCALL_DECL (err);
+ INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, &ss, NULL, _NSIG / 8);
+
+ struct thread_start_data *td = (struct thread_start_data *) arg;
+
+ void (*thrfunc) (sigval_t) = td->thrfunc;
+ sigval_t sival = td->sival;
+
+ /* The TD object was allocated in timer_helper_thread. */
+ free (td);
+
+ /* Call the user-provided function. */
+ thrfunc (sival);
+
+ return NULL;
+}
+
+
+/* Helper function to support starting threads for SIGEV_THREAD. */
+static void *
+timer_helper_thread (void *arg)
+{
+ /* Wait for the SIGTIMER signal, allowing the setXid signal, and
+ none else. */
+ sigset_t ss;
+ sigemptyset (&ss);
+ __sigaddset (&ss, SIGTIMER);
+
+ /* Endless loop of waiting for signals. The loop is only ended when
+ the thread is canceled. */
+ while (1)
+ {
+ siginfo_t si;
+
+ /* sigwaitinfo cannot be used here, since it deletes
+ SIGCANCEL == SIGTIMER from the set. */
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ /* XXX The size argument hopefully will have to be changed to the
+ real size of the user-level sigset_t. */
+ int result = INLINE_SYSCALL (rt_sigtimedwait, 4, &ss, &si, NULL,
+ _NSIG / 8);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ if (result > 0)
+ {
+ if (si.si_code == SI_TIMER)
+ {
+ struct timer *tk = (struct timer *) si.si_ptr;
+ struct thread_start_data *td = malloc (sizeof (*td));
+
+ /* There is not much we can do if the allocation fails. */
+ if (td != NULL)
+ {
+ /* That is the signal we are waiting for. */
+ td->thrfunc = tk->thrfunc;
+ td->sival = tk->sival;
+
+ pthread_t th;
+ (void) pthread_create (&th, &tk->attr, timer_sigev_thread,
+ td);
+ }
+ }
+ else if (si.si_code == SI_TKILL)
+ /* The thread is canceled. */
+ pthread_exit (NULL);
+ }
+ }
+}
+
+
+/* Control variable for helper thread creation. */
+pthread_once_t __helper_once attribute_hidden;
+
+
+/* TID of the helper thread. */
+pid_t __helper_tid attribute_hidden;
+
+
+/* Reset variables so that after a fork a new helper thread gets started. */
+static void
+reset_helper_control (void)
+{
+ __helper_once = PTHREAD_ONCE_INIT;
+ __helper_tid = 0;
+}
+
+
+void
+attribute_hidden
+__start_helper_thread (void)
+{
+ /* The helper thread needs only very little resources
+ and should go away automatically when canceled. */
+ pthread_attr_t attr;
+ (void) pthread_attr_init (&attr);
+ (void) pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
+
+ /* Block all signals in the helper thread but SIGSETXID. To do this
+ thoroughly we temporarily have to block all signals here. The
+ helper can lose wakeups if SIGCANCEL is not blocked throughout,
+ but sigfillset omits it SIGSETXID. So, we add SIGCANCEL back
+ explicitly here. */
+ sigset_t ss;
+ sigset_t oss;
+ sigfillset (&ss);
+ __sigaddset (&ss, SIGCANCEL);
+ INTERNAL_SYSCALL_DECL (err);
+ INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, &ss, &oss, _NSIG / 8);
+
+ /* Create the helper thread for this timer. */
+ pthread_t th;
+ int res = pthread_create (&th, &attr, timer_helper_thread, NULL);
+ if (res == 0)
+ /* We managed to start the helper thread. */
+ __helper_tid = ((struct pthread *) th)->tid;
+
+ /* Restore the signal mask. */
+ INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, &oss, NULL,
+ _NSIG / 8);
+
+ /* No need for the attribute anymore. */
+ (void) pthread_attr_destroy (&attr);
+
+ /* We have to make sure that after fork()ing a new helper thread can
+ be created. */
+ pthread_atfork (NULL, NULL, reset_helper_control);
+}
+#endif
+
+#ifndef __ASSUME_POSIX_TIMERS
+# include <nptl/sysdeps/pthread/timer_routines.c>
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/timer_settime.c b/libc/nptl/sysdeps/unix/sysv/linux/timer_settime.c
new file mode 100644
index 000000000..fe08080a1
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/timer_settime.c
@@ -0,0 +1,88 @@
+/* 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sysdep.h>
+#include <kernel-features.h>
+#include "kernel-posix-timers.h"
+
+
+#ifdef __NR_timer_settime
+# ifndef __ASSUME_POSIX_TIMERS
+static int compat_timer_settime (timer_t timerid, int flags,
+ const struct itimerspec *value,
+ struct itimerspec *ovalue);
+# define timer_settime static compat_timer_settime
+# include <nptl/sysdeps/pthread/timer_settime.c>
+# undef timer_settime
+# endif
+
+# ifdef timer_settime_alias
+# define timer_settime timer_settime_alias
+# endif
+
+
+int
+timer_settime (timerid, flags, value, ovalue)
+ timer_t timerid;
+ int flags;
+ const struct itimerspec *value;
+ struct itimerspec *ovalue;
+{
+# undef timer_settime
+# ifndef __ASSUME_POSIX_TIMERS
+ if (__no_posix_timers >= 0)
+# endif
+ {
+ struct timer *kt = (struct timer *) timerid;
+
+ /* Delete the kernel timer object. */
+ int res = INLINE_SYSCALL (timer_settime, 4, kt->ktimerid, flags,
+ value, ovalue);
+
+# ifndef __ASSUME_POSIX_TIMERS
+ if (res != -1 || errno != ENOSYS)
+ {
+ /* We know the syscall support is available. */
+ __no_posix_timers = 1;
+# endif
+ return res;
+# ifndef __ASSUME_POSIX_TIMERS
+ }
+# endif
+
+# ifndef __ASSUME_POSIX_TIMERS
+ __no_posix_timers = -1;
+# endif
+ }
+
+# ifndef __ASSUME_POSIX_TIMERS
+ return compat_timer_settime (timerid, flags, value, ovalue);
+# endif
+}
+#else
+# ifdef timer_settime_alias
+# define timer_settime timer_settime_alias
+# endif
+/* The new system calls are not available. Use the userlevel
+ implementation. */
+# include <nptl/sysdeps/pthread/timer_settime.c>
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/unregister-atfork.c b/libc/nptl/sysdeps/unix/sysv/linux/unregister-atfork.c
new file mode 100644
index 000000000..964f5b709
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/unregister-atfork.c
@@ -0,0 +1,111 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <stdlib.h>
+#include <fork.h>
+#include <atomic.h>
+
+
+void
+__unregister_atfork (dso_handle)
+ void *dso_handle;
+{
+ /* Check whether there is any entry in the list which we have to
+ remove. It is likely that this is not the case so don't bother
+ getting the lock.
+
+ We do not worry about other threads adding entries for this DSO
+ right this moment. If this happens this is a race and we can do
+ whatever we please. The program will crash anyway seen. */
+ struct fork_handler *runp = __fork_handlers;
+ struct fork_handler *lastp = NULL;
+
+ while (runp != NULL)
+ if (runp->dso_handle == dso_handle)
+ break;
+ else
+ {
+ lastp = runp;
+ runp = runp->next;
+ }
+
+ if (runp == NULL)
+ /* Nothing to do. */
+ return;
+
+ /* Get the lock to not conflict with additions or deletions. Note
+ that there couldn't have been another thread deleting something.
+ The __unregister_atfork function is only called from the
+ dlclose() code which itself serializes the operations. */
+ lll_lock (__fork_lock);
+
+ /* We have to create a new list with all the entries we don't remove. */
+ struct deleted_handler
+ {
+ struct fork_handler *handler;
+ struct deleted_handler *next;
+ } *deleted = NULL;
+
+ /* Remove the entries for the DSO which is unloaded from the list.
+ It's a single linked list so readers are. */
+ do
+ {
+ if (runp->dso_handle == dso_handle)
+ {
+ if (lastp == NULL)
+ __fork_handlers = runp->next;
+ else
+ lastp->next = runp->next;
+
+ /* We cannot overwrite the ->next element now. Put the deleted
+ entries in a separate list. */
+ struct deleted_handler *newp = alloca (sizeof (*newp));
+ newp->handler = runp;
+ newp->next = deleted;
+ deleted = newp;
+ }
+ else
+ lastp = runp;
+
+ runp = runp->next;
+ }
+ while (runp != NULL);
+
+ /* Release the lock. */
+ lll_unlock (__fork_lock);
+
+ /* Walk the list of all entries which have to be deleted. */
+ while (deleted != NULL)
+ {
+ /* We need to be informed by possible current users. */
+ deleted->handler->need_signal = 1;
+ /* Make sure this gets written out first. */
+ atomic_write_barrier ();
+
+ /* Decrement the reference counter. If it does not reach zero
+ wait for the last user. */
+ atomic_decrement (&deleted->handler->refcntr);
+ unsigned int val;
+ while ((val = deleted->handler->refcntr) != 0)
+ lll_futex_wait (&deleted->handler->refcntr, val);
+
+ deleted = deleted->next;
+ }
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/unwindbuf.sym b/libc/nptl/sysdeps/unix/sysv/linux/unwindbuf.sym
new file mode 100644
index 000000000..8044b4078
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/unwindbuf.sym
@@ -0,0 +1,7 @@
+#include <pthread.h>
+#include <stddef.h>
+
+--
+
+UNWINDBUFSIZE sizeof (__pthread_unwind_buf_t)
+UWJMPBUF offsetof (__pthread_unwind_buf_t, __cancel_jmp_buf)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/Makefile b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/Makefile
new file mode 100644
index 000000000..b32ce29ef
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/Makefile
@@ -0,0 +1,4 @@
+ifeq ($(subdir),nptl)
+CFLAGS-pt-initfini.s = -g0 -fPIC -fno-inline-functions \
+ -fno-asynchronous-unwind-tables $(fno-unit-at-a-time)
+endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/Versions b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/Versions
new file mode 100644
index 000000000..3b111ddb5
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/Versions
@@ -0,0 +1,7 @@
+librt {
+ GLIBC_2.3.3 {
+ # Changed timer_t.
+ timer_create; timer_delete; timer_getoverrun; timer_gettime;
+ timer_settime;
+ }
+}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h
new file mode 100644
index 000000000..693387a26
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h
@@ -0,0 +1,222 @@
+/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+#ifndef _BITS_PTHREADTYPES_H
+#define _BITS_PTHREADTYPES_H 1
+
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+# define __SIZEOF_PTHREAD_ATTR_T 56
+# define __SIZEOF_PTHREAD_MUTEX_T 40
+# define __SIZEOF_PTHREAD_MUTEXATTR_T 4
+# define __SIZEOF_PTHREAD_COND_T 48
+# define __SIZEOF_PTHREAD_CONDATTR_T 4
+# define __SIZEOF_PTHREAD_RWLOCK_T 56
+# define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
+# define __SIZEOF_PTHREAD_BARRIER_T 32
+# define __SIZEOF_PTHREAD_BARRIERATTR_T 4
+#else
+# define __SIZEOF_PTHREAD_ATTR_T 36
+# define __SIZEOF_PTHREAD_MUTEX_T 24
+# define __SIZEOF_PTHREAD_MUTEXATTR_T 4
+# define __SIZEOF_PTHREAD_COND_T 48
+# define __SIZEOF_PTHREAD_CONDATTR_T 4
+# define __SIZEOF_PTHREAD_RWLOCK_T 32
+# define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
+# define __SIZEOF_PTHREAD_BARRIER_T 20
+# define __SIZEOF_PTHREAD_BARRIERATTR_T 4
+#endif
+
+
+/* Thread identifiers. The structure of the attribute type is not
+ exposed on purpose. */
+typedef unsigned long int pthread_t;
+
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_ATTR_T];
+ long int __align;
+} pthread_attr_t;
+
+
+#if __WORDSIZE == 64
+typedef struct __pthread_internal_list
+{
+ struct __pthread_internal_list *__prev;
+ struct __pthread_internal_list *__next;
+} __pthread_list_t;
+#else
+typedef struct __pthread_internal_slist
+{
+ struct __pthread_internal_slist *__next;
+} __pthread_slist_t;
+#endif
+
+
+/* Data structures for mutex handling. The structure of the attribute
+ type is not exposed on purpose. */
+typedef union
+{
+ struct __pthread_mutex_s
+ {
+ int __lock;
+ unsigned int __count;
+ int __owner;
+#if __WORDSIZE == 64
+ unsigned int __nusers;
+#endif
+ /* KIND must stay at this position in the structure to maintain
+ binary compatibility. */
+ int __kind;
+#if __WORDSIZE == 64
+ int __spins;
+ __pthread_list_t __list;
+# define __PTHREAD_MUTEX_HAVE_PREV 1
+#else
+ unsigned int __nusers;
+ __extension__ union
+ {
+ int __spins;
+ __pthread_slist_t __list;
+ };
+#endif
+ } __data;
+ char __size[__SIZEOF_PTHREAD_MUTEX_T];
+ long int __align;
+} pthread_mutex_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_MUTEXATTR_T];
+ int __align;
+} pthread_mutexattr_t;
+
+
+/* Data structure for conditional variable handling. The structure of
+ the attribute type is not exposed on purpose. */
+typedef union
+{
+ struct
+ {
+ int __lock;
+ unsigned int __futex;
+ __extension__ unsigned long long int __total_seq;
+ __extension__ unsigned long long int __wakeup_seq;
+ __extension__ unsigned long long int __woken_seq;
+ void *__mutex;
+ unsigned int __nwaiters;
+ unsigned int __broadcast_seq;
+ } __data;
+ char __size[__SIZEOF_PTHREAD_COND_T];
+ __extension__ long long int __align;
+} pthread_cond_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_CONDATTR_T];
+ int __align;
+} pthread_condattr_t;
+
+
+/* Keys for thread-specific data */
+typedef unsigned int pthread_key_t;
+
+
+/* Once-only execution */
+typedef int pthread_once_t;
+
+
+#if defined __USE_UNIX98 || defined __USE_XOPEN2K
+/* Data structure for read-write lock variable handling. The
+ structure of the attribute type is not exposed on purpose. */
+typedef union
+{
+# if __WORDSIZE == 64
+ struct
+ {
+ int __lock;
+ unsigned int __nr_readers;
+ unsigned int __readers_wakeup;
+ unsigned int __writer_wakeup;
+ unsigned int __nr_readers_queued;
+ unsigned int __nr_writers_queued;
+ int __writer;
+ int __pad1;
+ unsigned long int __pad2;
+ unsigned long int __pad3;
+ /* FLAGS must stay at this position in the structure to maintain
+ binary compatibility. */
+ unsigned int __flags;
+ } __data;
+# else
+ struct
+ {
+ int __lock;
+ unsigned int __nr_readers;
+ unsigned int __readers_wakeup;
+ unsigned int __writer_wakeup;
+ unsigned int __nr_readers_queued;
+ unsigned int __nr_writers_queued;
+ /* FLAGS must stay at this position in the structure to maintain
+ binary compatibility. */
+ unsigned int __flags;
+ int __writer;
+ } __data;
+# endif
+ char __size[__SIZEOF_PTHREAD_RWLOCK_T];
+ long int __align;
+} pthread_rwlock_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_RWLOCKATTR_T];
+ long int __align;
+} pthread_rwlockattr_t;
+#endif
+
+
+#ifdef __USE_XOPEN2K
+/* POSIX spinlock data type. */
+typedef volatile int pthread_spinlock_t;
+
+
+/* POSIX barriers data type. The structure of the type is
+ deliberately not exposed. */
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_BARRIER_T];
+ long int __align;
+} pthread_barrier_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_BARRIERATTR_T];
+ int __align;
+} pthread_barrierattr_t;
+#endif
+
+
+#if __WORDSIZE == 32
+/* Extra attributes for the cleanup functions. */
+# define __cleanup_fct_attribute __attribute__ ((__regparm__ (1)))
+#endif
+
+#endif /* bits/pthreadtypes.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/bits/semaphore.h b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/bits/semaphore.h
new file mode 100644
index 000000000..57edbbbfb
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/bits/semaphore.h
@@ -0,0 +1,44 @@
+/* Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+#ifndef _SEMAPHORE_H
+# error "Never use <bits/semaphore.h> directly; include <semaphore.h> instead."
+#endif
+
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+# define __SIZEOF_SEM_T 32
+#else
+# define __SIZEOF_SEM_T 16
+#endif
+
+
+/* Value returned if `sem_open' failed. */
+#define SEM_FAILED ((sem_t *) 0)
+
+/* Maximum value the semaphore can have. */
+#define SEM_VALUE_MAX (2147483647)
+
+
+typedef union
+{
+ char __size[__SIZEOF_SEM_T];
+ long int __align;
+} sem_t;
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/clone.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/clone.S
new file mode 100644
index 000000000..675a997e9
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/clone.S
@@ -0,0 +1,9 @@
+/* We want an #include_next, but we are the main source file.
+ So, #include ourselves and in that incarnation we can use #include_next. */
+#ifndef INCLUDED_SELF
+# define INCLUDED_SELF
+# include <clone.S>
+#else
+# define RESET_PID
+# include_next <clone.S>
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/compat-timer.h b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/compat-timer.h
new file mode 100644
index 000000000..02485daa5
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/compat-timer.h
@@ -0,0 +1,46 @@
+/* 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <signal.h>
+#include <time.h>
+#include <sys/types.h>
+
+#define OLD_TIMER_MAX 256
+
+extern timer_t __compat_timer_list[OLD_TIMER_MAX] attribute_hidden;
+
+
+extern int __timer_create_new (clockid_t clock_id, struct sigevent *evp,
+ timer_t *timerid);
+extern int __timer_delete_new (timer_t timerid);
+extern int __timer_getoverrun_new (timer_t timerid);
+extern int __timer_gettime_new (timer_t timerid, struct itimerspec *value);
+extern int __timer_settime_new (timer_t timerid, int flags,
+ const struct itimerspec *value,
+ struct itimerspec *ovalue);
+
+
+extern int __timer_create_old (clockid_t clock_id, struct sigevent *evp,
+ int *timerid);
+extern int __timer_delete_old (int timerid);
+extern int __timer_getoverrun_old (int timerid);
+extern int __timer_gettime_old (int timerid, struct itimerspec *value);
+extern int __timer_settime_old (int timerid, int flags,
+ const struct itimerspec *value,
+ struct itimerspec *ovalue);
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c
new file mode 100644
index 000000000..c828e158d
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c
@@ -0,0 +1,31 @@
+/* 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 <sched.h>
+#include <signal.h>
+#include <sysdep.h>
+#include <tls.h>
+
+
+#define ARCH_FORK() \
+ INLINE_SYSCALL (clone, 4, \
+ CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, 0, \
+ NULL, &THREAD_SELF->tid)
+
+#include "../fork.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S
new file mode 100644
index 000000000..3621efa4f
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/libc-lowlevellock.S
@@ -0,0 +1,30 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+/* In libc.so we do not unconditionally use the lock prefix. Only if
+ the application is using threads. */
+#ifndef UP
+# define LOCK \
+ cmpl $0, __libc_multiple_threads(%rip); \
+ je 0f; \
+ lock; \
+0:
+#endif
+
+#include "lowlevellock.S"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
new file mode 100644
index 000000000..3a49e25dd
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
@@ -0,0 +1,283 @@
+/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <pthread-errnos.h>
+
+ .text
+
+#ifndef LOCK
+# ifdef UP
+# define LOCK
+# else
+# define LOCK lock
+# endif
+#endif
+
+#define SYS_futex 202
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+/* For the calculation see asm/vsyscall.h. */
+#define VSYSCALL_ADDR_vgettimeofday 0xffffffffff600000
+
+
+ .globl __lll_mutex_lock_wait
+ .type __lll_mutex_lock_wait,@function
+ .hidden __lll_mutex_lock_wait
+ .align 16
+__lll_mutex_lock_wait:
+ pushq %r10
+ pushq %rdx
+
+ xorq %r10, %r10 /* No timeout. */
+ movl $2, %edx
+#if FUTEX_WAIT == 0
+ xorl %esi, %esi
+#else
+ movl $FUTEX_WAIT, %esi
+#endif
+
+ cmpl %edx, %eax /* NB: %edx == 2 */
+ jne 2f
+
+1: movl $SYS_futex, %eax
+ syscall
+
+2: movl %edx, %eax
+ xchgl %eax, (%rdi) /* NB: lock is implied */
+
+ testl %eax, %eax
+ jnz 1b
+
+ popq %rdx
+ popq %r10
+ retq
+ .size __lll_mutex_lock_wait,.-__lll_mutex_lock_wait
+
+
+#ifdef NOT_IN_libc
+ .globl __lll_mutex_timedlock_wait
+ .type __lll_mutex_timedlock_wait,@function
+ .hidden __lll_mutex_timedlock_wait
+ .align 16
+__lll_mutex_timedlock_wait:
+ /* Check for a valid timeout value. */
+ cmpq $1000000000, 8(%rdx)
+ jae 3f
+
+ pushq %r8
+ pushq %r9
+ pushq %r12
+ pushq %r13
+ pushq %r14
+
+ /* Stack frame for the timespec and timeval structs. */
+ subq $16, %rsp
+
+ movq %rdi, %r12
+ movq %rdx, %r13
+
+1:
+ /* Get current time. */
+ movq %rsp, %rdi
+ xorl %esi, %esi
+ movq $VSYSCALL_ADDR_vgettimeofday, %rax
+ /* This is a regular function call, all caller-save registers
+ might be clobbered. */
+ callq *%rax
+
+ /* Compute relative timeout. */
+ movq 8(%rsp), %rax
+ movl $1000, %edi
+ mul %rdi /* Milli seconds to nano seconds. */
+ movq (%r13), %rdi
+ movq 8(%r13), %rsi
+ subq (%rsp), %rdi
+ subq %rax, %rsi
+ jns 4f
+ addq $1000000000, %rsi
+ decq %rdi
+4: testq %rdi, %rdi
+ js 5f /* Time is already up. */
+
+ /* Futex call. */
+ movq %rdi, (%rsp) /* Store relative timeout. */
+ movq %rsi, 8(%rsp)
+
+ movl $1, %eax
+ movl $2, %edx
+ LOCK
+ cmpxchgl %edx, (%r12)
+
+ testl %eax, %eax
+ je 8f
+
+ movq %rsp, %r10
+#if FUTEX_WAIT == 0
+ xorl %esi, %esi
+#else
+ movl $FUTEX_WAIT, %esi
+#endif
+ movq %r12, %rdi
+ movl $SYS_futex, %eax
+ syscall
+ movq %rax, %rcx
+
+8: /* NB: %edx == 2 */
+ xorl %eax, %eax
+ LOCK
+ cmpxchgl %edx, (%rdi)
+ jnz 7f
+
+6: addq $16, %rsp
+ popq %r14
+ popq %r13
+ popq %r12
+ popq %r9
+ popq %r8
+ retq
+
+ /* Check whether the time expired. */
+7: cmpq $-ETIMEDOUT, %rcx
+ je 5f
+
+ /* Make sure the current holder knows we are going to sleep. */
+ movl %edx, %eax
+ xchgl %eax, (%rdi)
+ testl %eax, %eax
+ jz 6b
+ jmp 1b
+
+3: movl $EINVAL, %eax
+ retq
+
+5: movl $ETIMEDOUT, %eax
+ jmp 6b
+ .size __lll_mutex_timedlock_wait,.-__lll_mutex_timedlock_wait
+#endif
+
+
+#ifdef NOT_IN_libc
+ .globl lll_unlock_wake_cb
+ .type lll_unlock_wake_cb,@function
+ .hidden lll_unlock_wake_cb
+ .align 16
+lll_unlock_wake_cb:
+ pushq %rsi
+ pushq %rdx
+
+ LOCK
+ addl $1, (%rdi)
+ jng 1f
+
+ popq %rdx
+ popq %rsi
+ retq
+ .size lll_unlock_wake_cb,.-lll_unlock_wake_cb
+#endif
+
+
+ .globl __lll_mutex_unlock_wake
+ .type __lll_mutex_unlock_wake,@function
+ .hidden __lll_mutex_unlock_wake
+ .align 16
+__lll_mutex_unlock_wake:
+ pushq %rsi
+ pushq %rdx
+
+ movl $0, (%rdi)
+ movl $FUTEX_WAKE, %esi
+ movl $1, %edx /* Wake one thread. */
+ movl $SYS_futex, %eax
+ syscall
+
+ popq %rdx
+ popq %rsi
+ retq
+ .size __lll_mutex_unlock_wake,.-__lll_mutex_unlock_wake
+
+
+#ifdef NOT_IN_libc
+ .globl __lll_timedwait_tid
+ .type __lll_timedwait_tid,@function
+ .hidden __lll_timedwait_tid
+ .align 16
+__lll_timedwait_tid:
+ pushq %r12
+ pushq %r13
+
+ movq %rdi, %r12
+ movq %rsi, %r13
+
+ subq $16, %rsp
+
+ /* Get current time. */
+2: movq %rsp, %rdi
+ xorl %esi, %esi
+ movq $VSYSCALL_ADDR_vgettimeofday, %rax
+ callq *%rax
+
+ /* Compute relative timeout. */
+ movq 8(%rsp), %rax
+ movl $1000, %edi
+ mul %rdi /* Milli seconds to nano seconds. */
+ movq (%r13), %rdi
+ movq 8(%r13), %rsi
+ subq (%rsp), %rdi
+ subq %rax, %rsi
+ jns 5f
+ addq $1000000000, %rsi
+ decq %rdi
+5: testq %rdi, %rdi
+ js 6f /* Time is already up. */
+
+ movq %rdi, (%rsp) /* Store relative timeout. */
+ movq %rsi, 8(%rsp)
+
+ movl (%r12), %edx
+ testl %edx, %edx
+ jz 4f
+
+ movq %rsp, %r10
+#if FUTEX_WAIT == 0
+ xorl %esi, %esi
+#else
+ movl $FUTEX_WAIT, %esi
+#endif
+ movq %r12, %rdi
+ movl $SYS_futex, %eax
+ syscall
+
+ cmpl $0, (%rdi)
+ jne 1f
+4: xorl %eax, %eax
+
+8: addq $16, %rsp
+ popq %r13
+ popq %r12
+ retq
+
+1: cmpq $-ETIMEDOUT, %rax
+ jne 2b
+
+6: movl $ETIMEDOUT, %eax
+ jmp 8b
+ .size __lll_timedwait_tid,.-__lll_timedwait_tid
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
new file mode 100644
index 000000000..c354e8489
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
@@ -0,0 +1,455 @@
+/* Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+#ifndef _LOWLEVELLOCK_H
+#define _LOWLEVELLOCK_H 1
+
+#include <time.h>
+#include <sys/param.h>
+#include <bits/pthreadtypes.h>
+
+#ifndef LOCK_INSTR
+# ifdef UP
+# define LOCK_INSTR /* nothing */
+# else
+# define LOCK_INSTR "lock;"
+# endif
+#endif
+
+#define SYS_futex 202
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+#define FUTEX_LOCK_PI 6
+#define FUTEX_UNLOCK_PI 7
+#define FUTEX_TRYLOCK_PI 8
+
+
+/* Initializer for compatibility lock. */
+#define LLL_MUTEX_LOCK_INITIALIZER (0)
+#define LLL_MUTEX_LOCK_INITIALIZER_LOCKED (1)
+#define LLL_MUTEX_LOCK_INITIALIZER_WAITERS (2)
+
+/* Delay in spinlock loop. */
+#define BUSY_WAIT_NOP asm ("rep; nop")
+
+
+#define lll_futex_wait(futex, val) \
+ ({ \
+ int __status; \
+ register __typeof (val) _val asm ("edx") = (val); \
+ __asm __volatile ("xorq %%r10, %%r10\n\t" \
+ "syscall" \
+ : "=a" (__status) \
+ : "0" (SYS_futex), "D" (futex), "S" (FUTEX_WAIT), \
+ "d" (_val) \
+ : "memory", "cc", "r10", "r11", "cx"); \
+ __status; \
+ })
+
+
+#define lll_futex_timed_wait(futex, val, timeout) \
+ ({ \
+ register const struct timespec *__to __asm__ ("r10") = timeout; \
+ int __status; \
+ register __typeof (val) _val asm ("edx") = (val); \
+ __asm __volatile ("syscall" \
+ : "=a" (__status) \
+ : "0" (SYS_futex), "D" (futex), "S" (FUTEX_WAIT), \
+ "d" (_val), "r" (__to) \
+ : "memory", "cc", "r11", "cx"); \
+ __status; \
+ })
+
+
+#define lll_futex_wake(futex, nr) \
+ do { \
+ int __ignore; \
+ register __typeof (nr) _nr asm ("edx") = (nr); \
+ __asm __volatile ("syscall" \
+ : "=a" (__ignore) \
+ : "0" (SYS_futex), "D" (futex), "S" (FUTEX_WAKE), \
+ "d" (_nr) \
+ : "memory", "cc", "r10", "r11", "cx"); \
+ } while (0)
+
+
+/* Does not preserve %eax and %ecx. */
+extern int __lll_mutex_lock_wait (int *__futex, int __val) attribute_hidden;
+/* Does not preserver %eax, %ecx, and %edx. */
+extern int __lll_mutex_timedlock_wait (int *__futex, int __val,
+ const struct timespec *__abstime)
+ attribute_hidden;
+/* Preserves all registers but %eax. */
+extern int __lll_mutex_unlock_wait (int *__futex) attribute_hidden;
+
+
+/* NB: in the lll_mutex_trylock macro we simply return the value in %eax
+ after the cmpxchg instruction. In case the operation succeded this
+ value is zero. In case the operation failed, the cmpxchg instruction
+ has loaded the current value of the memory work which is guaranteed
+ to be nonzero. */
+#define lll_mutex_trylock(futex) \
+ ({ int ret; \
+ __asm __volatile (LOCK_INSTR "cmpxchgl %2, %1" \
+ : "=a" (ret), "=m" (futex) \
+ : "r" (LLL_MUTEX_LOCK_INITIALIZER_LOCKED), "m" (futex),\
+ "0" (LLL_MUTEX_LOCK_INITIALIZER) \
+ : "memory"); \
+ ret; })
+
+
+#define lll_robust_mutex_trylock(futex, id) \
+ ({ int ret; \
+ __asm __volatile (LOCK_INSTR "cmpxchgl %2, %1" \
+ : "=a" (ret), "=m" (futex) \
+ : "r" (id), "m" (futex), \
+ "0" (LLL_MUTEX_LOCK_INITIALIZER) \
+ : "memory"); \
+ ret; })
+
+
+#define lll_mutex_cond_trylock(futex) \
+ ({ int ret; \
+ __asm __volatile (LOCK_INSTR "cmpxchgl %2, %1" \
+ : "=a" (ret), "=m" (futex) \
+ : "r" (LLL_MUTEX_LOCK_INITIALIZER_WAITERS), \
+ "m" (futex), "0" (LLL_MUTEX_LOCK_INITIALIZER) \
+ : "memory"); \
+ ret; })
+
+
+#define lll_mutex_lock(futex) \
+ (void) ({ int ignore1, ignore2, ignore3; \
+ __asm __volatile (LOCK_INSTR "cmpxchgl %0, %2\n\t" \
+ "jnz 1f\n\t" \
+ ".subsection 1\n" \
+ "1:\tleaq %2, %%rdi\n\t" \
+ "subq $128, %%rsp\n\t" \
+ "callq __lll_mutex_lock_wait\n\t" \
+ "addq $128, %%rsp\n\t" \
+ "jmp 2f\n\t" \
+ ".previous\n" \
+ "2:" \
+ : "=S" (ignore1), "=&D" (ignore2), "=m" (futex),\
+ "=a" (ignore3) \
+ : "0" (1), "m" (futex), "3" (0) \
+ : "cx", "r11", "cc", "memory"); })
+
+
+#define lll_robust_mutex_lock(futex, id) \
+ ({ int result, ignore1, ignore2; \
+ __asm __volatile (LOCK_INSTR "cmpxchgl %0, %2\n\t" \
+ "jnz 1f\n\t" \
+ ".subsection 1\n" \
+ "1:\tleaq %2, %%rdi\n\t" \
+ "subq $128, %%rsp\n\t" \
+ "callq __lll_robust_mutex_lock_wait\n\t" \
+ "addq $128, %%rsp\n\t" \
+ "jmp 2f\n\t" \
+ ".previous\n" \
+ "2:" \
+ : "=S" (ignore1), "=&D" (ignore2), "=m" (futex), \
+ "=a" (result) \
+ : "0" (id), "m" (futex), "3" (0) \
+ : "cx", "r11", "cc", "memory"); \
+ result; })
+
+
+#define lll_mutex_cond_lock(futex) \
+ (void) ({ int ignore1, ignore2, ignore3; \
+ __asm __volatile (LOCK_INSTR "cmpxchgl %0, %2\n\t" \
+ "jnz 1f\n\t" \
+ ".subsection 1\n" \
+ "1:\tleaq %2, %%rdi\n\t" \
+ "subq $128, %%rsp\n\t" \
+ "callq __lll_mutex_lock_wait\n\t" \
+ "addq $128, %%rsp\n\t" \
+ "jmp 2f\n\t" \
+ ".previous\n" \
+ "2:" \
+ : "=S" (ignore1), "=&D" (ignore2), "=m" (futex),\
+ "=a" (ignore3) \
+ : "0" (2), "m" (futex), "3" (0) \
+ : "cx", "r11", "cc", "memory"); })
+
+
+#define lll_robust_mutex_cond_lock(futex, id) \
+ ({ int result, ignore1, ignore2; \
+ __asm __volatile (LOCK_INSTR "cmpxchgl %0, %2\n\t" \
+ "jnz 1f\n\t" \
+ ".subsection 1\n" \
+ "1:\tleaq %2, %%rdi\n\t" \
+ "subq $128, %%rsp\n\t" \
+ "callq __lll_robust_mutex_lock_wait\n\t" \
+ "addq $128, %%rsp\n\t" \
+ "jmp 2f\n\t" \
+ ".previous\n" \
+ "2:" \
+ : "=S" (ignore1), "=&D" (ignore2), "=m" (futex), \
+ "=a" (result) \
+ : "0" (id | FUTEX_WAITERS), "m" (futex), "3" (0) \
+ : "cx", "r11", "cc", "memory"); \
+ result; })
+
+
+#define lll_mutex_timedlock(futex, timeout) \
+ ({ int result, ignore1, ignore2, ignore3; \
+ __asm __volatile (LOCK_INSTR "cmpxchgl %2, %4\n\t" \
+ "jnz 1f\n\t" \
+ ".subsection 1\n" \
+ "1:\tleaq %4, %%rdi\n\t" \
+ "movq %8, %%rdx\n\t" \
+ "subq $128, %%rsp\n\t" \
+ "callq __lll_mutex_timedlock_wait\n\t" \
+ "addq $128, %%rsp\n\t" \
+ "jmp 2f\n\t" \
+ ".previous\n" \
+ "2:" \
+ : "=a" (result), "=&D" (ignore1), "=S" (ignore2), \
+ "=&d" (ignore3), "=m" (futex) \
+ : "0" (0), "2" (1), "m" (futex), "m" (timeout) \
+ : "memory", "cx", "cc", "r10", "r11"); \
+ result; })
+
+
+#define lll_robust_mutex_timedlock(futex, timeout, id) \
+ ({ int result, ignore1, ignore2, ignore3; \
+ __asm __volatile (LOCK_INSTR "cmpxchgl %2, %4\n\t" \
+ "jnz 1f\n\t" \
+ ".subsection 1\n" \
+ "1:\tleaq %4, %%rdi\n\t" \
+ "movq %8, %%rdx\n\t" \
+ "subq $128, %%rsp\n\t" \
+ "callq __lll_robust_mutex_timedlock_wait\n\t" \
+ "addq $128, %%rsp\n\t" \
+ "jmp 2f\n\t" \
+ ".previous\n" \
+ "2:" \
+ : "=a" (result), "=&D" (ignore1), "=S" (ignore2), \
+ "=&d" (ignore3), "=m" (futex) \
+ : "0" (0), "2" (id), "m" (futex), "m" (timeout) \
+ : "memory", "cx", "cc", "r10", "r11"); \
+ result; })
+
+
+#define lll_mutex_unlock(futex) \
+ (void) ({ int ignore; \
+ __asm __volatile (LOCK_INSTR "decl %0\n\t" \
+ "jne 1f\n\t" \
+ ".subsection 1\n" \
+ "1:\tleaq %0, %%rdi\n\t" \
+ "subq $128, %%rsp\n\t" \
+ "callq __lll_mutex_unlock_wake\n\t" \
+ "addq $128, %%rsp\n\t" \
+ "jmp 2f\n\t" \
+ ".previous\n" \
+ "2:" \
+ : "=m" (futex), "=&D" (ignore) \
+ : "m" (futex) \
+ : "ax", "cx", "r11", "cc", "memory"); })
+
+
+#define lll_robust_mutex_unlock(futex) \
+ (void) ({ int ignore; \
+ __asm __volatile (LOCK_INSTR "andl %2, %0\n\t" \
+ "jne 1f\n\t" \
+ ".subsection 1\n" \
+ "1:\tleaq %0, %%rdi\n\t" \
+ "subq $128, %%rsp\n\t" \
+ "callq __lll_mutex_unlock_wake\n\t" \
+ "addq $128, %%rsp\n\t" \
+ "jmp 2f\n\t" \
+ ".previous\n" \
+ "2:" \
+ : "=m" (futex), "=&D" (ignore) \
+ : "i" (FUTEX_WAITERS), "m" (futex) \
+ : "ax", "cx", "r11", "cc", "memory"); })
+
+
+#define lll_robust_mutex_dead(futex) \
+ (void) ({ int ignore; \
+ __asm __volatile (LOCK_INSTR "orl %3, (%2)\n\t" \
+ "syscall" \
+ : "=m" (futex), "=a" (ignore) \
+ : "D" (&(futex)), "i" (FUTEX_OWNER_DIED), \
+ "S" (FUTEX_WAKE), "1" (__NR_futex), \
+ "d" (1) \
+ : "cx", "r11", "cc", "memory"); })
+
+
+#define lll_mutex_islocked(futex) \
+ (futex != LLL_MUTEX_LOCK_INITIALIZER)
+
+
+/* We have a separate internal lock implementation which is not tied
+ to binary compatibility. */
+
+/* Type for lock object. */
+typedef int lll_lock_t;
+
+/* Initializers for lock. */
+#define LLL_LOCK_INITIALIZER (0)
+#define LLL_LOCK_INITIALIZER_LOCKED (1)
+
+
+extern int lll_unlock_wake_cb (int *__futex) attribute_hidden;
+
+
+/* The states of a lock are:
+ 0 - untaken
+ 1 - taken by one user
+ 2 - taken by more users */
+
+
+#if defined NOT_IN_libc || defined UP
+# define lll_trylock(futex) lll_mutex_trylock (futex)
+# define lll_lock(futex) lll_mutex_lock (futex)
+# define lll_unlock(futex) lll_mutex_unlock (futex)
+#else
+/* Special versions of the macros for use in libc itself. They avoid
+ the lock prefix when the thread library is not used.
+
+ The code sequence to avoid unnecessary lock prefixes is what the AMD
+ guys suggested. If you do not like it, bring it up with AMD.
+
+ XXX In future we might even want to avoid it on UP machines. */
+
+# define lll_trylock(futex) \
+ ({ unsigned char ret; \
+ __asm __volatile ("cmpl $0, __libc_multiple_threads(%%rip)\n\t" \
+ "je 0f\n\t" \
+ "lock; cmpxchgl %2, %1\n\t" \
+ "jmp 1f\n" \
+ "0:\tcmpxchgl %2, %1\n\t" \
+ "1:setne %0" \
+ : "=a" (ret), "=m" (futex) \
+ : "r" (LLL_MUTEX_LOCK_INITIALIZER_LOCKED), "m" (futex),\
+ "0" (LLL_MUTEX_LOCK_INITIALIZER) \
+ : "memory"); \
+ ret; })
+
+
+# define lll_lock(futex) \
+ (void) ({ int ignore1, ignore2, ignore3; \
+ __asm __volatile ("cmpl $0, __libc_multiple_threads(%%rip)\n\t" \
+ "je 0f\n\t" \
+ "lock; cmpxchgl %0, %2\n\t" \
+ "jnz 1f\n\t" \
+ "jmp 2f\n" \
+ "0:\tcmpxchgl %0, %2\n\t" \
+ "jnz 1f\n\t" \
+ ".subsection 1\n" \
+ "1:\tleaq %2, %%rdi\n\t" \
+ "subq $128, %%rsp\n\t" \
+ "callq __lll_mutex_lock_wait\n\t" \
+ "addq $128, %%rsp\n\t" \
+ "jmp 2f\n\t" \
+ ".previous\n" \
+ "2:" \
+ : "=S" (ignore1), "=&D" (ignore2), "=m" (futex),\
+ "=a" (ignore3) \
+ : "0" (1), "m" (futex), "3" (0) \
+ : "cx", "r11", "cc", "memory"); })
+
+
+# define lll_unlock(futex) \
+ (void) ({ int ignore; \
+ __asm __volatile ("cmpl $0, __libc_multiple_threads(%%rip)\n\t" \
+ "je 0f\n\t" \
+ "lock; decl %0\n\t" \
+ "jne 1f\n\t" \
+ "jmp 2f\n" \
+ "0:\tdecl %0\n\t" \
+ "jne 1f\n\t" \
+ ".subsection 1\n" \
+ "1:\tleaq %0, %%rdi\n\t" \
+ "subq $128, %%rsp\n\t" \
+ "callq __lll_mutex_unlock_wake\n\t" \
+ "addq $128, %%rsp\n\t" \
+ "jmp 2f\n\t" \
+ ".previous\n" \
+ "2:" \
+ : "=m" (futex), "=&D" (ignore) \
+ : "m" (futex) \
+ : "ax", "cx", "r11", "cc", "memory"); })
+#endif
+
+
+#define lll_islocked(futex) \
+ (futex != LLL_MUTEX_LOCK_INITIALIZER)
+
+
+/* The kernel notifies a process with uses CLONE_CLEARTID via futex
+ wakeup when the clone terminates. The memory location contains the
+ thread ID while the clone is running and is reset to zero
+ afterwards.
+
+ The macro parameter must not have any side effect. */
+#define lll_wait_tid(tid) \
+ do { \
+ int __ignore; \
+ register __typeof (tid) _tid asm ("edx") = (tid); \
+ if (_tid != 0) \
+ __asm __volatile ("xorq %%r10, %%r10\n\t" \
+ "1:\tmovq %2, %%rax\n\t" \
+ "syscall\n\t" \
+ "cmpl $0, (%%rdi)\n\t" \
+ "jne 1b" \
+ : "=&a" (__ignore) \
+ : "S" (FUTEX_WAIT), "i" (SYS_futex), "D" (&tid), \
+ "d" (_tid) \
+ : "memory", "cc", "r10", "r11", "cx"); \
+ } while (0)
+
+extern int __lll_timedwait_tid (int *tid, const struct timespec *abstime)
+ attribute_hidden;
+#define lll_timedwait_tid(tid, abstime) \
+ ({ \
+ int __result = 0; \
+ if (tid != 0) \
+ { \
+ if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) \
+ __result = EINVAL; \
+ else \
+ __result = __lll_timedwait_tid (&tid, abstime); \
+ } \
+ __result; })
+
+
+/* Conditional variable handling. */
+
+extern void __lll_cond_wait (pthread_cond_t *cond) attribute_hidden;
+extern int __lll_cond_timedwait (pthread_cond_t *cond,
+ const struct timespec *abstime)
+ attribute_hidden;
+extern void __lll_cond_wake (pthread_cond_t *cond) attribute_hidden;
+extern void __lll_cond_broadcast (pthread_cond_t *cond) attribute_hidden;
+
+
+#define lll_cond_wait(cond) \
+ __lll_cond_wait (cond)
+#define lll_cond_timedwait(cond, abstime) \
+ __lll_cond_timedwait (cond, abstime)
+#define lll_cond_wake(cond) \
+ __lll_cond_wake (cond)
+#define lll_cond_broadcast(cond) \
+ __lll_cond_broadcast (cond)
+
+
+#endif /* lowlevellock.h */
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
new file mode 100644
index 000000000..1a088e27b
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
@@ -0,0 +1,194 @@
+/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <pthread-errnos.h>
+#include <lowlevelrobustlock.h>
+
+ .text
+
+#ifndef LOCK
+# ifdef UP
+# define LOCK
+# else
+# define LOCK lock
+# endif
+#endif
+
+#define SYS_futex 202
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+#define FUTEX_WAITERS 0x80000000
+#define FUTEX_OWNER_DIED 0x40000000
+
+/* For the calculation see asm/vsyscall.h. */
+#define VSYSCALL_ADDR_vgettimeofday 0xffffffffff600000
+
+
+ .globl __lll_robust_mutex_lock_wait
+ .type __lll_robust_mutex_lock_wait,@function
+ .hidden __lll_robust_mutex_lock_wait
+ .align 16
+__lll_robust_mutex_lock_wait:
+ pushq %r10
+ pushq %rdx
+
+ xorq %r10, %r10 /* No timeout. */
+#if FUTEX_WAIT == 0
+ xorl %esi, %esi
+#else
+ movl $FUTEX_WAIT, %esi
+#endif
+
+4: movl %eax, %edx
+ orl $FUTEX_WAITERS, %edx
+
+ testl $FUTEX_OWNER_DIED, %eax
+ jnz 3f
+
+ cmpl %edx, %eax
+ je 1f
+
+ LOCK
+ cmpxchgl %edx, (%rdi)
+ jnz 2f
+
+1: movl $SYS_futex, %eax
+ syscall
+
+ movl (%rdi), %eax
+
+2: testl %eax, %eax
+ jne 4b
+
+ movl %fs:TID, %edx
+ orl $FUTEX_WAITERS, %edx
+ LOCK
+ cmpxchgl %edx, (%rdi)
+ jnz 4b
+ /* NB: %rax == 0 */
+
+3: popq %rdx
+ popq %r10
+ retq
+ .size __lll_robust_mutex_lock_wait,.-__lll_robust_mutex_lock_wait
+
+
+ .globl __lll_robust_mutex_timedlock_wait
+ .type __lll_robust_mutex_timedlock_wait,@function
+ .hidden __lll_robust_mutex_timedlock_wait
+ .align 16
+__lll_robust_mutex_timedlock_wait:
+ /* Check for a valid timeout value. */
+ cmpq $1000000000, 8(%rdx)
+ jae 3f
+
+ pushq %r8
+ pushq %r9
+ pushq %r12
+ pushq %r13
+
+ /* Stack frame for the timespec and timeval structs. */
+ subq $24, %rsp
+
+ movq %rdi, %r12
+ movq %rdx, %r13
+
+1: movq %rax, 16(%rsp)
+
+ /* Get current time. */
+ movq %rsp, %rdi
+ xorl %esi, %esi
+ movq $VSYSCALL_ADDR_vgettimeofday, %rax
+ /* This is a regular function call, all caller-save registers
+ might be clobbered. */
+ callq *%rax
+
+ /* Compute relative timeout. */
+ movq 8(%rsp), %rax
+ movl $1000, %edi
+ mul %rdi /* Milli seconds to nano seconds. */
+ movq (%r13), %rdi
+ movq 8(%r13), %rsi
+ subq (%rsp), %rdi
+ subq %rax, %rsi
+ jns 4f
+ addq $1000000000, %rsi
+ decq %rdi
+4: testq %rdi, %rdi
+ js 8f /* Time is already up. */
+
+ /* Futex call. */
+ movq %rdi, (%rsp) /* Store relative timeout. */
+ movq %rsi, 8(%rsp)
+
+ movq 16(%rsp), %rdx
+ movl %edx, %eax
+ orl $FUTEX_WAITERS, %edx
+
+ testl $FUTEX_OWNER_DIED, %eax
+ jnz 6f
+
+ cmpl %eax, %edx
+ je 2f
+
+ LOCK
+ cmpxchgl %edx, (%r12)
+ movq $0, %rcx /* Must use mov to avoid changing cc. */
+ jnz 5f
+
+2: movq %rsp, %r10
+#if FUTEX_WAIT == 0
+ xorl %esi, %esi
+#else
+ movl $FUTEX_WAIT, %esi
+#endif
+ movq %r12, %rdi
+ movl $SYS_futex, %eax
+ syscall
+ movq %rax, %rcx
+
+ movl (%r12), %eax
+
+5: testl %eax, %eax
+ jne 7f
+
+ movl %fs:TID, %edx
+ orl $FUTEX_WAITERS, %edx
+ LOCK
+ cmpxchgl %edx, (%r12)
+ jnz 7f
+
+6: addq $24, %rsp
+ popq %r13
+ popq %r12
+ popq %r9
+ popq %r8
+ retq
+
+ /* Check whether the time expired. */
+7: cmpq $-ETIMEDOUT, %rcx
+ jne 1b
+
+8: movl $ETIMEDOUT, %eax
+ jmp 6b
+
+3: movl $EINVAL, %eax
+ retq
+ .size __lll_robust_mutex_timedlock_wait,.-__lll_robust_mutex_timedlock_wait
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/not-cancel.h b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/not-cancel.h
new file mode 100644
index 000000000..acf1a617e
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/not-cancel.h
@@ -0,0 +1 @@
+#include "../i386/not-cancel.h"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pt-vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pt-vfork.S
new file mode 100644
index 000000000..653b6b12f
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pt-vfork.S
@@ -0,0 +1,33 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <tcb-offsets.h>
+
+#define SAVE_PID \
+ movl %fs:PID, %esi; \
+ movl %esi, %edx; \
+ negl %edx; \
+ movl %edx, %fs:PID
+
+#define RESTORE_PID \
+ testq %rax, %rax; \
+ je 1f; \
+ movl %esi, %fs:PID; \
+1:
+
+#include <../../../../../../sysdeps/unix/sysv/linux/x86_64/vfork.S>
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
new file mode 100644
index 000000000..fa8125dd8
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
@@ -0,0 +1,160 @@
+/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <lowlevelbarrier.h>
+
+#define SYS_futex 202
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+#ifndef UP
+# define LOCK lock
+#else
+# define LOCK
+#endif
+
+
+ .text
+
+ .globl pthread_barrier_wait
+ .type pthread_barrier_wait,@function
+ .align 16
+pthread_barrier_wait:
+ /* Get the mutex. */
+ xorl %eax, %eax
+ movl $1, %esi
+ LOCK
+ cmpxchgl %esi, MUTEX(%rdi)
+ jnz 1f
+
+ /* One less waiter. If this was the last one needed wake
+ everybody. */
+2: decl LEFT(%rdi)
+ je 3f
+
+ /* There are more threads to come. */
+#if CURR_EVENT == 0
+ movl (%rdi), %edx
+#else
+ movl CURR_EVENT(%rdi), %edx
+#endif
+
+ /* Release the mutex. */
+ LOCK
+ decl MUTEX(%rdi)
+ jne 6f
+
+ /* Wait for the remaining threads. The call will return immediately
+ if the CURR_EVENT memory has meanwhile been changed. */
+7:
+#if FUTEX_WAIT == 0
+ xorl %esi, %esi
+#else
+ movl $FUTEX_WAIT, %esi
+#endif
+ xorq %r10, %r10
+8: movl $SYS_futex, %eax
+ syscall
+
+ /* Don't return on spurious wakeups. The syscall does not change
+ any register except %eax so there is no need to reload any of
+ them. */
+#if CURR_EVENT == 0
+ cmpl %edx, (%rdi)
+#else
+ cmpl %edx, CURR_EVENT(%rdi)
+#endif
+ je 8b
+
+ /* Increment LEFT. If this brings the count back to the
+ initial count unlock the object. */
+ movl $1, %edx
+ movl INIT_COUNT(%rdi), %eax
+ LOCK
+ xaddl %edx, LEFT(%rdi)
+ subl $1, %eax
+ cmpl %eax, %edx
+ jne,pt 10f
+
+ /* Release the mutex. We cannot release the lock before
+ waking the waiting threads since otherwise a new thread might
+ arrive and gets waken up, too. */
+ LOCK
+ decl MUTEX(%rdi)
+ jne 9f
+
+10: xorl %eax, %eax /* != PTHREAD_BARRIER_SERIAL_THREAD */
+
+ retq
+
+ /* The necessary number of threads arrived. */
+3:
+#if CURR_EVENT == 0
+ incl (%rdi)
+#else
+ incl CURR_EVENT(%rdi)
+#endif
+
+ /* Wake up all waiters. The count is a signed number in the kernel
+ so 0x7fffffff is the highest value. */
+ movl $0x7fffffff, %edx
+ movl $FUTEX_WAKE, %esi
+ movl $SYS_futex, %eax
+ syscall
+
+ /* Increment LEFT. If this brings the count back to the
+ initial count unlock the object. */
+ movl $1, %edx
+ movl INIT_COUNT(%rdi), %eax
+ LOCK
+ xaddl %edx, LEFT(%rdi)
+ subl $1, %eax
+ cmpl %eax, %edx
+ jne,pt 5f
+
+ /* Release the mutex. We cannot release the lock before
+ waking the waiting threads since otherwise a new thread might
+ arrive and gets waken up, too. */
+ LOCK
+ decl MUTEX(%rdi)
+ jne 4f
+
+5: orl $-1, %eax /* == PTHREAD_BARRIER_SERIAL_THREAD */
+
+ retq
+
+1: addq $MUTEX, %rdi
+ callq __lll_mutex_lock_wait
+ subq $MUTEX, %rdi
+ jmp 2b
+
+4: addq $MUTEX, %rdi
+ callq __lll_mutex_unlock_wake
+ jmp 5b
+
+6: addq $MUTEX, %rdi
+ callq __lll_mutex_unlock_wake
+ subq $MUTEX, %rdi
+ jmp 7b
+
+9: addq $MUTEX, %rdi
+ callq __lll_mutex_unlock_wake
+ jmp 10b
+ .size pthread_barrier_wait,.-pthread_barrier_wait
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
new file mode 100644
index 000000000..006de2696
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
@@ -0,0 +1,143 @@
+/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <lowlevelcond.h>
+#include <kernel-features.h>
+#include <pthread-pi-defines.h>
+
+#ifdef UP
+# define LOCK
+#else
+# define LOCK lock
+#endif
+
+#define SYS_futex 202
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+#define FUTEX_REQUEUE 3
+#define FUTEX_CMP_REQUEUE 4
+
+#define EINVAL 22
+
+
+ .text
+
+ /* int pthread_cond_broadcast (pthread_cond_t *cond) */
+ .globl __pthread_cond_broadcast
+ .type __pthread_cond_broadcast, @function
+ .align 16
+__pthread_cond_broadcast:
+
+ /* Get internal lock. */
+ movl $1, %esi
+ xorl %eax, %eax
+ LOCK
+#if cond_lock == 0
+ cmpxchgl %esi, (%rdi)
+#else
+ cmpxchgl %esi, cond_lock(%rdi)
+#endif
+ jnz 1f
+
+2: addq $cond_futex, %rdi
+ movq total_seq-cond_futex(%rdi), %r9
+ cmpq wakeup_seq-cond_futex(%rdi), %r9
+ jna 4f
+
+ /* Cause all currently waiting threads to recognize they are
+ woken up. */
+ movq %r9, wakeup_seq-cond_futex(%rdi)
+ movq %r9, woken_seq-cond_futex(%rdi)
+ addq %r9, %r9
+ movl %r9d, (%rdi)
+ incl broadcast_seq-cond_futex(%rdi)
+
+ /* Get the address of the mutex used. */
+ movq dep_mutex-cond_futex(%rdi), %r8
+
+ /* Unlock. */
+ LOCK
+ decl cond_lock-cond_futex(%rdi)
+ jne 7f
+
+8: cmpq $-1, %r8
+ je 9f
+
+ /* XXX: The kernel so far doesn't support requeue to PI futex. */
+ testl $PI_BIT, MUTEX_KIND(%r8)
+ jne 9f
+
+ /* Wake up all threads. */
+ movl $FUTEX_CMP_REQUEUE, %esi
+ movl $SYS_futex, %eax
+ movl $1, %edx
+ movl $0x7fffffff, %r10d
+ syscall
+
+ /* For any kind of error, which mainly is EAGAIN, we try again
+ with WAKE. The general test also covers running on old
+ kernels. */
+ cmpq $-4095, %rax
+ jae 9f
+
+10: xorl %eax, %eax
+ retq
+
+ .align 16
+ /* Unlock. */
+4: LOCK
+ decl cond_lock-cond_futex(%rdi)
+ jne 5f
+
+6: xorl %eax, %eax
+ retq
+
+ /* Initial locking failed. */
+1:
+#if cond_lock != 0
+ addq $cond_lock, %rdi
+#endif
+ callq __lll_mutex_lock_wait
+#if cond_lock != 0
+ subq $cond_lock, %rdi
+#endif
+ jmp 2b
+
+ /* Unlock in loop requires wakeup. */
+5: addq $cond_lock-cond_futex, %rdi
+ callq __lll_mutex_unlock_wake
+ jmp 6b
+
+ /* Unlock in loop requires wakeup. */
+7: addq $cond_lock-cond_futex, %rdi
+ callq __lll_mutex_unlock_wake
+ subq $cond_lock-cond_futex, %rdi
+ jmp 8b
+
+9: /* The futex requeue functionality is not available. */
+ movl $0x7fffffff, %edx
+ movl $FUTEX_WAKE, %esi
+ movl $SYS_futex, %eax
+ syscall
+ jmp 10b
+ .size __pthread_cond_broadcast, .-__pthread_cond_broadcast
+versioned_symbol (libpthread, __pthread_cond_broadcast, pthread_cond_broadcast,
+ GLIBC_2_3_2)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
new file mode 100644
index 000000000..3dbb9e81e
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
@@ -0,0 +1,127 @@
+/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <lowlevelcond.h>
+#include <kernel-features.h>
+
+#ifdef UP
+# define LOCK
+#else
+# define LOCK lock
+#endif
+
+#define SYS_futex 202
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+#define FUTEX_WAKE_OP 5
+
+#define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE ((4 << 24) | 1)
+
+#define EINVAL 22
+
+
+ .text
+
+ /* int pthread_cond_signal (pthread_cond_t *cond) */
+ .globl __pthread_cond_signal
+ .type __pthread_cond_signal, @function
+ .align 16
+__pthread_cond_signal:
+
+ /* Get internal lock. */
+ movq %rdi, %r8
+ movl $1, %esi
+ xorl %eax, %eax
+ LOCK
+#if cond_lock == 0
+ cmpxchgl %esi, (%rdi)
+#else
+ cmpxchgl %esi, cond_lock(%rdi)
+#endif
+ jnz 1f
+
+2: addq $cond_futex, %rdi
+ movq total_seq(%r8), %rcx
+ cmpq wakeup_seq(%r8), %rcx
+ jbe 4f
+
+ /* Bump the wakeup number. */
+ addq $1, wakeup_seq(%r8)
+ addl $1, (%rdi)
+
+ /* Wake up one thread. */
+ movl $FUTEX_WAKE_OP, %esi
+ movl $SYS_futex, %eax
+ movl $1, %edx
+ movl $1, %r10d
+#if cond_lock != 0
+ addq $cond_lock, %r8
+#endif
+ movl $FUTEX_OP_CLEAR_WAKE_IF_GT_ONE, %r9d
+ syscall
+#if cond_lock != 0
+ subq $cond_lock, %r8
+#endif
+ /* For any kind of error, we try again with WAKE.
+ The general test also covers running on old kernels. */
+ cmpq $-4095, %rax
+ jae 7f
+
+ xorl %eax, %eax
+ retq
+
+7: movl $FUTEX_WAKE, %esi
+ movl $SYS_futex, %eax
+ /* %rdx should be 1 already from $FUTEX_WAKE_OP syscall.
+ movl $1, %edx */
+ syscall
+
+ /* Unlock. */
+4: LOCK
+#if cond_lock == 0
+ decl (%r8)
+#else
+ decl cond_lock(%r8)
+#endif
+ jne 5f
+
+6: xorl %eax, %eax
+ retq
+
+ /* Initial locking failed. */
+1:
+#if cond_lock != 0
+ addq $cond_lock, %rdi
+#endif
+ callq __lll_mutex_lock_wait
+#if cond_lock != 0
+ subq $cond_lock, %rdi
+#endif
+ jmp 2b
+
+ /* Unlock in loop requires wakeup. */
+5:
+ movq %r8, %rdi
+ callq __lll_mutex_unlock_wake
+ jmp 6b
+ .size __pthread_cond_signal, .-__pthread_cond_signal
+versioned_symbol (libpthread, __pthread_cond_signal, pthread_cond_signal,
+ GLIBC_2_3_2)
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
new file mode 100644
index 000000000..ad3ae1e76
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
@@ -0,0 +1,470 @@
+/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <lowlevelcond.h>
+#include <pthread-errnos.h>
+
+#ifdef UP
+# define LOCK
+#else
+# define LOCK lock
+#endif
+
+#define SYS_futex 202
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+/* For the calculation see asm/vsyscall.h. */
+#define VSYSCALL_ADDR_vgettimeofday 0xffffffffff600000
+
+
+ .text
+
+/* int pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
+ const struct timespec *abstime) */
+ .globl __pthread_cond_timedwait
+ .type __pthread_cond_timedwait, @function
+ .align 16
+__pthread_cond_timedwait:
+.LSTARTCODE:
+ pushq %r12
+.Lpush_r12:
+ pushq %r13
+.Lpush_r13:
+ pushq %r14
+.Lpush_r14:
+#define FRAME_SIZE 80
+ subq $FRAME_SIZE, %rsp
+.Lsubq:
+
+ cmpq $1000000000, 8(%rdx)
+ movl $EINVAL, %eax
+ jae 18f
+
+ /* Stack frame:
+
+ rsp + 80
+ +--------------------------+
+ rsp + 48 | cleanup buffer |
+ +--------------------------+
+ rsp + 40 | old wake_seq value |
+ +--------------------------+
+ rsp + 24 | timeout value |
+ +--------------------------+
+ rsp + 16 | mutex pointer |
+ +--------------------------+
+ rsp + 8 | condvar pointer |
+ +--------------------------+
+ rsp + 4 | old broadcast_seq value |
+ +--------------------------+
+ rsp + 0 | old cancellation mode |
+ +--------------------------+
+ */
+
+ cmpq $-1, dep_mutex(%rdi)
+
+ /* Prepare structure passed to cancellation handler. */
+ movq %rdi, 8(%rsp)
+ movq %rsi, 16(%rsp)
+ movq %rdx, %r13
+
+ je 22f
+ movq %rsi, dep_mutex(%rdi)
+
+ /* Get internal lock. */
+22: movl $1, %esi
+ xorl %eax, %eax
+ LOCK
+#if cond_lock == 0
+ cmpxchgl %esi, (%rdi)
+#else
+ cmpxchgl %esi, cond_lock(%rdi)
+#endif
+ jnz 1f
+
+ /* Unlock the mutex. */
+2: movq 16(%rsp), %rdi
+ xorl %esi, %esi
+ callq __pthread_mutex_unlock_usercnt
+
+ testl %eax, %eax
+ jne 16f
+
+ movq 8(%rsp), %rdi
+ incq total_seq(%rdi)
+ incl cond_futex(%rdi)
+ addl $(1 << clock_bits), cond_nwaiters(%rdi)
+
+ /* Install cancellation handler. */
+#ifdef PIC
+ leaq __condvar_cleanup(%rip), %rsi
+#else
+ leaq __condvar_cleanup, %rsi
+#endif
+ leaq 48(%rsp), %rdi
+ movq %rsp, %rdx
+ callq __pthread_cleanup_push
+
+ /* Get and store current wakeup_seq value. */
+ movq 8(%rsp), %rdi
+ movq wakeup_seq(%rdi), %r9
+ movl broadcast_seq(%rdi), %edx
+ movq %r9, 40(%rsp)
+ movl %edx, 4(%rsp)
+
+ /* Get the current time. */
+8:
+#ifdef __NR_clock_gettime
+ /* Get the clock number. Note that the field in the condvar
+ structure stores the number minus 1. */
+ movq 8(%rsp), %rdi
+ movl cond_nwaiters(%rdi), %edi
+ andl $((1 << clock_bits) - 1), %edi
+ /* Only clocks 0 and 1 are allowed so far. Both are handled in the
+ kernel. */
+ leaq 24(%rsp), %rsi
+ movl $__NR_clock_gettime, %eax
+ syscall
+# ifndef __ASSUME_POSIX_TIMERS
+ cmpq $-ENOSYS, %rax
+ je 19f
+# endif
+
+ /* Compute relative timeout. */
+ movq (%r13), %rcx
+ movq 8(%r13), %rdx
+ subq 24(%rsp), %rcx
+ subq 32(%rsp), %rdx
+#else
+ leaq 24(%rsp), %rdi
+ xorl %esi, %esi
+ movq $VSYSCALL_ADDR_vgettimeofday, %rax
+ callq *%rax
+
+ /* Compute relative timeout. */
+ movq 32(%rsp), %rax
+ movl $1000, %edx
+ mul %rdx /* Milli seconds to nano seconds. */
+ movq (%r13), %rcx
+ movq 8(%r13), %rdx
+ subq 24(%rsp), %rcx
+ subq %rax, %rdx
+#endif
+ jns 12f
+ addq $1000000000, %rdx
+ decq %rcx
+12: testq %rcx, %rcx
+ movq 8(%rsp), %rdi
+ movq $-ETIMEDOUT, %r14
+ js 6f
+
+ /* Store relative timeout. */
+21: movq %rcx, 24(%rsp)
+ movq %rdx, 32(%rsp)
+
+ movl cond_futex(%rdi), %r12d
+
+ /* Unlock. */
+ LOCK
+#if cond_lock == 0
+ decl (%rdi)
+#else
+ decl cond_lock(%rdi)
+#endif
+ jne 3f
+
+4: callq __pthread_enable_asynccancel
+ movl %eax, (%rsp)
+
+ leaq 24(%rsp), %r10
+#if FUTEX_WAIT == 0
+ xorl %esi, %esi
+#else
+ movl $FUTEX_WAIT, %esi
+#endif
+ movq %r12, %rdx
+ addq $cond_futex, %rdi
+ movl $SYS_futex, %eax
+ syscall
+ movq %rax, %r14
+
+ movl (%rsp), %edi
+ callq __pthread_disable_asynccancel
+
+ /* Lock. */
+ movq 8(%rsp), %rdi
+ movl $1, %esi
+ xorl %eax, %eax
+ LOCK
+#if cond_lock == 0
+ cmpxchgl %esi, (%rdi)
+#else
+ cmpxchgl %esi, cond_lock(%rdi)
+#endif
+ jne 5f
+
+6: movl broadcast_seq(%rdi), %edx
+
+ movq woken_seq(%rdi), %rax
+
+ movq wakeup_seq(%rdi), %r9
+
+ cmpl 4(%rsp), %edx
+ jne 23f
+
+ cmpq 40(%rsp), %r9
+ jbe 15f
+
+ cmpq %rax, %r9
+ ja 9f
+
+15: cmpq $-ETIMEDOUT, %r14
+ jne 8b
+
+13: incq wakeup_seq(%rdi)
+ incl cond_futex(%rdi)
+ movl $ETIMEDOUT, %r14d
+ jmp 14f
+
+23: xorq %r14, %r14
+ jmp 24f
+
+9: xorq %r14, %r14
+14: incq woken_seq(%rdi)
+
+24: subl $(1 << clock_bits), cond_nwaiters(%rdi)
+
+ /* Wake up a thread which wants to destroy the condvar object. */
+ cmpq $0xffffffffffffffff, total_seq(%rdi)
+ jne 25f
+ movl cond_nwaiters(%rdi), %eax
+ andl $~((1 << clock_bits) - 1), %eax
+ jne 25f
+
+ addq $cond_nwaiters, %rdi
+ movl $SYS_futex, %eax
+ movl $FUTEX_WAKE, %esi
+ movl $1, %edx
+ syscall
+ subq $cond_nwaiters, %rdi
+
+25: LOCK
+#if cond_lock == 0
+ decl (%rdi)
+#else
+ decl cond_lock(%rdi)
+#endif
+ jne 10f
+
+ /* Remove cancellation handler. */
+11: movq 48+CLEANUP_PREV(%rsp), %rdx
+ movq %rdx, %fs:CLEANUP
+
+ movq 16(%rsp), %rdi
+ callq __pthread_mutex_cond_lock
+
+ testq %rax, %rax
+ cmoveq %r14, %rax
+
+18: addq $FRAME_SIZE, %rsp
+.Laddq:
+ popq %r14
+.Lpop_r14:
+ popq %r13
+.Lpop_r13:
+ popq %r12
+.Lpop_r12:
+
+ retq
+
+ /* Initial locking failed. */
+1:
+.LSbl1:
+#if cond_lock != 0
+ addq $cond_lock, %rdi
+#endif
+ callq __lll_mutex_lock_wait
+ jmp 2b
+
+ /* Unlock in loop requires wakeup. */
+3:
+#if cond_lock != 0
+ addq $cond_lock, %rdi
+#endif
+ callq __lll_mutex_unlock_wake
+ jmp 4b
+
+ /* Locking in loop failed. */
+5:
+#if cond_lock != 0
+ addq $cond_lock, %rdi
+#endif
+ callq __lll_mutex_lock_wait
+#if cond_lock != 0
+ subq $cond_lock, %rdi
+#endif
+ jmp 6b
+
+ /* Unlock after loop requires wakeup. */
+10:
+#if cond_lock != 0
+ addq $cond_lock, %rdi
+#endif
+ callq __lll_mutex_unlock_wake
+ jmp 11b
+
+ /* The initial unlocking of the mutex failed. */
+16: movq 8(%rsp), %rdi
+ movq %rax, (%rsp)
+ LOCK
+#if cond_lock == 0
+ decl (%rdi)
+#else
+ decl cond_lock(%rdi)
+#endif
+ jne 17f
+
+#if cond_lock != 0
+ addq $cond_lock, %rdi
+#endif
+ callq __lll_mutex_unlock_wake
+
+17: movq (%rsp), %rax
+ jmp 18b
+
+#if defined __NR_clock_gettime && !defined __ASSUME_POSIX_TIMERS
+ /* clock_gettime not available. */
+19: leaq 24(%rsp), %rdi
+ xorl %esi, %esi
+ movq $VSYSCALL_ADDR_vgettimeofday, %rax
+ callq *%rax
+
+ /* Compute relative timeout. */
+ movq 32(%rsp), %rax
+ movl $1000, %edx
+ mul %rdx /* Milli seconds to nano seconds. */
+ movq (%r13), %rcx
+ movq 8(%r13), %rdx
+ subq 24(%rsp), %rcx
+ subq %rax, %rdx
+ jns 20f
+ addq $1000000000, %rdx
+ decq %rcx
+20: testq %rcx, %rcx
+ movq 8(%rsp), %rdi
+ movq $-ETIMEDOUT, %r14
+ js 6b
+ jmp 21b
+#endif
+.LENDCODE:
+ .size __pthread_cond_timedwait, .-__pthread_cond_timedwait
+versioned_symbol (libpthread, __pthread_cond_timedwait, pthread_cond_timedwait,
+ GLIBC_2_3_2)
+
+
+ .section .eh_frame,"a",@progbits
+.LSTARTFRAME:
+ .long L(ENDCIE)-L(STARTCIE) # Length of the CIE.
+.LSTARTCIE:
+ .long 0 # CIE ID.
+ .byte 1 # Version number.
+#ifdef SHARED
+ .string "zR" # NUL-terminated augmentation
+ # string.
+#else
+ .ascii "\0" # NUL-terminated augmentation
+ # string.
+#endif
+ .uleb128 1 # Code alignment factor.
+ .sleb128 -8 # Data alignment factor.
+ .byte 16 # Return address register
+ # column.
+#ifdef SHARED
+ .uleb128 1 # Augmentation value length.
+ .byte 0x1b # Encoding: DW_EH_PE_pcrel
+ # + DW_EH_PE_sdata4.
+#endif
+ .byte 0x0c # DW_CFA_def_cfa
+ .uleb128 7
+ .uleb128 8
+ .byte 0x90 # DW_CFA_offset, column 0x8
+ .uleb128 1
+ .align 8
+.LENDCIE:
+
+ .long .LENDFDE-.LSTARTFDE # Length of the FDE.
+.LSTARTFDE:
+ .long .LSTARTFDE-.LSTARTFRAME # CIE pointer.
+#ifdef SHARED
+ .long .LSTARTCODE-. # PC-relative start address
+ # of the code
+#else
+ .long .LSTARTCODE # Start address of the code.
+#endif
+ .long .LENDCODE-.LSTARTCODE # Length of the code.
+#ifdef SHARED
+ .uleb128 0 # No augmentation data.
+#endif
+ .byte 0x40+.Lpush_r12-.LSTARTCODE # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 16
+ .byte 0x8c # DW_CFA_offset %r12
+ .uleb128 2
+ .byte 0x40+.Lpush_r13-.Lpush_r12 # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 24
+ .byte 0x8d # DW_CFA_offset %r13
+ .uleb128 3
+ .byte 0x40+.Lpush_r14-.Lpush_r13 # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 32
+ .byte 0x84 # DW_CFA_offset %r14
+ .uleb128 4
+ .byte 0x40+.Lsubq-.Lpush_r14 # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 32+FRAME_SIZE
+ .byte 3 # DW_CFA_advance_loc2
+ .2byte .Laddq-.Lsubq
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 32
+ .byte 0x40+.Lpop_r14-.Laddq # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 24
+ .byte 0xce # DW_CFA_restore %r14
+ .byte 0x40+.Lpop_r13-.Lpop_r14 # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 16
+ .byte 0xcd # DW_CFA_restore %r13
+ .byte 0x40+.Lpop_r12-.Lpop_r13 # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 8
+ .byte 0xcc # DW_CFA_restore %r12
+ .byte 0x40+.LSbl1-.Lpop_r12 # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 32+FRAME_SIZE
+ .byte 0x8c # DW_CFA_offset %r12
+ .uleb128 2
+ .byte 0x8d # DW_CFA_offset %r13
+ .uleb128 3
+ .byte 0x84 # DW_CFA_offset %r14
+ .uleb128 4
+ .align 8
+.LENDFDE:
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
new file mode 100644
index 000000000..b837d466b
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
@@ -0,0 +1,423 @@
+/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <lowlevelcond.h>
+#include <tcb-offsets.h>
+
+#ifdef UP
+# define LOCK
+#else
+# define LOCK lock
+#endif
+
+#define SYS_futex 202
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+
+ .text
+
+ .align 16
+ .type __condvar_cleanup, @function
+ .globl __condvar_cleanup
+ .hidden __condvar_cleanup
+__condvar_cleanup:
+ pushq %r12
+
+ /* Get internal lock. */
+ movq %rdi, %r8
+ movq 8(%rdi), %rdi
+ movl $1, %esi
+ xorl %eax, %eax
+ LOCK
+#if cond_lock == 0
+ cmpxchgl %esi, (%rdi)
+#else
+ cmpxchgl %esi, cond_lock(%rdi)
+#endif
+ jz 1f
+
+#if cond_lock != 0
+ addq $cond_lock, %rdi
+#endif
+ callq __lll_mutex_lock_wait
+#if cond_lock != 0
+ subq $cond_lock, %rdi
+#endif
+
+1: movl broadcast_seq(%rdi), %edx
+ cmpl 4(%r8), %edx
+ jne 3f
+
+ incq wakeup_seq(%rdi)
+ incq woken_seq(%rdi)
+ incl cond_futex(%rdi)
+
+3: subl $(1 << clock_bits), cond_nwaiters(%rdi)
+
+ /* Wake up a thread which wants to destroy the condvar object. */
+ xorq %r12, %r12
+ cmpq $0xffffffffffffffff, total_seq(%rdi)
+ jne 4f
+ movl cond_nwaiters(%rdi), %eax
+ andl $~((1 << clock_bits) - 1), %eax
+ jne 4f
+
+ addq $cond_nwaiters, %rdi
+ movl $SYS_futex, %eax
+ movl $FUTEX_WAKE, %esi
+ movl $1, %edx
+ syscall
+ subq $cond_nwaiters, %rdi
+ movl $1, %r12d
+
+4: LOCK
+#if cond_lock == 0
+ decl (%rdi)
+#else
+ decl cond_lock(%rdi)
+#endif
+ je 2f
+#if cond_lock != 0
+ addq $cond_lock, %rdi
+#endif
+ callq __lll_mutex_unlock_wake
+
+ /* Wake up all waiters to make sure no signal gets lost. */
+2: testq %r12, %r12
+ jnz 5f
+ addq $cond_futex, %rdi
+ movl $FUTEX_WAKE, %esi
+ movl $0x7fffffff, %edx
+ movl $SYS_futex, %eax
+ syscall
+
+5: movq 16(%r8), %rdi
+ callq __pthread_mutex_cond_lock
+
+ popq %r12
+
+ retq
+ .size __condvar_cleanup, .-__condvar_cleanup
+
+
+/* int pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex) */
+ .globl __pthread_cond_wait
+ .type __pthread_cond_wait, @function
+ .align 16
+__pthread_cond_wait:
+.LSTARTCODE:
+ pushq %r12
+.Lpush_r12:
+#define FRAME_SIZE 64
+ subq $FRAME_SIZE, %rsp
+.Lsubq:
+ /* Stack frame:
+
+ rsp + 64
+ +--------------------------+
+ rsp + 32 | cleanup buffer |
+ +--------------------------+
+ rsp + 24 | old wake_seq value |
+ +--------------------------+
+ rsp + 16 | mutex pointer |
+ +--------------------------+
+ rsp + 8 | condvar pointer |
+ +--------------------------+
+ rsp + 4 | old broadcast_seq value |
+ +--------------------------+
+ rsp + 0 | old cancellation mode |
+ +--------------------------+
+ */
+
+ cmpq $-1, dep_mutex(%rdi)
+
+ /* Prepare structure passed to cancellation handler. */
+ movq %rdi, 8(%rsp)
+ movq %rsi, 16(%rsp)
+
+ je 15f
+ movq %rsi, dep_mutex(%rdi)
+
+ /* Get internal lock. */
+15: movl $1, %esi
+ xorl %eax, %eax
+ LOCK
+#if cond_lock == 0
+ cmpxchgl %esi, (%rdi)
+#else
+ cmpxchgl %esi, cond_lock(%rdi)
+#endif
+ jne 1f
+
+ /* Unlock the mutex. */
+2: movq 16(%rsp), %rdi
+ xorl %esi, %esi
+ callq __pthread_mutex_unlock_usercnt
+
+ testl %eax, %eax
+ jne 12f
+
+ movq 8(%rsp), %rdi
+ incq total_seq(%rdi)
+ incl cond_futex(%rdi)
+ addl $(1 << clock_bits), cond_nwaiters(%rdi)
+
+ /* Install cancellation handler. */
+#ifdef PIC
+ leaq __condvar_cleanup(%rip), %rsi
+#else
+ leaq __condvar_cleanup, %rsi
+#endif
+ leaq 32(%rsp), %rdi
+ movq %rsp, %rdx
+ callq __pthread_cleanup_push
+
+ /* Get and store current wakeup_seq value. */
+ movq 8(%rsp), %rdi
+ movq wakeup_seq(%rdi), %r9
+ movl broadcast_seq(%rdi), %edx
+ movq %r9, 24(%rsp)
+ movl %edx, 4(%rsp)
+
+ /* Unlock. */
+8: movl cond_futex(%rdi), %r12d
+ LOCK
+#if cond_lock == 0
+ decl (%rdi)
+#else
+ decl cond_lock(%rdi)
+#endif
+ jne 3f
+
+4: callq __pthread_enable_asynccancel
+ movl %eax, (%rsp)
+
+ movq 8(%rsp), %rdi
+ xorq %r10, %r10
+ movq %r12, %rdx
+ addq $cond_futex-cond_lock, %rdi
+ movl $SYS_futex, %eax
+#if FUTEX_WAIT == 0
+ xorl %esi, %esi
+#else
+ movl $FUTEX_WAIT, %esi
+#endif
+ syscall
+
+ movl (%rsp), %edi
+ callq __pthread_disable_asynccancel
+
+ /* Lock. */
+ movq 8(%rsp), %rdi
+ movl $1, %esi
+ xorl %eax, %eax
+ LOCK
+#if cond_lock == 0
+ cmpxchgl %esi, (%rdi)
+#else
+ cmpxchgl %esi, cond_lock(%rdi)
+#endif
+ jnz 5f
+
+6: movl broadcast_seq(%rdi), %edx
+
+ movq woken_seq(%rdi), %rax
+
+ movq wakeup_seq(%rdi), %r9
+
+ cmpl 4(%rsp), %edx
+ jne 16f
+
+ cmpq 24(%rsp), %r9
+ jbe 8b
+
+ cmpq %rax, %r9
+ jna 8b
+
+ incq woken_seq(%rdi)
+
+ /* Unlock */
+16: subl $(1 << clock_bits), cond_nwaiters(%rdi)
+
+ /* Wake up a thread which wants to destroy the condvar object. */
+ cmpq $0xffffffffffffffff, total_seq(%rdi)
+ jne 17f
+ movl cond_nwaiters(%rdi), %eax
+ andl $~((1 << clock_bits) - 1), %eax
+ jne 17f
+
+ addq $cond_nwaiters, %rdi
+ movl $SYS_futex, %eax
+ movl $FUTEX_WAKE, %esi
+ movl $1, %edx
+ syscall
+ subq $cond_nwaiters, %rdi
+
+17: LOCK
+#if cond_lock == 0
+ decl (%rdi)
+#else
+ decl cond_lock(%rdi)
+#endif
+ jne 10f
+
+ /* Remove cancellation handler. */
+11: movq 32+CLEANUP_PREV(%rsp), %rdx
+ movq %rdx, %fs:CLEANUP
+
+ movq 16(%rsp), %rdi
+ callq __pthread_mutex_cond_lock
+14: addq $FRAME_SIZE, %rsp
+.Laddq:
+
+ popq %r12
+.Lpop_r12:
+
+ /* We return the result of the mutex_lock operation. */
+ retq
+
+ /* Initial locking failed. */
+1:
+.LSbl1:
+#if cond_lock != 0
+ addq $cond_lock, %rdi
+#endif
+ callq __lll_mutex_lock_wait
+ jmp 2b
+
+ /* Unlock in loop requires wakeup. */
+3:
+#if cond_lock != 0
+ addq $cond_lock, %rdi
+#endif
+ callq __lll_mutex_unlock_wake
+ jmp 4b
+
+ /* Locking in loop failed. */
+5:
+#if cond_lock != 0
+ addq $cond_lock, %rdi
+#endif
+ callq __lll_mutex_lock_wait
+#if cond_lock != 0
+ subq $cond_lock, %rdi
+#endif
+ jmp 6b
+
+ /* Unlock after loop requires wakeup. */
+10:
+#if cond_lock != 0
+ addq $cond_lock, %rdi
+#endif
+ callq __lll_mutex_unlock_wake
+ jmp 11b
+
+ /* The initial unlocking of the mutex failed. */
+12: movq %rax, %r10
+ movq 8(%rsp), %rdi
+ LOCK
+#if cond_lock == 0
+ decl (%rdi)
+#else
+ decl cond_lock(%rdi)
+#endif
+ jne 13f
+
+#if cond_lock != 0
+ addq $cond_lock, %rdi
+#endif
+ callq __lll_mutex_unlock_wake
+
+13: movq %r10, %rax
+ jmp 14b
+.LENDCODE:
+ .size __pthread_cond_wait, .-__pthread_cond_wait
+versioned_symbol (libpthread, __pthread_cond_wait, pthread_cond_wait,
+ GLIBC_2_3_2)
+
+
+ .section .eh_frame,"a",@progbits
+.LSTARTFRAME:
+ .long L(ENDCIE)-L(STARTCIE) # Length of the CIE.
+.LSTARTCIE:
+ .long 0 # CIE ID.
+ .byte 1 # Version number.
+#ifdef SHARED
+ .string "zR" # NUL-terminated augmentation
+ # string.
+#else
+ .ascii "\0" # NUL-terminated augmentation
+ # string.
+#endif
+ .uleb128 1 # Code alignment factor.
+ .sleb128 -8 # Data alignment factor.
+ .byte 16 # Return address register
+ # column.
+#ifdef SHARED
+ .uleb128 1 # Augmentation value length.
+ .byte 0x1b # Encoding: DW_EH_PE_pcrel
+ # + DW_EH_PE_sdata4.
+#endif
+ .byte 0x0c # DW_CFA_def_cfa
+ .uleb128 7
+ .uleb128 8
+ .byte 0x90 # DW_CFA_offset, column 0x8
+ .uleb128 1
+ .align 8
+.LENDCIE:
+
+ .long .LENDFDE-.LSTARTFDE # Length of the FDE.
+.LSTARTFDE:
+ .long .LSTARTFDE-.LSTARTFRAME # CIE pointer.
+#ifdef SHARED
+ .long .LSTARTCODE-. # PC-relative start address
+ # of the code
+#else
+ .long .LSTARTCODE # Start address of the code.
+#endif
+ .long .LENDCODE-.LSTARTCODE # Length of the code.
+#ifdef SHARED
+ .uleb128 0 # No augmentation data.
+#endif
+ .byte 0x40+.Lpush_r12-.LSTARTCODE # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 16
+ .byte 0x8c # DW_CFA_offset %r12
+ .uleb128 2
+ .byte 0x40+.Lsubq-.Lpush_r12 # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 16+FRAME_SIZE
+ .byte 3 # DW_CFA_advance_loc2
+ .2byte .Laddq-.Lsubq
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 16
+ .byte 0x40+.Lpop_r12-.Laddq # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 8
+ .byte 0xcc # DW_CFA_restore %r12
+ .byte 0x40+.LSbl1-.Lpop_r12 # DW_CFA_advance_loc+N
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 80
+ .byte 0x8c # DW_CFA_offset %r12
+ .uleb128 2
+ .align 8
+.LENDFDE:
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
new file mode 100644
index 000000000..9db551691
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
@@ -0,0 +1,270 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+#ifndef UP
+# define LOCK lock
+#else
+# define LOCK
+#endif
+
+#define SYS_futex 202
+#define FUTEX_WAKE 1
+
+ .comm __fork_generation, 4, 4
+
+ .text
+
+
+ .globl __pthread_once
+ .type __pthread_once,@function
+ .align 16
+__pthread_once:
+.LSTARTCODE:
+ testl $2, (%rdi)
+ jz 1f
+ xorl %eax, %eax
+ retq
+
+ /* Preserve the function pointer. */
+1: pushq %rsi
+.Lpush_rsi:
+ xorq %r10, %r10
+
+ /* Not yet initialized or initialization in progress.
+ Get the fork generation counter now. */
+6: movl (%rdi), %eax
+
+5: movl %eax, %edx
+
+ testl $2, %eax
+ jnz 4f
+
+ andl $3, %edx
+ orl __fork_generation(%rip), %edx
+ orl $1, %edx
+
+ LOCK
+ cmpxchgl %edx, (%rdi)
+ jnz 5b
+
+ /* Check whether another thread already runs the initializer. */
+ testl $1, %eax
+ jz 3f /* No -> do it. */
+
+ /* Check whether the initializer execution was interrupted
+ by a fork. */
+ xorl %edx, %eax
+ testl $0xfffffffc, %eax
+ jnz 3f /* Different for generation -> run initializer. */
+
+ /* Somebody else got here first. Wait. */
+#if FUTEX_WAIT == 0
+ xorl %esi, %esi
+#else
+ movl $FUTEX_WAIT, %esi
+#endif
+ movl $SYS_futex, %eax
+ syscall
+ jmp 6b
+
+ /* Preserve the pointer to the control variable. */
+3: pushq %rdi
+.Lpush_rdi:
+ pushq %rdi
+.Lpush_rdi2:
+
+.LcleanupSTART:
+ callq *16(%rsp)
+.LcleanupEND:
+
+ /* Get the control variable address back. */
+ popq %rdi
+.Lpop_rdi:
+
+ /* Sucessful run of the initializer. Signal that we are done. */
+ LOCK
+ incl (%rdi)
+
+ addq $8, %rsp
+.Ladd1:
+
+ /* Wake up all other threads. */
+ movl $0x7fffffff, %edx
+ movl $FUTEX_WAKE, %esi
+ movl $SYS_futex, %eax
+ syscall
+
+4: addq $8, %rsp
+.Ladd2:
+ xorl %eax, %eax
+ retq
+
+ .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:
+ movq (%rsp), %rdi
+ movq %rax, %r8
+ movl $0, (%rdi)
+
+ movl $0x7fffffff, %edx
+ movl $FUTEX_WAKE, %esi
+ movl $SYS_futex, %eax
+ syscall
+
+ movq %r8, %rdi
+.LcallUR:
+ call _Unwind_Resume@PLT
+ hlt
+.LENDCODE:
+ .size clear_once_control,.-clear_once_control
+
+
+ .section .gcc_except_table,"a",@progbits
+.LexceptSTART:
+ .byte 0xff # @LPStart format (omit)
+ .byte 0xff # @TType format (omit)
+ .byte 0x01 # call-site format
+ # DW_EH_PE_uleb128
+ .uleb128 .Lcstend-.Lcstbegin
+.Lcstbegin:
+ .uleb128 .LcleanupSTART-.LSTARTCODE
+ .uleb128 .LcleanupEND-.LcleanupSTART
+ .uleb128 clear_once_control-.LSTARTCODE
+ .uleb128 0
+ .uleb128 .LcallUR-.LSTARTCODE
+ .uleb128 .LENDCODE-.LcallUR
+ .uleb128 0
+ .uleb128 0
+.Lcstend:
+
+
+ .section .eh_frame,"a",@progbits
+.LSTARTFRAME:
+ .long .LENDCIE-.LSTARTCIE # Length of the CIE.
+.LSTARTCIE:
+ .long 0 # CIE ID.
+ .byte 1 # Version number.
+#ifdef SHARED
+ .string "zPLR" # NUL-terminated augmentation
+ # string.
+#else
+ .string "zPL" # NUL-terminated augmentation
+ # string.
+#endif
+ .uleb128 1 # Code alignment factor.
+ .sleb128 -8 # Data alignment factor.
+ .byte 16 # Return address register
+ # column.
+#ifdef SHARED
+ .uleb128 7 # Augmentation value length.
+ .byte 0x9b # Personality: DW_EH_PE_pcrel
+ # + DW_EH_PE_sdata4
+ # + DW_EH_PE_indirect
+ .long DW.ref.__gcc_personality_v0-.
+ .byte 0x1b # LSDA Encoding: DW_EH_PE_pcrel
+ # + DW_EH_PE_sdata4.
+ .byte 0x1b # FDE Encoding: DW_EH_PE_pcrel
+ # + DW_EH_PE_sdata4.
+#else
+ .uleb128 10 # Augmentation value length.
+ .byte 0x0 # Personality: absolute
+ .quad __gcc_personality_v0
+ .byte 0x0 # LSDA Encoding: absolute
+#endif
+ .byte 0x0c # DW_CFA_def_cfa
+ .uleb128 7
+ .uleb128 8
+ .byte 0x90 # DW_CFA_offset, column 0x10
+ .uleb128 1
+ .align 8
+.LENDCIE:
+
+ .long .LENDFDE-.LSTARTFDE # Length of the FDE.
+.LSTARTFDE:
+ .long .LSTARTFDE-.LSTARTFRAME # CIE pointer.
+#ifdef SHARED
+ .long .LSTARTCODE-. # PC-relative start address
+ # of the code.
+ .long .LENDCODE-.LSTARTCODE # Length of the code.
+ .uleb128 4 # Augmentation size
+ .long .LexceptSTART-.
+#else
+ .quad .LSTARTCODE # Start address of the code.
+ .quad .LENDCODE-.LSTARTCODE # Length of the code.
+ .uleb128 8 # Augmentation size
+ .quad .LexceptSTART
+#endif
+ .byte 4 # DW_CFA_advance_loc4
+ .long .Lpush_rsi-.LSTARTCODE
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 16
+ .byte 4 # DW_CFA_advance_loc4
+ .long .Lpush_rdi-.Lpush_rsi
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 24
+ .byte 4 # DW_CFA_advance_loc4
+ .long .Lpush_rdi2-.Lpush_rdi
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 32
+ .byte 4 # DW_CFA_advance_loc4
+ .long .Lpop_rdi-.Lpush_rdi2
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 24
+ .byte 4 # DW_CFA_advance_loc4
+ .long .Ladd1-.Lpop_rdi
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 16
+ .byte 4 # DW_CFA_advance_loc4
+ .long .Ladd2-.Ladd1
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 8
+ .byte 4 # DW_CFA_advance_loc4
+ .long clear_once_control-.Ladd2
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 32
+#if 0
+ .byte 4 # DW_CFA_advance_loc4
+ .long .Lpop_rdi3-clear_once_control
+ .byte 14 # DW_CFA_def_cfa_offset
+ .uleb128 16
+#endif
+ .align 8
+.LENDFDE:
+
+
+#ifdef SHARED
+ .hidden DW.ref.__gcc_personality_v0
+ .weak DW.ref.__gcc_personality_v0
+ .section .gnu.linkonce.d.DW.ref.__gcc_personality_v0,"aw",@progbits
+ .align 8
+ .type DW.ref.__gcc_personality_v0, @object
+ .size DW.ref.__gcc_personality_v0, 8
+DW.ref.__gcc_personality_v0:
+ .quad __gcc_personality_v0
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S
new file mode 100644
index 000000000..5e9d8fb1d
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S
@@ -0,0 +1,177 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <lowlevelrwlock.h>
+#include <pthread-errnos.h>
+
+
+#define SYS_futex 202
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+#ifndef UP
+# define LOCK lock
+#else
+# define LOCK
+#endif
+
+
+ .text
+
+ .globl __pthread_rwlock_rdlock
+ .type __pthread_rwlock_rdlock,@function
+ .align 16
+__pthread_rwlock_rdlock:
+ xorq %r10, %r10
+
+ /* Get the lock. */
+ movl $1, %esi
+ xorl %eax, %eax
+ LOCK
+#if MUTEX == 0
+ cmpxchgl %esi, (%rdi)
+#else
+ cmpxchgl %esi, MUTEX(%rdi)
+#endif
+ jnz 1f
+
+2: movl WRITER(%rdi), %eax
+ testl %eax, %eax
+ jne 14f
+ cmpl $0, WRITERS_QUEUED(%rdi)
+ je 5f
+ cmpl $0, FLAGS(%rdi)
+ je 5f
+
+3: incl READERS_QUEUED(%rdi)
+ je 4f
+
+ movl READERS_WAKEUP(%rdi), %edx
+
+ LOCK
+#if MUTEX == 0
+ decl (%rdi)
+#else
+ decl MUTEX(%rdi)
+#endif
+ jne 10f
+
+11: addq $READERS_WAKEUP, %rdi
+#if FUTEX_WAIT == 0
+ xorl %esi, %esi
+#else
+ movl $FUTEX_WAIT, %esi
+#endif
+ movl $SYS_futex, %eax
+ syscall
+
+ subq $READERS_WAKEUP, %rdi
+
+ /* Reget the lock. */
+ movl $1, %esi
+ xorl %eax, %eax
+ LOCK
+#if MUTEX == 0
+ cmpxchgl %esi, (%rdi)
+#else
+ cmpxchgl %esi, MUTEX(%rdi)
+#endif
+ jnz 12f
+
+13: decl READERS_QUEUED(%rdi)
+ jmp 2b
+
+5: xorl %edx, %edx
+ incl NR_READERS(%rdi)
+ je 8f
+9: LOCK
+#if MUTEX == 0
+ decl (%rdi)
+#else
+ decl MUTEX(%rdi)
+#endif
+ jne 6f
+7:
+
+ movq %rdx, %rax
+ retq
+
+1:
+#if MUTEX != 0
+ addq $MUTEX, %rdi
+#endif
+ callq __lll_mutex_lock_wait
+#if MUTEX != 0
+ subq $MUTEX, %rdi
+#endif
+ jmp 2b
+
+14: cmpl %fs:TID, %eax
+ jne 3b
+ /* Deadlock detected. */
+ movl $EDEADLK, %edx
+ jmp 9b
+
+6:
+#if MUTEX != 0
+ addq $MUTEX, %rdi
+#endif
+ callq __lll_mutex_unlock_wake
+#if MUTEX != 0
+ subq $MUTEX, %rdi
+#endif
+ jmp 7b
+
+ /* Overflow. */
+8: decl NR_READERS(%rdi)
+ movl $EAGAIN, %edx
+ jmp 9b
+
+ /* Overflow. */
+4: decl READERS_QUEUED(%rdi)
+ movl $EAGAIN, %edx
+ jmp 9b
+
+10:
+#if MUTEX != 0
+ addq $MUTEX, %rdi
+#endif
+ callq __lll_mutex_unlock_wake
+#if MUTEX != 0
+ subq $MUTEX, %rdi
+#endif
+ jmp 11b
+
+12:
+#if MUTEX == 0
+ addq $MUTEX, %rdi
+#endif
+ callq __lll_mutex_lock_wait
+#if MUTEX != 0
+ subq $MUTEX, %rdi
+#endif
+ jmp 13b
+ .size __pthread_rwlock_rdlock,.-__pthread_rwlock_rdlock
+
+ .globl pthread_rwlock_rdlock
+pthread_rwlock_rdlock = __pthread_rwlock_rdlock
+
+ .globl __pthread_rwlock_rdlock_internal
+__pthread_rwlock_rdlock_internal = __pthread_rwlock_rdlock
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
new file mode 100644
index 000000000..b44660418
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
@@ -0,0 +1,220 @@
+/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <lowlevelrwlock.h>
+#include <pthread-errnos.h>
+
+
+#define SYS_futex 202
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+/* For the calculation see asm/vsyscall.h. */
+#define VSYSCALL_ADDR_vgettimeofday 0xffffffffff600000
+
+
+#ifndef UP
+# define LOCK lock
+#else
+# define LOCK
+#endif
+
+
+ .text
+
+ .globl pthread_rwlock_timedrdlock
+ .type pthread_rwlock_timedrdlock,@function
+ .align 16
+pthread_rwlock_timedrdlock:
+ pushq %r12
+ pushq %r13
+ pushq %r14
+ subq $16, %rsp
+
+ movq %rdi, %r12
+ movq %rsi, %r13
+
+ /* Get the lock. */
+ movl $1, %esi
+ xorl %eax, %eax
+ LOCK
+#if MUTEX == 0
+ cmpxchgl %esi, (%rdi)
+#else
+ cmpxchgl %esi, MUTEX(%rdi)
+#endif
+ jnz 1f
+
+2: movl WRITER(%r12), %eax
+ testl %eax, %eax
+ jne 14f
+ cmpl $0, WRITERS_QUEUED(%r12)
+ je 5f
+ cmpl $0, FLAGS(%r12)
+ je 5f
+
+ /* Check the value of the timeout parameter. */
+3: cmpq $1000000000, 8(%r13)
+ jae 19f
+
+ incl READERS_QUEUED(%r12)
+ je 4f
+
+ movl READERS_WAKEUP(%r12), %r14d
+
+ /* Unlock. */
+ LOCK
+#if MUTEX == 0
+ decl (%r12)
+#else
+ decl MUTEX(%r12)
+#endif
+ jne 10f
+
+ /* Get current time. */
+11: movq %rsp, %rdi
+ xorl %esi, %esi
+ movq $VSYSCALL_ADDR_vgettimeofday, %rax
+ callq *%rax
+
+ /* Compute relative timeout. */
+ movq 8(%rsp), %rax
+ movl $1000, %edi
+ mul %rdi /* Milli seconds to nano seconds. */
+ movq (%r13), %rcx
+ movq 8(%r13), %rdi
+ subq (%rsp), %rcx
+ subq %rax, %rdi
+ jns 15f
+ addq $1000000000, %rdi
+ decq %rcx
+15: testq %rcx, %rcx
+ js 16f /* Time is already up. */
+
+ /* Futex call. */
+ movq %rcx, (%rsp) /* Store relative timeout. */
+ movq %rdi, 8(%rsp)
+
+#if FUTEX_WAIT == 0
+ xorl %esi, %esi
+#else
+ movl $FUTEX_WAIT, %esi
+#endif
+ movq %rsp, %r10
+ movl %r14d, %edx
+ leaq READERS_WAKEUP(%r12), %rdi
+ movl $SYS_futex, %eax
+ syscall
+ movq %rax, %rdx
+17:
+
+ /* Reget the lock. */
+ movl $1, %esi
+ xorl %eax, %eax
+ LOCK
+#if MUTEX == 0
+ cmpxchgl %esi, (%r12)
+#else
+ cmpxchgl %esi, MUTEX(%r12)
+#endif
+ jnz 12f
+
+13: decl READERS_QUEUED(%r12)
+ cmpq $-ETIMEDOUT, %rdx
+ jne 2b
+
+18: movl $ETIMEDOUT, %edx
+ jmp 9f
+
+
+5: xorl %edx, %edx
+ incl NR_READERS(%r12)
+ je 8f
+9: LOCK
+#if MUTEX == 0
+ decl (%r12)
+#else
+ decl MUTEX(%r12)
+#endif
+ jne 6f
+
+7: movq %rdx, %rax
+
+ addq $16, %rsp
+ popq %r14
+ popq %r13
+ popq %r12
+ retq
+
+1:
+#if MUTEX != 0
+ addq $MUTEX, %rdi
+#endif
+ callq __lll_mutex_lock_wait
+ jmp 2b
+
+14: cmpl %fs:TID, %eax
+ jne 3b
+ movl $EDEADLK, %edx
+ jmp 9b
+
+6:
+#if MUTEX == 0
+ movq %r12, %rdi
+#else
+ leal MUTEX(%r12), %rdi
+#endif
+ callq __lll_mutex_unlock_wake
+ jmp 7b
+
+ /* Overflow. */
+8: decl NR_READERS(%r12)
+ movl $EAGAIN, %edx
+ jmp 9b
+
+ /* Overflow. */
+4: decl READERS_QUEUED(%r12)
+ movl $EAGAIN, %edx
+ jmp 9b
+
+10:
+#if MUTEX == 0
+ movq %r12, %rdi
+#else
+ leaq MUTEX(%r12), %rdi
+#endif
+ callq __lll_mutex_unlock_wake
+ jmp 11b
+
+12:
+#if MUTEX == 0
+ movq %r12, %rdi
+#else
+ leaq MUTEX(%r12), %rdi
+#endif
+ callq __lll_mutex_lock_wait
+ jmp 13b
+
+16: movq $-ETIMEDOUT, %rdx
+ jmp 17b
+
+19: movl $EINVAL, %edx
+ jmp 9b
+ .size pthread_rwlock_timedrdlock,.-pthread_rwlock_timedrdlock
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
new file mode 100644
index 000000000..525e5b6b9
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
@@ -0,0 +1,211 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <lowlevelrwlock.h>
+#include <pthread-errnos.h>
+
+
+#define SYS_futex 202
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+/* For the calculation see asm/vsyscall.h. */
+#define VSYSCALL_ADDR_vgettimeofday 0xffffffffff600000
+
+#ifndef UP
+# define LOCK lock
+#else
+# define LOCK
+#endif
+
+
+ .text
+
+ .globl pthread_rwlock_timedwrlock
+ .type pthread_rwlock_timedwrlock,@function
+ .align 16
+pthread_rwlock_timedwrlock:
+ pushq %r12
+ pushq %r13
+ pushq %r14
+ subq $16, %rsp
+
+ movq %rdi, %r12
+ movq %rsi, %r13
+
+ /* Get the lock. */
+ movl $1, %esi
+ xorl %eax, %eax
+ LOCK
+#if MUTEX == 0
+ cmpxchgl %esi, (%rdi)
+#else
+ cmpxchgl %esi, MUTEX(%rdi)
+#endif
+ jnz 1f
+
+2: movl WRITER(%r12), %eax
+ testl %eax, %eax
+ jne 14f
+ cmpl $0, NR_READERS(%r12)
+ je 5f
+
+ /* Check the value of the timeout parameter. */
+3: cmpq $1000000000, 8(%r13)
+ jae 19f
+
+ incl WRITERS_QUEUED(%r12)
+ je 4f
+
+ movl WRITERS_WAKEUP(%r12), %r14d
+
+ LOCK
+#if MUTEX == 0
+ decl (%r12)
+#else
+ decl MUTEX(%r12)
+#endif
+ jne 10f
+
+ /* Get current time. */
+11: movq %rsp, %rdi
+ xorl %esi, %esi
+ movq $VSYSCALL_ADDR_vgettimeofday, %rax
+ callq *%rax
+
+ /* Compute relative timeout. */
+ movq 8(%rsp), %rax
+ movl $1000, %edi
+ mul %rdi /* Milli seconds to nano seconds. */
+ movq (%r13), %rcx
+ movq 8(%r13), %rdi
+ subq (%rsp), %rcx
+ subq %rax, %rdi
+ jns 15f
+ addq $1000000000, %rdi
+ decq %rcx
+15: testq %rcx, %rcx
+ js 16f /* Time is already up. */
+
+ /* Futex call. */
+ movq %rcx, (%rsp) /* Store relative timeout. */
+ movq %rdi, 8(%rsp)
+
+#if FUTEX_WAIT == 0
+ xorl %esi, %esi
+#else
+ movl $FUTEX_WAIT, %esi
+#endif
+ movq %rsp, %r10
+ movl %r14d, %edx
+ leaq WRITERS_WAKEUP(%r12), %rdi
+ movl $SYS_futex, %eax
+ syscall
+ movq %rax, %rdx
+17:
+
+ /* Reget the lock. */
+ movl $1, %esi
+ xorl %eax, %eax
+ LOCK
+#if MUTEX == 0
+ cmpxchgl %esi, (%r12)
+#else
+ cmpxchgl %esi, MUTEX(%r12)
+#endif
+ jnz 12f
+
+13: decl WRITERS_QUEUED(%r12)
+ cmpq $-ETIMEDOUT, %rdx
+ jne 2b
+
+18: movl $ETIMEDOUT, %edx
+ jmp 9f
+
+
+5: xorl %edx, %edx
+ movl %fs:TID, %eax
+ movl %eax, WRITER(%r12)
+9: LOCK
+#if MUTEX == 0
+ decl (%r12)
+#else
+ decl MUTEX(%r12)
+#endif
+ jne 6f
+
+7: movq %rdx, %rax
+
+ addq $16, %rsp
+ popq %r14
+ popq %r13
+ popq %r12
+ retq
+
+1:
+#if MUTEX != 0
+ addq $MUTEX, %rdi
+#endif
+ callq __lll_mutex_lock_wait
+ jmp 2b
+
+14: cmpl %fs:TID, %eax
+ jne 3b
+20: movl $EDEADLK, %edx
+ jmp 9b
+
+6:
+#if MUTEX == 0
+ movq %r12, %rdi
+#else
+ leal MUTEX(%r12), %rdi
+#endif
+ callq __lll_mutex_unlock_wake
+ jmp 7b
+
+ /* Overflow. */
+4: decl WRITERS_QUEUED(%r12)
+ movl $EAGAIN, %edx
+ jmp 9b
+
+10:
+#if MUTEX == 0
+ movq %r12, %rdi
+#else
+ leaq MUTEX(%r12), %rdi
+#endif
+ callq __lll_mutex_unlock_wake
+ jmp 11b
+
+12:
+#if MUTEX == 0
+ movq %r12, %rdi
+#else
+ leaq MUTEX(%r12), %rdi
+#endif
+ callq __lll_mutex_lock_wait
+ jmp 13b
+
+16: movq $-ETIMEDOUT, %rdx
+ jmp 17b
+
+19: movl $EINVAL, %edx
+ jmp 9b
+ .size pthread_rwlock_timedwrlock,.-pthread_rwlock_timedwrlock
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
new file mode 100644
index 000000000..3a6b9f0ba
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
@@ -0,0 +1,130 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <lowlevelrwlock.h>
+
+
+#define SYS_futex 202
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+#ifndef UP
+# define LOCK lock
+#else
+# define LOCK
+#endif
+
+
+ .text
+
+ .globl __pthread_rwlock_unlock
+ .type __pthread_rwlock_unlock,@function
+ .align 16
+__pthread_rwlock_unlock:
+ /* Get the lock. */
+ movl $1, %esi
+ xorl %eax, %eax
+ LOCK
+#if MUTEX == 0
+ cmpxchgl %esi, (%rdi)
+#else
+ cmpxchgl %esi, MUTEX(%rdi)
+#endif
+ jnz 1f
+
+2: cmpl $0, WRITER(%rdi)
+ jne 5f
+ decl NR_READERS(%rdi)
+ jnz 6f
+
+5: movl $0, WRITER(%rdi)
+
+ movl $1, %esi
+ leaq WRITERS_WAKEUP(%rdi), %r10
+ movq %rsi, %rdx
+ cmpl $0, WRITERS_QUEUED(%rdi)
+ jne 0f
+
+ /* If also no readers waiting nothing to do. */
+ cmpl $0, READERS_QUEUED(%rdi)
+ je 6f
+
+ movl $0x7fffffff, %edx
+ leaq READERS_WAKEUP(%rdi), %r10
+
+0: incl (%r10)
+ LOCK
+#if MUTEX == 0
+ decl (%rdi)
+#else
+ decl MUTEX(%rdi)
+#endif
+ jne 7f
+
+8: movl $SYS_futex, %eax
+ movq %r10, %rdi
+ syscall
+
+ xorl %eax, %eax
+ retq
+
+ .align 16
+6: LOCK
+#if MUTEX == 0
+ decl (%rdi)
+#else
+ decl MUTEX(%rdi)
+#endif
+ jne 3f
+
+4: xorl %eax, %eax
+ retq
+
+1:
+#if MUTEX != 0
+ addq $MUTEX, %rdi
+#endif
+ callq __lll_mutex_lock_wait
+#if MUTEX != 0
+ subq $MUTEX, %rdi
+#endif
+ jmp 2b
+
+3:
+#if MUTEX != 0
+ addq $MUTEX, %rdi
+#endif
+ callq __lll_mutex_unlock_wake
+ jmp 4b
+
+7:
+#if MUTEX != 0
+ addq $MUTEX, %rdi
+#endif
+ callq __lll_mutex_unlock_wake
+ jmp 8b
+
+ .size __pthread_rwlock_unlock,.-__pthread_rwlock_unlock
+
+ .globl pthread_rwlock_unlock
+pthread_rwlock_unlock = __pthread_rwlock_unlock
+
+ .globl __pthread_rwlock_unlock_internal
+__pthread_rwlock_unlock_internal = __pthread_rwlock_unlock
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
new file mode 100644
index 000000000..0e82f890a
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
@@ -0,0 +1,165 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <lowlevelrwlock.h>
+#include <pthread-errnos.h>
+
+
+#define SYS_futex 202
+#define FUTEX_WAIT 0
+#define FUTEX_WAKE 1
+
+#ifndef UP
+# define LOCK lock
+#else
+# define LOCK
+#endif
+
+
+ .text
+
+ .globl __pthread_rwlock_wrlock
+ .type __pthread_rwlock_wrlock,@function
+ .align 16
+__pthread_rwlock_wrlock:
+ xorq %r10, %r10
+
+ /* Get the lock. */
+ movl $1, %esi
+ xorl %eax, %eax
+ LOCK
+#if MUTEX == 0
+ cmpxchgl %esi, (%rdi)
+#else
+ cmpxchgl %esi, MUTEX(%rdi)
+#endif
+ jnz 1f
+
+2: movl WRITER(%rdi), %eax
+ testl %eax, %eax
+ jne 14f
+ cmpl $0, NR_READERS(%rdi)
+ je 5f
+
+3: incl WRITERS_QUEUED(%rdi)
+ je 4f
+
+ movl WRITERS_WAKEUP(%rdi), %edx
+
+ LOCK
+#if MUTEX == 0
+ decl (%rdi)
+#else
+ decl MUTEX(%rdi)
+#endif
+ jne 10f
+
+11: addq $WRITERS_WAKEUP, %rdi
+#if FUTEX_WAIT == 0
+ xorl %esi, %esi
+#else
+ movl $FUTEX_WAIT, %esi
+#endif
+ movl $SYS_futex, %eax
+ syscall
+
+ subq $WRITERS_WAKEUP, %rdi
+
+ /* Reget the lock. */
+ movl $1, %esi
+ xorl %eax, %eax
+ LOCK
+#if MUTEX == 0
+ cmpxchgl %esi, (%rdi)
+#else
+ cmpxchgl %esi, MUTEX(%rdi)
+#endif
+ jnz 12f
+
+13: decl WRITERS_QUEUED(%rdi)
+ jmp 2b
+
+5: xorl %edx, %edx
+ movl %fs:TID, %eax
+ movl %eax, WRITER(%rdi)
+9: LOCK
+#if MUTEX == 0
+ decl (%rdi)
+#else
+ decl MUTEX(%rdi)
+#endif
+ jne 6f
+7:
+
+ movq %rdx, %rax
+ retq
+
+1:
+#if MUTEX != 0
+ addq $MUTEX, %rdi
+#endif
+ callq __lll_mutex_lock_wait
+#if MUTEX != 0
+ subq $MUTEX, %rdi
+#endif
+ jmp 2b
+
+14: cmpl %fs:TID, %eax
+ jne 3b
+ movl $EDEADLK, %edx
+ jmp 9b
+
+6:
+#if MUTEX != 0
+ addq $MUTEX, %rdi
+#endif
+ callq __lll_mutex_unlock_wake
+ jmp 7b
+
+4: decl WRITERS_QUEUED(%rdi)
+ movl $EAGAIN, %edx
+ jmp 9b
+
+10:
+#if MUTEX != 0
+ addq $MUTEX, %rdi
+#endif
+ callq __lll_mutex_unlock_wake
+#if MUTEX != 0
+ subq $MUTEX, %rdi
+#endif
+ jmp 11b
+
+12:
+#if MUTEX != 0
+ addq $MUTEX, %rdi
+#endif
+ callq __lll_mutex_lock_wait
+#if MUTEX != 0
+ subq $MUTEX, %rdi
+#endif
+ jmp 13b
+ .size __pthread_rwlock_wrlock,.-__pthread_rwlock_wrlock
+
+ .globl pthread_rwlock_wrlock
+pthread_rwlock_wrlock = __pthread_rwlock_wrlock
+
+ .globl __pthread_rwlock_wrlock_internal
+__pthread_rwlock_wrlock_internal = __pthread_rwlock_wrlock
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_spin_init.c b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_spin_init.c
new file mode 100644
index 000000000..dc811787e
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_spin_init.c
@@ -0,0 +1 @@
+#include <nptl/sysdeps/x86_64/pthread_spin_init.c>
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_spin_unlock.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_spin_unlock.S
new file mode 100644
index 000000000..7da1c75dc
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_spin_unlock.S
@@ -0,0 +1 @@
+#include <nptl/sysdeps/x86_64/pthread_spin_unlock.S>
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
new file mode 100644
index 000000000..7f608a597
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
@@ -0,0 +1,66 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <pthread-errnos.h>
+
+#ifndef UP
+# define LOCK lock
+#else
+# define
+#endif
+
+#define SYS_futex 202
+#define FUTEX_WAKE 1
+
+
+ .text
+
+ .globl sem_post
+ .type sem_post,@function
+ .align 16
+sem_post:
+ movl $1, %edx
+ LOCK
+ xaddl %edx, (%rdi)
+
+ movl $SYS_futex, %eax
+ movl $FUTEX_WAKE, %esi
+ incl %edx
+ syscall
+
+ testq %rax, %rax
+ js 1f
+
+ xorl %eax, %eax
+ retq
+
+1:
+#if USE___THREAD
+ movq errno@gottpoff(%rip), %rdx
+ movl $EINVAL, %fs:(%rdx)
+#else
+ callq __errno_location@plt
+ movl $EINVAL, (%rax)
+#endif
+
+ orl $-1, %eax
+ retq
+ .size sem_post,.-sem_post
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
new file mode 100644
index 000000000..c44d3f5e7
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
@@ -0,0 +1,175 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <pthread-errnos.h>
+
+#ifndef UP
+# define LOCK lock
+#else
+# define
+#endif
+
+#define SYS_futex 202
+
+/* For the calculation see asm/vsyscall.h. */
+#define VSYSCALL_ADDR_vgettimeofday 0xffffffffff600000
+
+
+ .text
+
+ .globl sem_timedwait
+ .type sem_timedwait,@function
+ .align 16
+ cfi_startproc
+sem_timedwait:
+ /* First check for cancellation. */
+ movl %fs:CANCELHANDLING, %eax
+ andl $0xfffffff9, %eax
+ cmpl $8, %eax
+ je 11f
+
+ movl (%rdi), %eax
+2: testl %eax, %eax
+ je 1f
+
+ leaq -1(%rax), %rdx
+ LOCK
+ cmpxchgl %edx, (%rdi)
+ jne 2b
+
+ xorl %eax, %eax
+ retq
+
+ /* Check whether the timeout value is valid. */
+1: pushq %r12
+ cfi_adjust_cfa_offset(8)
+ pushq %r13
+ cfi_adjust_cfa_offset(8)
+ pushq %r14
+ cfi_adjust_cfa_offset(8)
+ subq $24, %rsp
+ cfi_adjust_cfa_offset(24)
+
+ movq %rdi, %r12
+ cfi_offset(12, -16) /* %r12 */
+ movq %rsi, %r13
+ cfi_offset(13, -24) /* %r13 */
+
+ /* Check for invalid nanosecond field. */
+ cmpq $1000000000, 8(%r13)
+ movl $EINVAL, %r14d
+ cfi_offset(14, -24) /* %r14 */
+ jae 6f
+
+7: call __pthread_enable_asynccancel
+ movl %eax, 16(%rsp)
+
+ xorl %esi, %esi
+ movq %rsp, %rdi
+ movq $VSYSCALL_ADDR_vgettimeofday, %rax
+ callq *%rax
+
+ /* Compute relative timeout. */
+ movq 8(%rsp), %rax
+ movl $1000, %edi
+ mul %rdi /* Milli seconds to nano seconds. */
+ movq (%r13), %rdi
+ movq 8(%r13), %rsi
+ subq (%rsp), %rdi
+ subq %rax, %rsi
+ jns 5f
+ addq $1000000000, %rsi
+ decq %rdi
+5: testq %rdi, %rdi
+ movl $ETIMEDOUT, %r14d
+ js 6f /* Time is already up. */
+
+ movq %rdi, (%rsp) /* Store relative timeout. */
+ movq %rsi, 8(%rsp)
+
+ movq %rsp, %r10
+ movq %r12, %rdi
+ xorl %esi, %esi
+ movl $SYS_futex, %eax
+ xorl %edx, %edx
+ syscall
+ movq %rax, %r14
+
+ movl 16(%rsp), %edi
+ call __pthread_disable_asynccancel
+
+ testq %r14, %r14
+ je 9f
+ cmpq $-EWOULDBLOCK, %r14
+ jne 3f
+
+9: movl (%r12), %eax
+8: testl %eax, %eax
+ je 7b
+
+ leaq -1(%rax), %rcx
+ LOCK
+ cmpxchgl %ecx, (%r12)
+ jne 8b
+
+ xorl %eax, %eax
+10: addq $24, %rsp
+ cfi_adjust_cfa_offset(-24)
+ popq %r14
+ cfi_adjust_cfa_offset(-8)
+ cfi_restore(14)
+ popq %r13
+ cfi_adjust_cfa_offset(-8)
+ cfi_restore(13)
+ popq %r12
+ cfi_adjust_cfa_offset(-8)
+ cfi_restore(12)
+ retq
+
+ cfi_adjust_cfa_offset(48)
+ cfi_offset(12, -16) /* %r12 */
+ cfi_offset(13, -24) /* %r13 */
+ cfi_offset(14, -32) /* %r14 */
+3: negq %r14
+6:
+#if USE___THREAD
+ movq errno@gottpoff(%rip), %rdx
+ movl %r14d, %fs:(%rdx)
+#else
+ callq __errno_location@plt
+ movl %r14d, (%rax)
+#endif
+
+ orl $-1, %eax
+ jmp 10b
+ cfi_adjust_cfa_offset(-48)
+ cfi_restore(14)
+ cfi_restore(13)
+ cfi_restore(12)
+
+11: /* Canceled. */
+ movq $0xffffffffffffffff, %fs:RESULT
+ LOCK
+ orl $0x10, %fs:CANCELHANDLING
+ movq %fs:CLEANUP_JMP_BUF, %rdi
+ jmp HIDDEN_JUMPTARGET (__pthread_unwind)
+ cfi_endproc
+ .size sem_timedwait,.-sem_timedwait
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_trywait.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_trywait.S
new file mode 100644
index 000000000..6b77dfc0d
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_trywait.S
@@ -0,0 +1,58 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <pthread-errnos.h>
+
+#ifndef UP
+# define LOCK lock
+#else
+# define
+#endif
+
+ .text
+
+ .globl sem_trywait
+ .type sem_trywait,@function
+ .align 16
+sem_trywait:
+ movl (%rdi), %eax
+2: testl %eax, %eax
+ jz 1f
+
+ leaq -1(%rax), %rdx
+ LOCK
+ cmpxchgl %edx, (%rdi)
+ jne 2b
+
+ xorl %eax, %eax
+ retq
+
+1:
+#if USE___THREAD
+ movq errno@gottpoff(%rip), %rdx
+ movl $EAGAIN, %fs:(%rdx)
+#else
+ callq __errno_location@plt
+ movl $EAGAIN, (%rax)
+#endif
+ orl $-1, %eax
+ retq
+ .size sem_trywait,.-sem_trywait
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
new file mode 100644
index 000000000..63ecd063a
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
@@ -0,0 +1,120 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <shlib-compat.h>
+#include <pthread-errnos.h>
+
+#ifndef UP
+# define LOCK lock
+#else
+# define
+#endif
+
+#define SYS_futex 202
+
+
+ .text
+
+ .globl sem_wait
+ .type sem_wait,@function
+ .align 16
+ cfi_startproc
+sem_wait:
+ /* First check for cancellation. */
+ movl %fs:CANCELHANDLING, %eax
+ andl $0xfffffff9, %eax
+ cmpl $8, %eax
+ je 4f
+
+ pushq %r12
+ cfi_adjust_cfa_offset(8)
+ cfi_offset(12, -16)
+ pushq %r13
+ cfi_adjust_cfa_offset(8)
+ movq %rdi, %r13
+ cfi_offset(13, -24)
+
+3: movl (%r13), %eax
+2: testl %eax, %eax
+ je 1f
+
+ leaq -1(%rax), %rdx
+ LOCK
+ cmpxchgl %edx, (%r13)
+ jne 2b
+ xorl %eax, %eax
+
+ popq %r13
+ cfi_adjust_cfa_offset(-8)
+ cfi_restore(13)
+ popq %r12
+ cfi_adjust_cfa_offset(-8)
+ cfi_restore(12)
+
+ retq
+
+ cfi_adjust_cfa_offset(16)
+ cfi_offset(12, -16)
+ cfi_offset(13, -24)
+1: call __pthread_enable_asynccancel
+ movl %eax, %r8d
+
+ xorq %r10, %r10
+ movl $SYS_futex, %eax
+ movq %r13, %rdi
+ movq %r10, %rsi
+ movq %r10, %rdx
+ syscall
+ movq %rax, %r12
+
+ movl %r8d, %edi
+ call __pthread_disable_asynccancel
+
+ testq %r12, %r12
+ je 3b
+ cmpq $-EWOULDBLOCK, %r12
+ je 3b
+ negq %r12
+#if USE___THREAD
+ movq errno@gottpoff(%rip), %rdx
+ movl %r12d, %fs:(%rdx)
+#else
+ callq __errno_location@plt
+ movl %r12d, (%rax)
+#endif
+ orl $-1, %eax
+
+ popq %r13
+ cfi_adjust_cfa_offset(-8)
+ cfi_restore(13)
+ popq %r12
+ cfi_adjust_cfa_offset(-8)
+ cfi_restore(12)
+
+ retq
+
+4: /* Canceled. */
+ movq $0xffffffffffffffff, %fs:RESULT
+ LOCK
+ orl $0x10, %fs:CANCELHANDLING
+ movq %fs:CLEANUP_JMP_BUF, %rdi
+ jmp HIDDEN_JUMPTARGET (__pthread_unwind)
+ cfi_endproc
+ .size sem_wait,.-sem_wait
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h
new file mode 100644
index 000000000..97debaba9
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h
@@ -0,0 +1,138 @@
+/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
+
+ 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 <sysdep.h>
+#include <tls.h>
+#ifndef __ASSEMBLER__
+# include <nptl/pthreadP.h>
+#endif
+
+#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
+
+# undef PSEUDO
+# define PSEUDO(name, syscall_name, args) \
+ .text; \
+ ENTRY (name) \
+ SINGLE_THREAD_P; \
+ jne L(pseudo_cancel); \
+ .type __##syscall_name##_nocancel,@function; \
+ .globl __##syscall_name##_nocancel; \
+ __##syscall_name##_nocancel: \
+ DO_CALL (syscall_name, args); \
+ cmpq $-4095, %rax; \
+ jae SYSCALL_ERROR_LABEL; \
+ ret; \
+ .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
+ L(pseudo_cancel): \
+ /* Save registers that might get destroyed. */ \
+ SAVESTK_##args \
+ PUSHARGS_##args \
+ CENABLE \
+ /* Restore registers. */ \
+ POPARGS_##args \
+ /* The return value from CENABLE is argument for CDISABLE. */ \
+ movq %rax, (%rsp); \
+ movl $SYS_ify (syscall_name), %eax; \
+ syscall; \
+ movq (%rsp), %rdi; \
+ /* Save %rax since it's the error code from the syscall. */ \
+ movq %rax, 8(%rsp); \
+ CDISABLE \
+ movq 8(%rsp), %rax; \
+ RESTSTK_##args \
+ cmpq $-4095, %rax; \
+ jae SYSCALL_ERROR_LABEL; \
+ L(pseudo_end):
+
+
+# define PUSHARGS_0 /* Nothing. */
+# define PUSHARGS_1 PUSHARGS_0 movq %rdi, 8(%rsp);
+# define PUSHARGS_2 PUSHARGS_1 movq %rsi, 16(%rsp);
+# define PUSHARGS_3 PUSHARGS_2 movq %rdx, 24(%rsp);
+# define PUSHARGS_4 PUSHARGS_3 movq %rcx, 32(%rsp);
+# define PUSHARGS_5 PUSHARGS_4 movq %r8, 40(%rsp);
+# define PUSHARGS_6 PUSHARGS_5 movq %r9, 48(%rsp);
+
+# define POPARGS_0 /* Nothing. */
+# define POPARGS_1 POPARGS_0 movq 8(%rsp), %rdi;
+# define POPARGS_2 POPARGS_1 movq 16(%rsp), %rsi;
+# define POPARGS_3 POPARGS_2 movq 24(%rsp), %rdx;
+# define POPARGS_4 POPARGS_3 movq 32(%rsp), %r10;
+# define POPARGS_5 POPARGS_4 movq 40(%rsp), %r8;
+# define POPARGS_6 POPARGS_5 movq 48(%rsp), %r9;
+
+/* We always have to align the stack before calling a function. */
+# define SAVESTK_0 subq $24, %rsp; cfi_adjust_cfa_offset (24);
+# define SAVESTK_1 SAVESTK_0
+# define SAVESTK_2 SAVESTK_1
+# define SAVESTK_3 subq $40, %rsp; cfi_adjust_cfa_offset (40);
+# define SAVESTK_4 SAVESTK_3
+# define SAVESTK_5 subq $56, %rsp; cfi_adjust_cfa_offset (56);
+# define SAVESTK_6 SAVESTK_5
+
+# define RESTSTK_0 addq $24,%rsp; cfi_adjust_cfa_offset (-24);
+# define RESTSTK_1 RESTSTK_0
+# define RESTSTK_2 RESTSTK_1
+# define RESTSTK_3 addq $40, %rsp; cfi_adjust_cfa_offset (-40);
+# define RESTSTK_4 RESTSTK_3
+# define RESTSTK_5 addq $56, %rsp; cfi_adjust_cfa_offset (-56);
+# define RESTSTK_6 RESTSTK_5
+
+# ifdef IS_IN_libpthread
+# define CENABLE call __pthread_enable_asynccancel;
+# define CDISABLE call __pthread_disable_asynccancel;
+# define __local_multiple_threads __pthread_multiple_threads
+# elif !defined NOT_IN_libc
+# define CENABLE call __libc_enable_asynccancel;
+# define CDISABLE call __libc_disable_asynccancel;
+# define __local_multiple_threads __libc_multiple_threads
+# elif defined IS_IN_librt
+# define CENABLE call __librt_enable_asynccancel;
+# define CDISABLE call __librt_disable_asynccancel;
+# else
+# error Unsupported library
+# endif
+
+# 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
+
+# ifndef __ASSEMBLER__
+# define SINGLE_THREAD_P \
+ __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+ header.multiple_threads) == 0, 1)
+# else
+# define SINGLE_THREAD_P cmpl $0, %fs:MULTIPLE_THREADS_OFFSET
+# endif
+
+# endif
+
+#elif !defined __ASSEMBLER__
+
+# define SINGLE_THREAD_P (1)
+# define NO_CANCELLATION 1
+
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/timer_create.c b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/timer_create.c
new file mode 100644
index 000000000..1849f72a4
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/timer_create.c
@@ -0,0 +1,66 @@
+/* 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <shlib-compat.h>
+#include "compat-timer.h"
+#include <atomic.h>
+
+
+#define timer_create_alias __timer_create_new
+#include "../timer_create.c"
+
+#undef timer_create
+versioned_symbol (librt, __timer_create_new, timer_create, GLIBC_2_3_3);
+
+
+#if SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_3_3)
+timer_t __compat_timer_list[OLD_TIMER_MAX] attribute_hidden;
+
+
+int
+__timer_create_old (clockid_t clock_id, struct sigevent *evp, int *timerid)
+{
+ timer_t newp;
+
+ int res = __timer_create_new (clock_id, evp, &newp);
+ if (res == 0)
+ {
+ int i;
+ for (i = 0; i < OLD_TIMER_MAX; ++i)
+ if (__compat_timer_list[i] == NULL
+ && ! atomic_compare_and_exchange_bool_acq (&__compat_timer_list[i],
+ newp, NULL))
+ {
+ *timerid = i;
+ break;
+ }
+
+ if (__builtin_expect (i == OLD_TIMER_MAX, 0))
+ {
+ /* No free slot. */
+ (void) __timer_delete_new (newp);
+ __set_errno (EINVAL);
+ res = -1;
+ }
+ }
+
+ return res;
+}
+compat_symbol (librt, __timer_create_old, timer_create, GLIBC_2_2);
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/timer_delete.c b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/timer_delete.c
new file mode 100644
index 000000000..6e0d9d033
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/timer_delete.c
@@ -0,0 +1,45 @@
+/* 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <shlib-compat.h>
+#include "compat-timer.h"
+
+
+#define timer_delete_alias __timer_delete_new
+#include "../timer_delete.c"
+
+#undef timer_delete
+versioned_symbol (librt, __timer_delete_new, timer_delete, GLIBC_2_3_3);
+
+
+#if SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_3_3)
+int
+__timer_delete_old (int timerid)
+{
+ int res = __timer_delete_new (__compat_timer_list[timerid]);
+
+ if (res == 0)
+ /* Successful timer deletion, now free the index. We only need to
+ store a word and that better be atomic. */
+ __compat_timer_list[timerid] = NULL;
+
+ return res;
+}
+compat_symbol (librt, __timer_delete_old, timer_delete, GLIBC_2_2);
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/timer_getoverr.c b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/timer_getoverr.c
new file mode 100644
index 000000000..d75636c99
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/timer_getoverr.c
@@ -0,0 +1,39 @@
+/* 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <shlib-compat.h>
+#include "compat-timer.h"
+
+
+#define timer_getoverrun_alias __timer_getoverrun_new
+#include "../timer_getoverr.c"
+
+#undef timer_getoverrun
+versioned_symbol (librt, __timer_getoverrun_new, timer_getoverrun,
+ GLIBC_2_3_3);
+
+
+#if SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_3_3)
+int
+__timer_getoverrun_old (int timerid)
+{
+ return __timer_getoverrun_new (__compat_timer_list[timerid]);
+}
+compat_symbol (librt, __timer_getoverrun_old, timer_getoverrun, GLIBC_2_2);
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/timer_gettime.c b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/timer_gettime.c
new file mode 100644
index 000000000..1f1253af2
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/timer_gettime.c
@@ -0,0 +1,38 @@
+/* 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <shlib-compat.h>
+#include "compat-timer.h"
+
+
+#define timer_gettime_alias __timer_gettime_new
+#include "../timer_gettime.c"
+
+#undef timer_gettime
+versioned_symbol (librt, __timer_gettime_new, timer_gettime, GLIBC_2_3_3);
+
+
+#if SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_3_3)
+int
+__timer_gettime_old (int timerid, struct itimerspec *value)
+{
+ return __timer_gettime_new (__compat_timer_list[timerid], value);
+}
+compat_symbol (librt, __timer_gettime_old, timer_gettime, GLIBC_2_2);
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/timer_settime.c b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/timer_settime.c
new file mode 100644
index 000000000..4c945ec51
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/timer_settime.c
@@ -0,0 +1,40 @@
+/* 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <shlib-compat.h>
+#include "compat-timer.h"
+
+
+#define timer_settime_alias __timer_settime_new
+#include "../timer_settime.c"
+
+#undef timer_settime
+versioned_symbol (librt, __timer_settime_new, timer_settime, GLIBC_2_3_3);
+
+
+#if SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_3_3)
+int
+__timer_settime_old (int timerid, int flags, const struct itimerspec *value,
+ struct itimerspec *ovalue)
+{
+ return __timer_settime_new (__compat_timer_list[timerid], flags,
+ value, ovalue);
+}
+compat_symbol (librt, __timer_settime_old, timer_settime, GLIBC_2_2);
+#endif
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/vfork.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/vfork.S
new file mode 100644
index 000000000..9a9912ca8
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/vfork.S
@@ -0,0 +1,43 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+/* We want an #include_next, but we are the main source file.
+ So, #include ourselves and in that incarnation we can use #include_next. */
+#ifndef INCLUDED_SELF
+# define INCLUDED_SELF
+# include <vfork.S>
+#else
+
+# include <tcb-offsets.h>
+
+# define SAVE_PID \
+ movl %fs:PID, %esi; \
+ movl $0x80000000, %ecx; \
+ movl %esi, %edx; \
+ negl %edx; \
+ cmove %ecx, %edx; \
+ movl %edx, %fs:PID
+
+# define RESTORE_PID \
+ testq %rax, %rax; \
+ je 1f; \
+ movl %esi, %fs:PID; \
+1:
+
+# include_next <vfork.S>
+#endif
diff --git a/libc/nptl/sysdeps/x86_64/Makefile b/libc/nptl/sysdeps/x86_64/Makefile
new file mode 100644
index 000000000..6e24a26cd
--- /dev/null
+++ b/libc/nptl/sysdeps/x86_64/Makefile
@@ -0,0 +1,28 @@
+# Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# 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.
+
+ifeq ($(subdir),csu)
+gen-as-const-headers += tcb-offsets.sym
+endif
+
+ifeq ($(subdir),nptl)
+# P4s have problems with 4M aliasing. We disturb the allocation of stacks
+# just enough so the subsequent allocations do not use stack address
+# (mod 4M) == 0.
+CFLAGS-pthread_create.c += -DMULTI_PAGE_ALIASING=65536
+endif
diff --git a/libc/nptl/sysdeps/x86_64/pthread_spin_init.c b/libc/nptl/sysdeps/x86_64/pthread_spin_init.c
new file mode 100644
index 000000000..55696204c
--- /dev/null
+++ b/libc/nptl/sysdeps/x86_64/pthread_spin_init.c
@@ -0,0 +1 @@
+#include "../i386/pthread_spin_init.c"
diff --git a/libc/nptl/sysdeps/x86_64/pthread_spin_lock.c b/libc/nptl/sysdeps/x86_64/pthread_spin_lock.c
new file mode 100644
index 000000000..7cf0e0ecc
--- /dev/null
+++ b/libc/nptl/sysdeps/x86_64/pthread_spin_lock.c
@@ -0,0 +1 @@
+#include "../i386/pthread_spin_lock.c"
diff --git a/libc/nptl/sysdeps/x86_64/pthread_spin_trylock.S b/libc/nptl/sysdeps/x86_64/pthread_spin_trylock.S
new file mode 100644
index 000000000..9b5133583
--- /dev/null
+++ b/libc/nptl/sysdeps/x86_64/pthread_spin_trylock.S
@@ -0,0 +1,40 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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-errnos.h>
+
+
+#ifdef UP
+# define LOCK
+#else
+# define LOCK lock
+#endif
+
+ .globl pthread_spin_trylock
+ .type pthread_spin_trylock,@function
+ .align 16
+pthread_spin_trylock:
+ movl $1, %eax
+ xorl %ecx, %ecx
+ LOCK
+ cmpxchgl %ecx, (%rdi)
+ movl $EBUSY, %eax
+ cmovel %ecx, %eax
+ retq
+ .size pthread_spin_trylock,.-pthread_spin_trylock
diff --git a/libc/nptl/sysdeps/x86_64/pthread_spin_unlock.S b/libc/nptl/sysdeps/x86_64/pthread_spin_unlock.S
new file mode 100644
index 000000000..d3e13bde9
--- /dev/null
+++ b/libc/nptl/sysdeps/x86_64/pthread_spin_unlock.S
@@ -0,0 +1,31 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+ .globl pthread_spin_unlock
+ .type pthread_spin_unlock,@function
+ .align 16
+pthread_spin_unlock:
+ movl $1, (%rdi)
+ xorl %eax, %eax
+ retq
+ .size pthread_spin_unlock,.-pthread_spin_unlock
+
+ /* The implementation of pthread_spin_init is identical. */
+ .globl pthread_spin_init
+pthread_spin_init = pthread_spin_unlock
diff --git a/libc/nptl/sysdeps/x86_64/pthreaddef.h b/libc/nptl/sysdeps/x86_64/pthreaddef.h
new file mode 100644
index 000000000..27896a445
--- /dev/null
+++ b/libc/nptl/sysdeps/x86_64/pthreaddef.h
@@ -0,0 +1,54 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+/* Default stack size. */
+#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024)
+
+/* Required stack pointer alignment at beginning. SSE requires 16
+ bytes. */
+#define STACK_ALIGN 16
+
+/* Minimal stack size after allocating thread descriptor and guard size. */
+#define MINIMAL_REST_STACK 2048
+
+/* Alignment requirement for TCB. */
+#define TCB_ALIGNMENT 16
+
+
+/* Location of current stack frame. The frame pointer is not usable. */
+#define CURRENT_STACK_FRAME \
+ ({ char *frame; asm ("movq %%rsp, %0" : "=r" (frame)); frame; })
+
+
+/* We prefer to have the stack allocated in the low 4GB since this
+ allows faster context switches. */
+#define ARCH_MAP_FLAGS MAP_32BIT
+
+/* If it is not possible to allocate memory there retry without that
+ flag. */
+#define ARCH_RETRY_MMAP(size) \
+ mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, \
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)
+
+
+/* XXX Until we have a better place keep the definitions here. */
+
+/* While there is no such syscall. */
+#define __exit_thread_inline(val) \
+ asm volatile ("syscall" :: "a" (__NR_exit), "D" (val))
diff --git a/libc/nptl/sysdeps/x86_64/tcb-offsets.sym b/libc/nptl/sysdeps/x86_64/tcb-offsets.sym
new file mode 100644
index 000000000..a9ede75c9
--- /dev/null
+++ b/libc/nptl/sysdeps/x86_64/tcb-offsets.sym
@@ -0,0 +1,13 @@
+#include <sysdep.h>
+#include <tls.h>
+
+RESULT offsetof (struct pthread, result)
+TID offsetof (struct pthread, tid)
+PID offsetof (struct pthread, pid)
+CANCELHANDLING offsetof (struct pthread, cancelhandling)
+CLEANUP_JMP_BUF offsetof (struct pthread, cleanup_jmp_buf)
+CLEANUP offsetof (struct pthread, cleanup)
+CLEANUP_PREV offsetof (struct _pthread_cleanup_buffer, __prev)
+MUTEX_FUTEX offsetof (pthread_mutex_t, __data.__lock)
+MULTIPLE_THREADS_OFFSET offsetof (tcbhead_t, multiple_threads)
+POINTER_GUARD offsetof (tcbhead_t, pointer_guard)
diff --git a/libc/nptl/sysdeps/x86_64/tls.h b/libc/nptl/sysdeps/x86_64/tls.h
new file mode 100644
index 000000000..65ff0639b
--- /dev/null
+++ b/libc/nptl/sysdeps/x86_64/tls.h
@@ -0,0 +1,344 @@
+/* Definition for thread-local data handling. nptl/x86_64 version.
+ Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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. */
+
+#ifndef _TLS_H
+#define _TLS_H 1
+
+#ifndef __ASSEMBLER__
+# include <asm/prctl.h> /* For ARCH_SET_FS. */
+# include <stdbool.h>
+# include <stddef.h>
+# include <stdint.h>
+# include <stdlib.h>
+
+
+/* Type for the dtv. */
+typedef union dtv
+{
+ size_t counter;
+ struct
+ {
+ void *val;
+ bool is_static;
+ } pointer;
+} dtv_t;
+
+
+typedef struct
+{
+ void *tcb; /* Pointer to the TCB. Not necessary the
+ thread descriptor used by libpthread. */
+ dtv_t *dtv;
+ void *self; /* Pointer to the thread descriptor. */
+ int multiple_threads;
+ uintptr_t sysinfo;
+ uintptr_t stack_guard;
+ uintptr_t pointer_guard;
+} tcbhead_t;
+
+#else /* __ASSEMBLER__ */
+# include <tcb-offsets.h>
+#endif
+
+
+/* We require TLS support in the tools. */
+#ifndef HAVE_TLS_SUPPORT
+# error "TLS support is required."
+#endif
+
+/* Signal that TLS support is available. */
+#define USE_TLS 1
+
+/* Alignment requirement for the stack. */
+#define STACK_ALIGN 16
+
+
+#ifndef __ASSEMBLER__
+/* Get system call information. */
+# include <sysdep.h>
+
+
+/* Get the thread descriptor definition. */
+# include <nptl/descr.h>
+
+#ifndef LOCK_PREFIX
+# ifdef UP
+# define LOCK_PREFIX /* nothing */
+# else
+# define LOCK_PREFIX "lock;"
+# endif
+#endif
+
+/* This is the size of the initial TCB. Can't be just sizeof (tcbhead_t),
+ because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
+ struct pthread even when not linked with -lpthread. */
+# define TLS_INIT_TCB_SIZE sizeof (struct pthread)
+
+/* Alignment requirements for the initial TCB. */
+# define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
+
+/* This is the size of the TCB. */
+# define TLS_TCB_SIZE sizeof (struct pthread)
+
+/* Alignment requirements for the TCB. */
+# define TLS_TCB_ALIGN __alignof__ (struct pthread)
+
+/* The TCB can have any size and the memory following the address the
+ thread pointer points to is unspecified. Allocate the TCB there. */
+# define TLS_TCB_AT_TP 1
+
+
+/* Install the dtv pointer. The pointer passed is to the element with
+ index -1 which contain the length. */
+# define INSTALL_DTV(descr, dtvp) \
+ ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
+
+/* Install new dtv for current thread. */
+# define INSTALL_NEW_DTV(dtvp) \
+ ({ struct pthread *__pd; \
+ THREAD_SETMEM (__pd, header.dtv, (dtvp)); })
+
+/* Return dtv of given thread descriptor. */
+# define GET_DTV(descr) \
+ (((tcbhead_t *) (descr))->dtv)
+
+
+/* Macros to load from and store into segment registers. */
+# define TLS_GET_FS() \
+ ({ int __seg; __asm ("movl %%fs, %0" : "=q" (__seg)); __seg; })
+# define TLS_SET_FS(val) \
+ __asm ("movl %0, %%fs" :: "q" (val))
+
+
+/* Code to initially initialize the thread pointer. This might need
+ special attention since 'errno' is not yet available and if the
+ operation can cause a failure 'errno' must not be touched.
+
+ We have to make the syscall for both uses of the macro since the
+ address might be (and probably is) different. */
+# define TLS_INIT_TP(thrdescr, secondcall) \
+ ({ void *_thrdescr = (thrdescr); \
+ tcbhead_t *_head = _thrdescr; \
+ int _result; \
+ \
+ _head->tcb = _thrdescr; \
+ /* For now the thread descriptor is at the same address. */ \
+ _head->self = _thrdescr; \
+ \
+ /* It is a simple syscall to set the %fs value for the thread. */ \
+ asm volatile ("syscall" \
+ : "=a" (_result) \
+ : "0" ((unsigned long int) __NR_arch_prctl), \
+ "D" ((unsigned long int) ARCH_SET_FS), \
+ "S" (_thrdescr) \
+ : "memory", "cc", "r11", "cx"); \
+ \
+ _result ? "cannot set %fs base address for thread-local storage" : 0; \
+ })
+
+
+/* Return the address of the dtv for the current thread. */
+# define THREAD_DTV() \
+ ({ struct pthread *__pd; \
+ THREAD_GETMEM (__pd, header.dtv); })
+
+
+/* Return the thread descriptor for the current thread.
+
+ The contained asm must *not* be marked volatile since otherwise
+ assignments like
+ pthread_descr self = thread_self();
+ do not get optimized away. */
+# define THREAD_SELF \
+ ({ struct pthread *__self; \
+ asm ("movq %%fs:%c1,%q0" : "=r" (__self) \
+ : "i" (offsetof (struct pthread, header.self))); \
+ __self;})
+
+/* Magic for libthread_db to know how to do THREAD_SELF. */
+# define DB_THREAD_SELF_INCLUDE <sys/reg.h> /* For the FS constant. */
+# define DB_THREAD_SELF CONST_THREAD_AREA (64, FS)
+
+/* Read member of the thread descriptor directly. */
+# define THREAD_GETMEM(descr, member) \
+ ({ __typeof (descr->member) __value; \
+ if (sizeof (__value) == 1) \
+ asm volatile ("movb %%fs:%P2,%b0" \
+ : "=q" (__value) \
+ : "0" (0), "i" (offsetof (struct pthread, member))); \
+ else if (sizeof (__value) == 4) \
+ asm volatile ("movl %%fs:%P1,%0" \
+ : "=r" (__value) \
+ : "i" (offsetof (struct pthread, member))); \
+ else \
+ { \
+ if (sizeof (__value) != 8) \
+ /* There should not be any value with a size other than 1, \
+ 4 or 8. */ \
+ abort (); \
+ \
+ asm volatile ("movq %%fs:%P1,%q0" \
+ : "=r" (__value) \
+ : "i" (offsetof (struct pthread, member))); \
+ } \
+ __value; })
+
+
+/* Same as THREAD_GETMEM, but the member offset can be non-constant. */
+# define THREAD_GETMEM_NC(descr, member, idx) \
+ ({ __typeof (descr->member[0]) __value; \
+ if (sizeof (__value) == 1) \
+ asm volatile ("movb %%fs:%P2(%q3),%b0" \
+ : "=q" (__value) \
+ : "0" (0), "i" (offsetof (struct pthread, member[0])), \
+ "r" (idx)); \
+ else if (sizeof (__value) == 4) \
+ asm volatile ("movl %%fs:%P1(,%q2,4),%0" \
+ : "=r" (__value) \
+ : "i" (offsetof (struct pthread, member[0])), "r" (idx));\
+ else \
+ { \
+ if (sizeof (__value) != 8) \
+ /* There should not be any value with a size other than 1, \
+ 4 or 8. */ \
+ abort (); \
+ \
+ asm volatile ("movq %%fs:%P1(,%q2,8),%q0" \
+ : "=r" (__value) \
+ : "i" (offsetof (struct pthread, member[0])), \
+ "r" (idx)); \
+ } \
+ __value; })
+
+
+/* Loading addresses of objects on x86-64 needs to be treated special
+ when generating PIC code. */
+#ifdef __pic__
+# define IMM_MODE "nr"
+#else
+# define IMM_MODE "ir"
+#endif
+
+
+/* Same as THREAD_SETMEM, but the member offset can be non-constant. */
+# define THREAD_SETMEM(descr, member, value) \
+ ({ if (sizeof (descr->member) == 1) \
+ asm volatile ("movb %b0,%%fs:%P1" : \
+ : "iq" (value), \
+ "i" (offsetof (struct pthread, member))); \
+ else if (sizeof (descr->member) == 4) \
+ asm volatile ("movl %0,%%fs:%P1" : \
+ : IMM_MODE (value), \
+ "i" (offsetof (struct pthread, member))); \
+ else \
+ { \
+ if (sizeof (descr->member) != 8) \
+ /* There should not be any value with a size other than 1, \
+ 4 or 8. */ \
+ abort (); \
+ \
+ asm volatile ("movq %q0,%%fs:%P1" : \
+ : IMM_MODE ((unsigned long int) value), \
+ "i" (offsetof (struct pthread, member))); \
+ }})
+
+
+/* Set member of the thread descriptor directly. */
+# define THREAD_SETMEM_NC(descr, member, idx, value) \
+ ({ if (sizeof (descr->member[0]) == 1) \
+ asm volatile ("movb %b0,%%fs:%P1(%q2)" : \
+ : "iq" (value), \
+ "i" (offsetof (struct pthread, member[0])), \
+ "r" (idx)); \
+ else if (sizeof (descr->member[0]) == 4) \
+ asm volatile ("movl %0,%%fs:%P1(,%q2,4)" : \
+ : IMM_MODE (value), \
+ "i" (offsetof (struct pthread, member[0])), \
+ "r" (idx)); \
+ else \
+ { \
+ if (sizeof (descr->member[0]) != 8) \
+ /* There should not be any value with a size other than 1, \
+ 4 or 8. */ \
+ abort (); \
+ \
+ asm volatile ("movq %q0,%%fs:%P1(,%q2,8)" : \
+ : IMM_MODE ((unsigned long int) value), \
+ "i" (offsetof (struct pthread, member[0])), \
+ "r" (idx)); \
+ }})
+
+
+/* Atomic compare and exchange on TLS, returning old value. */
+#define THREAD_ATOMIC_CMPXCHG_VAL(descr, member, newval, oldval) \
+ ({ __typeof (descr->member) __ret; \
+ __typeof (oldval) __old = (oldval); \
+ if (sizeof (descr->member) == 4) \
+ asm volatile (LOCK_PREFIX "cmpxchgl %2, %%fs:%P3" \
+ : "=a" (__ret) \
+ : "0" (__old), "r" (newval), \
+ "i" (offsetof (struct pthread, member))); \
+ else \
+ /* Not necessary for other sizes in the moment. */ \
+ abort (); \
+ __ret; })
+
+
+/* Atomic set bit. */
+#define THREAD_ATOMIC_BIT_SET(descr, member, bit) \
+ (void) ({ if (sizeof ((descr)->member) == 4) \
+ asm volatile (LOCK_PREFIX "orl %1, %%fs:%P0" \
+ :: "i" (offsetof (struct pthread, member)), \
+ "ir" (1 << (bit))); \
+ else \
+ /* Not necessary for other sizes in the moment. */ \
+ abort (); })
+
+
+#define CALL_THREAD_FCT(descr) \
+ ({ void *__res; \
+ asm volatile ("movq %%fs:%P2, %%rdi\n\t" \
+ "callq *%%fs:%P1" \
+ : "=a" (__res) \
+ : "i" (offsetof (struct pthread, start_routine)), \
+ "i" (offsetof (struct pthread, arg)) \
+ : "di", "si", "cx", "dx", "r8", "r9", "r10", "r11", \
+ "memory", "cc"); \
+ __res; })
+
+
+/* Set the stack guard field in TCB head. */
+# define THREAD_SET_STACK_GUARD(value) \
+ THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
+# define THREAD_COPY_STACK_GUARD(descr) \
+ ((descr)->header.stack_guard \
+ = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
+
+
+/* Set the pointer guard field in the TCB head. */
+#define THREAD_SET_POINTER_GUARD(value) \
+ THREAD_SETMEM (THREAD_SELF, header.pointer_guard, value)
+#define THREAD_COPY_POINTER_GUARD(descr) \
+ ((descr)->header.pointer_guard \
+ = THREAD_GETMEM (THREAD_SELF, header.pointer_guard))
+
+
+#endif /* __ASSEMBLER__ */
+
+#endif /* tls.h */
diff --git a/libc/nptl/tpp.c b/libc/nptl/tpp.c
new file mode 100644
index 000000000..367dd8162
--- /dev/null
+++ b/libc/nptl/tpp.c
@@ -0,0 +1,172 @@
+/* Thread Priority Protect helpers.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2006.
+
+ 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 <assert.h>
+#include <atomic.h>
+#include <errno.h>
+#include <pthreadP.h>
+#include <sched.h>
+#include <stdlib.h>
+
+
+int __sched_fifo_min_prio = -1;
+int __sched_fifo_max_prio = -1;
+
+void
+__init_sched_fifo_prio (void)
+{
+ __sched_fifo_max_prio = sched_get_priority_max (SCHED_FIFO);
+ atomic_write_barrier ();
+ __sched_fifo_min_prio = sched_get_priority_min (SCHED_FIFO);
+}
+
+int
+__pthread_tpp_change_priority (int previous_prio, int new_prio)
+{
+ struct pthread *self = THREAD_SELF;
+ struct priority_protection_data *tpp = THREAD_GETMEM (self, tpp);
+
+ if (tpp == NULL)
+ {
+ if (__sched_fifo_min_prio == -1)
+ __init_sched_fifo_prio ();
+
+ size_t size = sizeof *tpp;
+ size += (__sched_fifo_max_prio - __sched_fifo_min_prio + 1)
+ * sizeof (tpp->priomap[0]);
+ tpp = calloc (size, 1);
+ if (tpp == NULL)
+ return ENOMEM;
+ tpp->priomax = __sched_fifo_min_prio - 1;
+ THREAD_SETMEM (self, tpp, tpp);
+ }
+
+ assert (new_prio == -1
+ || (new_prio >= __sched_fifo_min_prio
+ && new_prio <= __sched_fifo_max_prio));
+ assert (previous_prio == -1
+ || (previous_prio >= __sched_fifo_min_prio
+ && previous_prio <= __sched_fifo_max_prio));
+
+ int priomax = tpp->priomax;
+ int newpriomax = priomax;
+ if (new_prio != -1)
+ {
+ if (tpp->priomap[new_prio - __sched_fifo_min_prio] + 1 == 0)
+ return EAGAIN;
+ ++tpp->priomap[new_prio - __sched_fifo_min_prio];
+ if (new_prio > priomax)
+ newpriomax = new_prio;
+ }
+
+ if (previous_prio != -1)
+ {
+ if (--tpp->priomap[previous_prio - __sched_fifo_min_prio] == 0
+ && priomax == previous_prio
+ && previous_prio > new_prio)
+ {
+ int i;
+ for (i = previous_prio - 1; i >= __sched_fifo_min_prio; --i)
+ if (tpp->priomap[i - __sched_fifo_min_prio])
+ break;
+ newpriomax = i;
+ }
+ }
+
+ if (priomax == newpriomax)
+ return 0;
+
+ lll_lock (self->lock);
+
+ tpp->priomax = newpriomax;
+
+ int result = 0;
+
+ if ((self->flags & ATTR_FLAG_SCHED_SET) == 0)
+ {
+ if (__sched_getparam (self->tid, &self->schedparam) != 0)
+ result = errno;
+ else
+ self->flags |= ATTR_FLAG_SCHED_SET;
+ }
+
+ if ((self->flags & ATTR_FLAG_POLICY_SET) == 0)
+ {
+ self->schedpolicy = __sched_getscheduler (self->tid);
+ if (self->schedpolicy == -1)
+ result = errno;
+ else
+ self->flags |= ATTR_FLAG_POLICY_SET;
+ }
+
+ if (result == 0)
+ {
+ struct sched_param sp = self->schedparam;
+ if (sp.sched_priority < newpriomax || sp.sched_priority < priomax)
+ {
+ if (sp.sched_priority < newpriomax)
+ sp.sched_priority = newpriomax;
+
+ if (__sched_setscheduler (self->tid, self->schedpolicy, &sp) < 0)
+ result = errno;
+ }
+ }
+
+ lll_unlock (self->lock);
+
+ return result;
+}
+
+int
+__pthread_current_priority (void)
+{
+ struct pthread *self = THREAD_SELF;
+ if ((self->flags & (ATTR_FLAG_POLICY_SET | ATTR_FLAG_SCHED_SET))
+ == (ATTR_FLAG_POLICY_SET | ATTR_FLAG_SCHED_SET))
+ return self->schedparam.sched_priority;
+
+ int result = 0;
+
+ lll_lock (self->lock);
+
+ if ((self->flags & ATTR_FLAG_SCHED_SET) == 0)
+ {
+ if (__sched_getparam (self->tid, &self->schedparam) != 0)
+ result = -1;
+ else
+ self->flags |= ATTR_FLAG_SCHED_SET;
+ }
+
+ if ((self->flags & ATTR_FLAG_POLICY_SET) == 0)
+ {
+ self->schedpolicy = __sched_getscheduler (self->tid);
+ if (self->schedpolicy == -1)
+ result = -1;
+ else
+ self->flags |= ATTR_FLAG_POLICY_SET;
+ }
+
+ if (result != -1)
+ result = self->schedparam.sched_priority;
+
+ lll_unlock (self->lock);
+
+ return result;
+}
diff --git a/libc/nptl/tst-_res1.c b/libc/nptl/tst-_res1.c
new file mode 100644
index 000000000..651e3cc40
--- /dev/null
+++ b/libc/nptl/tst-_res1.c
@@ -0,0 +1,69 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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. */
+
+/* Test whether _res in glibc 2.1.x and earlier (before __res_state()
+ was introduced) works. Portable programs should never do the
+ dirty things below. */
+
+#include <pthread.h>
+#include <resolv.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+void *tf (void *resp)
+{
+ if (resp == &_res || resp == __res_state ())
+ abort ();
+ _res.retry = 24;
+ return NULL;
+}
+
+void do_test (struct __res_state *resp)
+{
+ if (resp != &_res || resp != __res_state ())
+ abort ();
+ if (_res.retry != 12)
+ abort ();
+}
+
+int main (void)
+{
+#undef _res
+ extern struct __res_state _res;
+ pthread_t th;
+
+ _res.retry = 12;
+ if (pthread_create (&th, NULL, tf, &_res) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ do_test (&_res);
+
+ if (pthread_join (th, NULL) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ do_test (&_res);
+
+ exit (0);
+}
diff --git a/libc/nptl/tst-_res1mod1.c b/libc/nptl/tst-_res1mod1.c
new file mode 100644
index 000000000..73b190e6b
--- /dev/null
+++ b/libc/nptl/tst-_res1mod1.c
@@ -0,0 +1,23 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 <resolv.h>
+#undef _res
+
+struct __res_state _res;
diff --git a/libc/nptl/tst-_res1mod2.c b/libc/nptl/tst-_res1mod2.c
new file mode 100644
index 000000000..d2a3509c6
--- /dev/null
+++ b/libc/nptl/tst-_res1mod2.c
@@ -0,0 +1 @@
+/* Nothing. */
diff --git a/libc/nptl/tst-align.c b/libc/nptl/tst-align.c
new file mode 100644
index 000000000..2de9d7a10
--- /dev/null
+++ b/libc/nptl/tst-align.c
@@ -0,0 +1,71 @@
+/* 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>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <tst-stack-align.h>
+
+static void *
+tf (void *arg)
+{
+ bool ok = true;
+
+ puts ("in thread");
+
+ if (TEST_STACK_ALIGN ())
+ ok = false;
+
+ return ok ? NULL : (void *) -1l;
+}
+
+static int
+do_test (void)
+{
+ bool ok = true;
+
+ puts ("in main");
+
+ if (TEST_STACK_ALIGN ())
+ ok = false;
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ return 1;
+ }
+
+ void *res;
+ if (pthread_join (th, &res) != 0)
+ {
+ puts ("join failed");
+ return 1;
+ }
+
+ if (res != NULL)
+ ok = false;
+
+ return ok ? 0 : 1;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-align2.c b/libc/nptl/tst-align2.c
new file mode 100644
index 000000000..ec85f435b
--- /dev/null
+++ b/libc/nptl/tst-align2.c
@@ -0,0 +1,87 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <sched.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <tst-stack-align.h>
+
+static int
+f (void *arg)
+{
+ bool ok = true;
+
+ if (TEST_STACK_ALIGN ())
+ ok = false;
+
+ return ok ? 0 : 1;
+}
+
+static int
+do_test (void)
+{
+ bool ok = true;
+
+ puts ("in main");
+
+ if (TEST_STACK_ALIGN ())
+ ok = false;
+
+#ifdef __ia64__
+ extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base,
+ size_t __child_stack_size, int __flags,
+ void *__arg, ...);
+ char st[256 * 1024];
+ pid_t p = __clone2 (f, st, sizeof (st), 0, 0);
+#else
+ char st[128 * 1024];
+ pid_t p = clone (f, st + sizeof (st), 0, 0);
+#endif
+ if (p == -1)
+ {
+ printf("clone failed: %m\n");
+ return 1;
+ }
+
+ int e;
+ if (waitpid (p, &e, __WCLONE) != p)
+ {
+ puts ("waitpid failed");
+ kill (p, SIGKILL);
+ return 1;
+ }
+ if (!WIFEXITED (e))
+ {
+ if (WIFSIGNALED (e))
+ printf ("died from signal %s\n", strsignal (WTERMSIG (e)));
+ else
+ puts ("did not terminate correctly");
+ return 1;
+ }
+ if (WEXITSTATUS (e) != 0)
+ ok = false;
+
+ return ok ? 0 : 1;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-align3.c b/libc/nptl/tst-align3.c
new file mode 100644
index 000000000..64df14613
--- /dev/null
+++ b/libc/nptl/tst-align3.c
@@ -0,0 +1,57 @@
+/* Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2005.
+
+ 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>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <tst-stack-align.h>
+
+static bool ok = true;
+static pthread_once_t once = PTHREAD_ONCE_INIT;
+
+static void
+once_test (void)
+{
+ puts ("in once_test");
+
+ if (TEST_STACK_ALIGN ())
+ ok = false;
+}
+
+static int
+do_test (void)
+{
+ puts ("in main");
+
+ if (TEST_STACK_ALIGN ())
+ ok = false;
+
+ if (pthread_once (&once, once_test))
+ {
+ puts ("pthread once failed");
+ return 1;
+ }
+
+ return ok ? 0 : 1;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-atfork1.c b/libc/nptl/tst-atfork1.c
new file mode 100644
index 000000000..b42ab4246
--- /dev/null
+++ b/libc/nptl/tst-atfork1.c
@@ -0,0 +1,121 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+
+static int val;
+
+
+static void
+prepare1 (void)
+{
+ val *= 2;
+}
+
+static void
+prepare2 (void)
+{
+ ++val;
+}
+
+static void
+parent1 (void)
+{
+ val += 4;
+}
+
+static void
+parent2 (void)
+{
+ val *= 4;
+}
+
+static void
+child1 (void)
+{
+ val += 8;
+}
+
+static void
+child2 (void)
+{
+ val *= 8;
+}
+
+
+static int
+do_test (void)
+{
+ pid_t pid;
+ int status = 0;
+
+ if (pthread_atfork (prepare1, parent1, child1) != 0)
+ {
+ puts ("1st atfork failed");
+ exit (1);
+ }
+ if (pthread_atfork (prepare2, parent2, child2) != 0)
+ {
+ puts ("2nd atfork failed");
+ exit (1);
+ }
+
+ pid = fork ();
+ if (pid == -1)
+ {
+ puts ("fork failed");
+ exit (1);
+ }
+
+ if (pid != 0)
+ {
+ /* Parent. */
+ if (val != 24)
+ {
+ printf ("expected val=%d, got %d\n", 24, val);
+ exit (1);
+ }
+
+ if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid)
+ {
+ puts ("waitpid failed");
+ exit (1);
+ }
+ }
+ else
+ {
+ /* Child. */
+ if (val != 80)
+ {
+ printf ("expected val=%d, got %d\n", 80, val);
+ exit (2);
+ }
+ }
+
+ return status;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-atfork2.c b/libc/nptl/tst-atfork2.c
new file mode 100644
index 000000000..f162f80e6
--- /dev/null
+++ b/libc/nptl/tst-atfork2.c
@@ -0,0 +1,159 @@
+/* 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 <dlfcn.h>
+#include <errno.h>
+#include <mcheck.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+
+/* Must be exported. */
+int val;
+
+static void
+prepare (void)
+{
+ val *= 2;
+}
+
+static void
+parent (void)
+{
+ val += 4;
+}
+
+static void
+child (void)
+{
+ val += 8;
+}
+
+
+static int
+do_test (void)
+{
+ mtrace ();
+
+ if (pthread_atfork (prepare, parent, child) != 0)
+ {
+ puts ("do_test: atfork failed");
+ exit (1);
+ }
+
+ void *h = dlopen ("tst-atfork2mod.so", RTLD_LAZY);
+ if (h == NULL)
+ {
+ printf ("dlopen failed: %s\n", dlerror ());
+ exit (1);
+ }
+
+ /* First trial of fork. */
+ pid_t pid = fork ();
+ if (pid == -1)
+ {
+ puts ("1st fork failed");
+ exit (1);
+ }
+
+ if (pid == 0)
+ {
+ /* Child. */
+ if (val != 80)
+ {
+ printf ("1st: expected val=%d, got %d\n", 80, val);
+ exit (2);
+ }
+
+ exit (0);
+ }
+
+ /* Parent. */
+ if (val != 24)
+ {
+ printf ("1st: expected val=%d, got %d\n", 24, val);
+ exit (1);
+ }
+
+ int status;
+ if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid)
+ {
+ puts ("1st waitpid failed");
+ exit (1);
+ }
+
+ if (status != 0)
+ exit (status);
+
+ puts ("unloading now");
+
+ /* Unload the module. */
+ if (dlclose (h) != 0)
+ {
+ puts ("dlclose failed");
+ exit (1);
+ }
+
+ puts ("2nd fork");
+
+ /* Second fork trial. */
+ val = 1;
+ pid = fork ();
+ if (pid == -1)
+ {
+ puts ("2nd fork failed");
+ exit (1);
+ }
+
+ if (pid == 0)
+ {
+ /* Child. */
+ if (val != 10)
+ {
+ printf ("2nd: expected val=%d, got %d\n", 10, val);
+ exit (3);
+ }
+
+ exit (0);
+ }
+
+ /* Parent. */
+ if (val != 6)
+ {
+ printf ("2nd: expected val=%d, got %d\n", 6, val);
+ exit (1);
+ }
+
+ if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid)
+ {
+ puts ("2nd waitpid failed");
+ exit (1);
+ }
+
+ if (status != 0)
+ exit (status);
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-atfork2mod.c b/libc/nptl/tst-atfork2mod.c
new file mode 100644
index 000000000..a7fe68d24
--- /dev/null
+++ b/libc/nptl/tst-atfork2mod.c
@@ -0,0 +1,58 @@
+/* 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>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+extern int val;
+
+
+static void
+prepare (void)
+{
+ ++val;
+}
+
+static void
+parent (void)
+{
+ val *= 4;
+}
+
+static void
+child (void)
+{
+ val *= 8;
+}
+
+static void
+__attribute__ ((constructor))
+init (void)
+{
+ extern void *__dso_handle;
+ printf ("dsohandle = %p\n", __dso_handle);
+
+ if (pthread_atfork (prepare, parent, child) != 0)
+ {
+ puts ("init: atfork failed");
+ exit (1);
+ }
+}
diff --git a/libc/nptl/tst-attr1.c b/libc/nptl/tst-attr1.c
new file mode 100644
index 000000000..13b62a69d
--- /dev/null
+++ b/libc/nptl/tst-attr1.c
@@ -0,0 +1,306 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+int
+do_test (void)
+{
+ int i;
+ pthread_attr_t a;
+
+ if (pthread_attr_init (&a) != 0)
+ {
+ puts ("attr_init failed");
+ exit (1);
+ }
+
+ pthread_mutexattr_t ma;
+
+ if (pthread_mutexattr_init (&ma) != 0)
+ {
+ puts ("mutexattr_init failed");
+ exit (1);
+ }
+
+ pthread_rwlockattr_t rwa;
+
+ if (pthread_rwlockattr_init (&rwa) != 0)
+ {
+ puts ("rwlockattr_init failed");
+ exit (1);
+ }
+
+ /* XXX Remove if default value is clear. */
+ pthread_attr_setinheritsched (&a, PTHREAD_INHERIT_SCHED);
+ pthread_attr_setschedpolicy (&a, SCHED_OTHER);
+ pthread_attr_setscope (&a, PTHREAD_SCOPE_SYSTEM);
+
+ for (i = 0; i < 10000; ++i)
+ {
+ long int r = random ();
+
+ if (r != PTHREAD_CREATE_DETACHED && r != PTHREAD_CREATE_JOINABLE)
+ {
+ int e = pthread_attr_setdetachstate (&a, r);
+
+ if (e == 0)
+ {
+ printf ("attr_setdetachstate with value %ld succeeded\n", r);
+ exit (1);
+ }
+ if (e != EINVAL)
+ {
+ puts ("attr_setdetachstate didn't return EINVAL");
+ exit (1);
+ }
+
+ int s;
+ if (pthread_attr_getdetachstate (&a, &s) != 0)
+ {
+ puts ("attr_getdetachstate failed");
+ exit (1);
+ }
+
+ if (s != PTHREAD_CREATE_JOINABLE)
+ {
+ printf ("\
+detach state changed to %d by invalid setdetachstate call\n", s);
+ exit (1);
+ }
+ }
+
+ if (r != PTHREAD_INHERIT_SCHED && r != PTHREAD_EXPLICIT_SCHED)
+ {
+ int e = pthread_attr_setinheritsched (&a, r);
+
+ if (e == 0)
+ {
+ printf ("attr_setinheritsched with value %ld succeeded\n", r);
+ exit (1);
+ }
+ if (e != EINVAL)
+ {
+ puts ("attr_setinheritsched didn't return EINVAL");
+ exit (1);
+ }
+
+ int s;
+ if (pthread_attr_getinheritsched (&a, &s) != 0)
+ {
+ puts ("attr_getinheritsched failed");
+ exit (1);
+ }
+
+ if (s != PTHREAD_INHERIT_SCHED)
+ {
+ printf ("\
+inheritsched changed to %d by invalid setinheritsched call\n", s);
+ exit (1);
+ }
+ }
+
+ if (r != SCHED_OTHER && r != SCHED_RR && r != SCHED_FIFO)
+ {
+ int e = pthread_attr_setschedpolicy (&a, r);
+
+ if (e == 0)
+ {
+ printf ("attr_setschedpolicy with value %ld succeeded\n", r);
+ exit (1);
+ }
+ if (e != EINVAL)
+ {
+ puts ("attr_setschedpolicy didn't return EINVAL");
+ exit (1);
+ }
+
+ int s;
+ if (pthread_attr_getschedpolicy (&a, &s) != 0)
+ {
+ puts ("attr_getschedpolicy failed");
+ exit (1);
+ }
+
+ if (s != SCHED_OTHER)
+ {
+ printf ("\
+schedpolicy changed to %d by invalid setschedpolicy call\n", s);
+ exit (1);
+ }
+ }
+
+ if (r != PTHREAD_SCOPE_SYSTEM && r != PTHREAD_SCOPE_PROCESS)
+ {
+ int e = pthread_attr_setscope (&a, r);
+
+ if (e == 0)
+ {
+ printf ("attr_setscope with value %ld succeeded\n", r);
+ exit (1);
+ }
+ if (e != EINVAL)
+ {
+ puts ("attr_setscope didn't return EINVAL");
+ exit (1);
+ }
+
+ int s;
+ if (pthread_attr_getscope (&a, &s) != 0)
+ {
+ puts ("attr_getscope failed");
+ exit (1);
+ }
+
+ if (s != PTHREAD_SCOPE_SYSTEM)
+ {
+ printf ("\
+contentionscope changed to %d by invalid setscope call\n", s);
+ exit (1);
+ }
+ }
+
+ if (r != PTHREAD_PROCESS_PRIVATE && r != PTHREAD_PROCESS_SHARED)
+ {
+ int e = pthread_mutexattr_setpshared (&ma, r);
+
+ if (e == 0)
+ {
+ printf ("mutexattr_setpshared with value %ld succeeded\n", r);
+ exit (1);
+ }
+ if (e != EINVAL)
+ {
+ puts ("mutexattr_setpshared didn't return EINVAL");
+ exit (1);
+ }
+
+ int s;
+ if (pthread_mutexattr_getpshared (&ma, &s) != 0)
+ {
+ puts ("mutexattr_getpshared failed");
+ exit (1);
+ }
+
+ if (s != PTHREAD_PROCESS_PRIVATE)
+ {
+ printf ("\
+pshared changed to %d by invalid mutexattr_setpshared call\n", s);
+ exit (1);
+ }
+
+ e = pthread_rwlockattr_setpshared (&rwa, r);
+
+ if (e == 0)
+ {
+ printf ("rwlockattr_setpshared with value %ld succeeded\n", r);
+ exit (1);
+ }
+ if (e != EINVAL)
+ {
+ puts ("rwlockattr_setpshared didn't return EINVAL");
+ exit (1);
+ }
+
+ if (pthread_rwlockattr_getpshared (&rwa, &s) != 0)
+ {
+ puts ("rwlockattr_getpshared failed");
+ exit (1);
+ }
+
+ if (s != PTHREAD_PROCESS_PRIVATE)
+ {
+ printf ("\
+pshared changed to %d by invalid rwlockattr_setpshared call\n", s);
+ exit (1);
+ }
+ }
+
+ if (r != PTHREAD_CANCEL_ENABLE && r != PTHREAD_CANCEL_DISABLE)
+ {
+ int e = pthread_setcancelstate (r, NULL);
+
+ if (e == 0)
+ {
+ printf ("setcancelstate with value %ld succeeded\n", r);
+ exit (1);
+ }
+
+ if (e != EINVAL)
+ {
+ puts ("setcancelstate didn't return EINVAL");
+ exit (1);
+ }
+
+ int s;
+ if (pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, &s) != 0)
+ {
+ puts ("setcancelstate failed for PTHREAD_CANCEL_ENABLE");
+ exit (1);
+ }
+
+ if (s != PTHREAD_CANCEL_ENABLE)
+ {
+ puts ("invalid setcancelstate changed state");
+ exit (1);
+ }
+ }
+
+ if (r != PTHREAD_CANCEL_DEFERRED && r != PTHREAD_CANCEL_ASYNCHRONOUS)
+ {
+ int e = pthread_setcanceltype (r, NULL);
+
+ if (e == 0)
+ {
+ printf ("setcanceltype with value %ld succeeded\n", r);
+ exit (1);
+ }
+
+ if (e != EINVAL)
+ {
+ puts ("setcanceltype didn't return EINVAL");
+ exit (1);
+ }
+
+ int s;
+ if (pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, &s) != 0)
+ {
+ puts ("setcanceltype failed for PTHREAD_CANCEL_DEFERRED");
+ exit (1);
+ }
+
+ if (s != PTHREAD_CANCEL_DEFERRED)
+ {
+ puts ("invalid setcanceltype changed state");
+ exit (1);
+ }
+ }
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-attr2.c b/libc/nptl/tst-attr2.c
new file mode 100644
index 000000000..a60598dd7
--- /dev/null
+++ b/libc/nptl/tst-attr2.c
@@ -0,0 +1,317 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+int
+do_test (void)
+{
+ pthread_attr_t a;
+
+ if (pthread_attr_init (&a) != 0)
+ {
+ puts ("attr_init failed");
+ exit (1);
+ }
+
+ /* Check default value of detach state. */
+ int s;
+ if (pthread_attr_getdetachstate (&a, &s) != 0)
+ {
+ puts ("1st attr_getdestachstate failed");
+ exit (1);
+ }
+ if (s != PTHREAD_CREATE_JOINABLE)
+ {
+ printf ("\
+default detach state wrong: %d, expected %d (PTHREAD_CREATE_JOINABLE)\n",
+ s, PTHREAD_CREATE_JOINABLE);
+ exit (1);
+ }
+
+ int e = pthread_attr_setdetachstate (&a, PTHREAD_CREATE_DETACHED);
+ if (e != 0)
+ {
+ puts ("1st attr_setdetachstate failed");
+ exit (1);
+ }
+ if (pthread_attr_getdetachstate (&a, &s) != 0)
+ {
+ puts ("2nd attr_getdestachstate failed");
+ exit (1);
+ }
+ if (s != PTHREAD_CREATE_DETACHED)
+ {
+ puts ("PTHREAD_CREATE_DETACHED set, but not given back");
+ exit (1);
+ }
+
+ e = pthread_attr_setdetachstate (&a, PTHREAD_CREATE_JOINABLE);
+ if (e != 0)
+ {
+ puts ("2nd attr_setdetachstate failed");
+ exit (1);
+ }
+ if (pthread_attr_getdetachstate (&a, &s) != 0)
+ {
+ puts ("3rd attr_getdestachstate failed");
+ exit (1);
+ }
+ if (s != PTHREAD_CREATE_JOINABLE)
+ {
+ puts ("PTHREAD_CREATE_JOINABLE set, but not given back");
+ exit (1);
+ }
+
+
+ size_t g;
+ if (pthread_attr_getguardsize (&a, &g) != 0)
+ {
+ puts ("1st attr_getguardsize failed");
+ exit (1);
+ }
+ if (g != (size_t) sysconf (_SC_PAGESIZE))
+ {
+ printf ("default guardsize %zu, expected %ld (PAGESIZE)\n",
+ g, sysconf (_SC_PAGESIZE));
+ exit (1);
+ }
+
+ e = pthread_attr_setguardsize (&a, 0);
+ if (e != 0)
+ {
+ puts ("1st attr_setguardsize failed");
+ exit (1);
+ }
+ if (pthread_attr_getguardsize (&a, &g) != 0)
+ {
+ puts ("2nd attr_getguardsize failed");
+ exit (1);
+ }
+ if (g != 0)
+ {
+ printf ("guardsize set to zero but %zu returned\n", g);
+ exit (1);
+ }
+
+ e = pthread_attr_setguardsize (&a, 1);
+ if (e != 0)
+ {
+ puts ("2nd attr_setguardsize failed");
+ exit (1);
+ }
+ if (pthread_attr_getguardsize (&a, &g) != 0)
+ {
+ puts ("3rd attr_getguardsize failed");
+ exit (1);
+ }
+ if (g != 1)
+ {
+ printf ("guardsize set to 1 but %zu returned\n", g);
+ exit (1);
+ }
+
+
+ if (pthread_attr_getinheritsched (&a, &s) != 0)
+ {
+ puts ("1st attr_getinheritsched failed");
+ exit (1);
+ }
+ /* XXX What is the correct default value. */
+ if (s != PTHREAD_INHERIT_SCHED && s != PTHREAD_EXPLICIT_SCHED)
+ {
+ puts ("incorrect default value for inheritsched");
+ exit (1);
+ }
+
+ e = pthread_attr_setinheritsched (&a, PTHREAD_EXPLICIT_SCHED);
+ if (e != 0)
+ {
+ puts ("1st attr_setinheritsched failed");
+ exit (1);
+ }
+ if (pthread_attr_getinheritsched (&a, &s) != 0)
+ {
+ puts ("2nd attr_getinheritsched failed");
+ exit (1);
+ }
+ if (s != PTHREAD_EXPLICIT_SCHED)
+ {
+ printf ("inheritsched set to PTHREAD_EXPLICIT_SCHED, but got %d\n", s);
+ exit (1);
+ }
+
+ e = pthread_attr_setinheritsched (&a, PTHREAD_INHERIT_SCHED);
+ if (e != 0)
+ {
+ puts ("2nd attr_setinheritsched failed");
+ exit (1);
+ }
+ if (pthread_attr_getinheritsched (&a, &s) != 0)
+ {
+ puts ("3rd attr_getinheritsched failed");
+ exit (1);
+ }
+ if (s != PTHREAD_INHERIT_SCHED)
+ {
+ printf ("inheritsched set to PTHREAD_INHERIT_SCHED, but got %d\n", s);
+ exit (1);
+ }
+
+
+ if (pthread_attr_getschedpolicy (&a, &s) != 0)
+ {
+ puts ("1st attr_getschedpolicy failed");
+ exit (1);
+ }
+ /* XXX What is the correct default value. */
+ if (s != SCHED_OTHER && s != SCHED_FIFO && s != SCHED_RR)
+ {
+ puts ("incorrect default value for schedpolicy");
+ exit (1);
+ }
+
+ e = pthread_attr_setschedpolicy (&a, SCHED_RR);
+ if (e != 0)
+ {
+ puts ("1st attr_setschedpolicy failed");
+ exit (1);
+ }
+ if (pthread_attr_getschedpolicy (&a, &s) != 0)
+ {
+ puts ("2nd attr_getschedpolicy failed");
+ exit (1);
+ }
+ if (s != SCHED_RR)
+ {
+ printf ("schedpolicy set to SCHED_RR, but got %d\n", s);
+ exit (1);
+ }
+
+ e = pthread_attr_setschedpolicy (&a, SCHED_FIFO);
+ if (e != 0)
+ {
+ puts ("2nd attr_setschedpolicy failed");
+ exit (1);
+ }
+ if (pthread_attr_getschedpolicy (&a, &s) != 0)
+ {
+ puts ("3rd attr_getschedpolicy failed");
+ exit (1);
+ }
+ if (s != SCHED_FIFO)
+ {
+ printf ("schedpolicy set to SCHED_FIFO, but got %d\n", s);
+ exit (1);
+ }
+
+ e = pthread_attr_setschedpolicy (&a, SCHED_OTHER);
+ if (e != 0)
+ {
+ puts ("3rd attr_setschedpolicy failed");
+ exit (1);
+ }
+ if (pthread_attr_getschedpolicy (&a, &s) != 0)
+ {
+ puts ("4th attr_getschedpolicy failed");
+ exit (1);
+ }
+ if (s != SCHED_OTHER)
+ {
+ printf ("schedpolicy set to SCHED_OTHER, but got %d\n", s);
+ exit (1);
+ }
+
+
+ if (pthread_attr_getscope (&a, &s) != 0)
+ {
+ puts ("1st attr_getscope failed");
+ exit (1);
+ }
+ /* XXX What is the correct default value. */
+ if (s != PTHREAD_SCOPE_SYSTEM && s != PTHREAD_SCOPE_PROCESS)
+ {
+ puts ("incorrect default value for contentionscope");
+ exit (1);
+ }
+
+ e = pthread_attr_setscope (&a, PTHREAD_SCOPE_PROCESS);
+ if (e != ENOTSUP)
+ {
+ if (e != 0)
+ {
+ puts ("1st attr_setscope failed");
+ exit (1);
+ }
+ if (pthread_attr_getscope (&a, &s) != 0)
+ {
+ puts ("2nd attr_getscope failed");
+ exit (1);
+ }
+ if (s != PTHREAD_SCOPE_PROCESS)
+ {
+ printf ("\
+contentionscope set to PTHREAD_SCOPE_PROCESS, but got %d\n", s);
+ exit (1);
+ }
+ }
+
+ e = pthread_attr_setscope (&a, PTHREAD_SCOPE_SYSTEM);
+ if (e != 0)
+ {
+ puts ("2nd attr_setscope failed");
+ exit (1);
+ }
+ if (pthread_attr_getscope (&a, &s) != 0)
+ {
+ puts ("3rd attr_getscope failed");
+ exit (1);
+ }
+ if (s != PTHREAD_SCOPE_SYSTEM)
+ {
+ printf ("contentionscope set to PTHREAD_SCOPE_SYSTEM, but got %d\n", s);
+ exit (1);
+ }
+
+ char buf[1];
+ e = pthread_attr_setstack (&a, buf, 1);
+ if (e != EINVAL)
+ {
+ puts ("setstack with size 1 did not produce EINVAL");
+ exit (1);
+ }
+
+ e = pthread_attr_setstacksize (&a, 1);
+ if (e != EINVAL)
+ {
+ puts ("setstacksize with size 1 did not produce EINVAL");
+ exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-attr3.c b/libc/nptl/tst-attr3.c
new file mode 100644
index 000000000..733e8512d
--- /dev/null
+++ b/libc/nptl/tst-attr3.c
@@ -0,0 +1,422 @@
+/* pthread_getattr_np test.
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 <errno.h>
+#include <error.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <stackinfo.h>
+
+static void *
+tf (void *arg)
+{
+ pthread_attr_t a, *ap, a2;
+ int err;
+ void *result = NULL;
+
+ if (arg == NULL)
+ {
+ ap = &a2;
+ err = pthread_attr_init (ap);
+ if (err)
+ {
+ error (0, err, "pthread_attr_init failed");
+ return tf;
+ }
+ }
+ else
+ ap = (pthread_attr_t *) arg;
+
+ err = pthread_getattr_np (pthread_self (), &a);
+ if (err)
+ {
+ error (0, err, "pthread_getattr_np failed");
+ result = tf;
+ }
+
+ int detachstate1, detachstate2;
+ err = pthread_attr_getdetachstate (&a, &detachstate1);
+ if (err)
+ {
+ error (0, err, "pthread_attr_getdetachstate failed");
+ result = tf;
+ }
+ else
+ {
+ err = pthread_attr_getdetachstate (ap, &detachstate2);
+ if (err)
+ {
+ error (0, err, "pthread_attr_getdetachstate failed");
+ result = tf;
+ }
+ else if (detachstate1 != detachstate2)
+ {
+ error (0, 0, "detachstate differs %d != %d",
+ detachstate1, detachstate2);
+ result = tf;
+ }
+ }
+
+ void *stackaddr;
+ size_t stacksize;
+ err = pthread_attr_getstack (&a, &stackaddr, &stacksize);
+ if (err)
+ {
+ error (0, err, "pthread_attr_getstack failed");
+ result = tf;
+ }
+ else if ((void *) &a < stackaddr
+ || (void *) &a >= stackaddr + stacksize)
+ {
+ error (0, 0, "pthread_attr_getstack returned range does not cover thread's stack");
+ result = tf;
+ }
+ else
+ printf ("thread stack %p-%p (0x%zx)\n", stackaddr, stackaddr + stacksize,
+ stacksize);
+
+ size_t guardsize1, guardsize2;
+ err = pthread_attr_getguardsize (&a, &guardsize1);
+ if (err)
+ {
+ error (0, err, "pthread_attr_getguardsize failed");
+ result = tf;
+ }
+ else
+ {
+ err = pthread_attr_getguardsize (ap, &guardsize2);
+ if (err)
+ {
+ error (0, err, "pthread_attr_getguardsize failed");
+ result = tf;
+ }
+ else if (guardsize1 != guardsize2)
+ {
+ error (0, 0, "guardsize differs %zd != %zd",
+ guardsize1, guardsize2);
+ result = tf;
+ }
+ else
+ printf ("thread guardsize %zd\n", guardsize1);
+ }
+
+ int scope1, scope2;
+ err = pthread_attr_getscope (&a, &scope1);
+ if (err)
+ {
+ error (0, err, "pthread_attr_getscope failed");
+ result = tf;
+ }
+ else
+ {
+ err = pthread_attr_getscope (ap, &scope2);
+ if (err)
+ {
+ error (0, err, "pthread_attr_getscope failed");
+ result = tf;
+ }
+ else if (scope1 != scope2)
+ {
+ error (0, 0, "scope differs %d != %d",
+ scope1, scope2);
+ result = tf;
+ }
+ }
+
+ int inheritsched1, inheritsched2;
+ err = pthread_attr_getinheritsched (&a, &inheritsched1);
+ if (err)
+ {
+ error (0, err, "pthread_attr_getinheritsched failed");
+ result = tf;
+ }
+ else
+ {
+ err = pthread_attr_getinheritsched (ap, &inheritsched2);
+ if (err)
+ {
+ error (0, err, "pthread_attr_getinheritsched failed");
+ result = tf;
+ }
+ else if (inheritsched1 != inheritsched2)
+ {
+ error (0, 0, "inheritsched differs %d != %d",
+ inheritsched1, inheritsched2);
+ result = tf;
+ }
+ }
+
+ cpu_set_t c1, c2;
+ err = pthread_getaffinity_np (pthread_self (), sizeof (c1), &c1);
+ if (err == 0)
+ {
+ err = pthread_attr_getaffinity_np (&a, sizeof (c2), &c2);
+ if (err)
+ {
+ error (0, err, "pthread_attr_getaffinity_np failed");
+ result = tf;
+ }
+ else if (memcmp (&c1, &c2, sizeof (c1)))
+ {
+ error (0, 0, "pthread_attr_getaffinity_np returned different CPU mask than pthread_getattr_np");
+ result = tf;
+ }
+ }
+
+ err = pthread_attr_destroy (&a);
+ if (err)
+ {
+ error (0, err, "pthread_attr_destroy failed");
+ result = tf;
+ }
+
+ if (ap == &a2)
+ {
+ err = pthread_attr_destroy (ap);
+ if (err)
+ {
+ error (0, err, "pthread_attr_destroy failed");
+ result = tf;
+ }
+ }
+
+ return result;
+}
+
+
+static int
+do_test (void)
+{
+ int result = 0;
+ pthread_attr_t a;
+ cpu_set_t c1, c2;
+
+ int err = pthread_attr_init (&a);
+ if (err)
+ {
+ error (0, err, "pthread_attr_init failed");
+ result = 1;
+ }
+
+ err = pthread_attr_getaffinity_np (&a, sizeof (c1), &c1);
+ if (err && err != ENOSYS)
+ {
+ error (0, err, "pthread_attr_getaffinity_np failed");
+ result = 1;
+ }
+
+ err = pthread_attr_destroy (&a);
+ if (err)
+ {
+ error (0, err, "pthread_attr_destroy failed");
+ result = 1;
+ }
+
+ err = pthread_getattr_np (pthread_self (), &a);
+ if (err)
+ {
+ error (0, err, "pthread_getattr_np failed");
+ result = 1;
+ }
+
+ int detachstate;
+ err = pthread_attr_getdetachstate (&a, &detachstate);
+ if (err)
+ {
+ error (0, err, "pthread_attr_getdetachstate failed");
+ result = 1;
+ }
+ else if (detachstate != PTHREAD_CREATE_JOINABLE)
+ {
+ error (0, 0, "initial thread not joinable");
+ result = 1;
+ }
+
+ void *stackaddr;
+ size_t stacksize;
+ err = pthread_attr_getstack (&a, &stackaddr, &stacksize);
+ if (err)
+ {
+ error (0, err, "pthread_attr_getstack failed");
+ result = 1;
+ }
+ else if ((void *) &a < stackaddr
+ || (void *) &a >= stackaddr + stacksize)
+ {
+ error (0, 0, "pthread_attr_getstack returned range does not cover main's stack");
+ result = 1;
+ }
+ else
+ printf ("initial thread stack %p-%p (0x%zx)\n", stackaddr,
+ stackaddr + stacksize, stacksize);
+
+ size_t guardsize;
+ err = pthread_attr_getguardsize (&a, &guardsize);
+ if (err)
+ {
+ error (0, err, "pthread_attr_getguardsize failed");
+ result = 1;
+ }
+ else if (guardsize != 0)
+ {
+ error (0, 0, "pthread_attr_getguardsize returned %zd != 0",
+ guardsize);
+ result = 1;
+ }
+
+ int scope;
+ err = pthread_attr_getscope (&a, &scope);
+ if (err)
+ {
+ error (0, err, "pthread_attr_getscope failed");
+ result = 1;
+ }
+ else if (scope != PTHREAD_SCOPE_SYSTEM)
+ {
+ error (0, 0, "pthread_attr_getscope returned %d != PTHREAD_SCOPE_SYSTEM",
+ scope);
+ result = 1;
+ }
+
+ int inheritsched;
+ err = pthread_attr_getinheritsched (&a, &inheritsched);
+ if (err)
+ {
+ error (0, err, "pthread_attr_getinheritsched failed");
+ result = 1;
+ }
+ else if (inheritsched != PTHREAD_INHERIT_SCHED)
+ {
+ error (0, 0, "pthread_attr_getinheritsched returned %d != PTHREAD_INHERIT_SCHED",
+ inheritsched);
+ result = 1;
+ }
+
+ err = pthread_getaffinity_np (pthread_self (), sizeof (c1), &c1);
+ if (err == 0)
+ {
+ err = pthread_attr_getaffinity_np (&a, sizeof (c2), &c2);
+ if (err)
+ {
+ error (0, err, "pthread_attr_getaffinity_np failed");
+ result = 1;
+ }
+ else if (memcmp (&c1, &c2, sizeof (c1)))
+ {
+ error (0, 0, "pthread_attr_getaffinity_np returned different CPU mask than pthread_getattr_np");
+ result = 1;
+ }
+ }
+
+ err = pthread_attr_destroy (&a);
+ if (err)
+ {
+ error (0, err, "pthread_attr_destroy failed");
+ result = 1;
+ }
+
+ pthread_t th;
+ err = pthread_create (&th, NULL, tf, NULL);
+ if (err)
+ {
+ error (0, err, "pthread_create #1 failed");
+ result = 1;
+ }
+ else
+ {
+ void *ret;
+ err = pthread_join (th, &ret);
+ if (err)
+ {
+ error (0, err, "pthread_join #1 failed");
+ result = 1;
+ }
+ else if (ret != NULL)
+ result = 1;
+ }
+
+ err = pthread_attr_init (&a);
+ if (err)
+ {
+ error (0, err, "pthread_attr_init failed");
+ result = 1;
+ }
+
+ err = pthread_create (&th, &a, tf, &a);
+ if (err)
+ {
+ error (0, err, "pthread_create #2 failed");
+ result = 1;
+ }
+ else
+ {
+ void *ret;
+ err = pthread_join (th, &ret);
+ if (err)
+ {
+ error (0, err, "pthread_join #2 failed");
+ result = 1;
+ }
+ else if (ret != NULL)
+ result = 1;
+ }
+
+ err = pthread_attr_setguardsize (&a, 16 * sysconf (_SC_PAGESIZE));
+ if (err)
+ {
+ error (0, err, "pthread_attr_setguardsize failed");
+ result = 1;
+ }
+
+ err = pthread_create (&th, &a, tf, &a);
+ if (err)
+ {
+ error (0, err, "pthread_create #3 failed");
+ result = 1;
+ }
+ else
+ {
+ void *ret;
+ err = pthread_join (th, &ret);
+ if (err)
+ {
+ error (0, err, "pthread_join #3 failed");
+ result = 1;
+ }
+ else if (ret != NULL)
+ result = 1;
+ }
+
+ err = pthread_attr_destroy (&a);
+ if (err)
+ {
+ error (0, err, "pthread_attr_destroy failed");
+ result = 1;
+ }
+
+ return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-backtrace1.c b/libc/nptl/tst-backtrace1.c
new file mode 100644
index 000000000..903c49374
--- /dev/null
+++ b/libc/nptl/tst-backtrace1.c
@@ -0,0 +1,86 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
+
+ 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 <execinfo.h>
+#include <pthread.h>
+#include <stdio.h>
+
+#define BT_SIZE 64
+void *bt_array[BT_SIZE];
+int bt_cnt;
+
+int
+do_bt (void)
+{
+ bt_cnt = backtrace (bt_array, BT_SIZE);
+ return 56;
+}
+
+int
+call_do_bt (void)
+{
+ return do_bt () + 1;
+}
+
+void *
+tf (void *arg)
+{
+ if (call_do_bt () != 57)
+ return (void *) 1L;
+ return NULL;
+}
+
+int
+do_test (void)
+{
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL))
+ {
+ puts ("create failed");
+ return 1;
+ }
+
+ void *res;
+ if (pthread_join (th, &res))
+ {
+ puts ("join failed");
+ return 1;
+ }
+
+ if (res != NULL)
+ {
+ puts ("thread failed");
+ return 1;
+ }
+
+ char **text = backtrace_symbols (bt_array, bt_cnt);
+ if (text == NULL)
+ {
+ puts ("backtrace_symbols failed");
+ return 1;
+ }
+
+ for (int i = 0; i < bt_cnt; ++i)
+ puts (text[i]);
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-barrier1.c b/libc/nptl/tst-barrier1.c
new file mode 100644
index 000000000..2859fb4ca
--- /dev/null
+++ b/libc/nptl/tst-barrier1.c
@@ -0,0 +1,71 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+
+
+static int
+do_test (void)
+{
+ pthread_barrier_t b;
+ int e;
+ int cnt;
+
+ e = pthread_barrier_init (&b, NULL, 0);
+ if (e == 0)
+ {
+ puts ("barrier_init with count 0 succeeded");
+ return 1;
+ }
+ if (e != EINVAL)
+ {
+ puts ("barrier_init with count 0 didn't return EINVAL");
+ return 1;
+ }
+
+ if (pthread_barrier_init (&b, NULL, 1) != 0)
+ {
+ puts ("real barrier_init failed");
+ return 1;
+ }
+
+ for (cnt = 0; cnt < 10; ++cnt)
+ {
+ e = pthread_barrier_wait (&b);
+
+ if (e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait didn't return PTHREAD_BARRIER_SERIAL_THREAD");
+ return 1;
+ }
+ }
+
+ if (pthread_barrier_destroy (&b) != 0)
+ {
+ puts ("barrier_destroy failed");
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-barrier2.c b/libc/nptl/tst-barrier2.c
new file mode 100644
index 000000000..7f588694d
--- /dev/null
+++ b/libc/nptl/tst-barrier2.c
@@ -0,0 +1,185 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+
+
+static int
+do_test (void)
+{
+ size_t ps = sysconf (_SC_PAGESIZE);
+ char tmpfname[] = "/tmp/tst-barrier2.XXXXXX";
+ char data[ps];
+ void *mem;
+ int fd;
+ pthread_barrier_t *b;
+ pthread_barrierattr_t a;
+ pid_t pid;
+ int serials = 0;
+ int cnt;
+ int status;
+ int p;
+
+ fd = mkstemp (tmpfname);
+ if (fd == -1)
+ {
+ printf ("cannot open temporary file: %m\n");
+ return 1;
+ }
+
+ /* Make sure it is always removed. */
+ unlink (tmpfname);
+
+ /* Create one page of data. */
+ memset (data, '\0', ps);
+
+ /* Write the data to the file. */
+ if (write (fd, data, ps) != (ssize_t) ps)
+ {
+ puts ("short write");
+ return 1;
+ }
+
+ mem = mmap (NULL, ps, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if (mem == MAP_FAILED)
+ {
+ printf ("mmap failed: %m\n");
+ return 1;
+ }
+
+ b = (pthread_barrier_t *) (((uintptr_t) mem + __alignof (pthread_barrier_t))
+ & ~(__alignof (pthread_barrier_t) - 1));
+
+ if (pthread_barrierattr_init (&a) != 0)
+ {
+ puts ("barrierattr_init failed");
+ return 1;
+ }
+
+ if (pthread_barrierattr_getpshared (&a, &p) != 0)
+ {
+ puts ("1st barrierattr_getpshared failed");
+ return 1;
+ }
+
+ if (p != PTHREAD_PROCESS_PRIVATE)
+ {
+ puts ("default pshared value wrong");
+ return 1;
+ }
+
+ if (pthread_barrierattr_setpshared (&a, PTHREAD_PROCESS_SHARED) != 0)
+ {
+ puts ("barrierattr_setpshared failed");
+ return 1;
+ }
+
+ if (pthread_barrierattr_getpshared (&a, &p) != 0)
+ {
+ puts ("2nd barrierattr_getpshared failed");
+ return 1;
+ }
+
+ if (p != PTHREAD_PROCESS_SHARED)
+ {
+ puts ("pshared value after setpshared call wrong");
+ return 1;
+ }
+
+ if (pthread_barrier_init (b, &a, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ return 1;
+ }
+
+ if (pthread_barrierattr_destroy (&a) != 0)
+ {
+ puts ("barrierattr_destroy failed");
+ return 1;
+ }
+
+ puts ("going to fork now");
+ pid = fork ();
+ if (pid == -1)
+ {
+ puts ("fork failed");
+ return 1;
+ }
+
+ /* Just to be sure we don't hang forever. */
+ alarm (4);
+
+#define N 30
+ for (cnt = 0; cnt < N; ++cnt)
+ {
+ int e;
+
+ e = pthread_barrier_wait (b);
+ if (e == PTHREAD_BARRIER_SERIAL_THREAD)
+ ++serials;
+ else if (e != 0)
+ {
+ printf ("%s: barrier_wait returned value %d != 0 and PTHREAD_BARRIER_SERIAL_THREAD\n",
+ pid == 0 ? "child" : "parent", e);
+ return 1;
+ }
+ }
+
+ alarm (0);
+
+ printf ("%s: was %d times the serial thread\n",
+ pid == 0 ? "child" : "parent", serials);
+
+ if (pid == 0)
+ /* The child. Pass the number of times we had the serializing
+ thread back to the parent. */
+ exit (serials);
+
+ if (waitpid (pid, &status, 0) != pid)
+ {
+ puts ("waitpid failed");
+ return 1;
+ }
+
+ if (!WIFEXITED (status))
+ {
+ puts ("child exited abnormally");
+ return 1;
+ }
+
+ if (WEXITSTATUS (status) + serials != N)
+ {
+ printf ("total number of serials is %d, expected %d\n",
+ WEXITSTATUS (status) + serials, N);
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-barrier3.c b/libc/nptl/tst-barrier3.c
new file mode 100644
index 000000000..b5478f827
--- /dev/null
+++ b/libc/nptl/tst-barrier3.c
@@ -0,0 +1,154 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+/* Test of POSIX barriers. */
+
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define NTHREADS 20
+
+#define ROUNDS 20
+
+static pthread_barrier_t barriers[NTHREADS];
+
+static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+static int counters[NTHREADS];
+static int serial[NTHREADS];
+
+static void *
+worker (void *arg)
+{
+ void *result = NULL;
+ int nr = (long int) arg;
+ int i;
+
+ for (i = 0; i < ROUNDS; ++i)
+ {
+ int j;
+ int retval;
+
+ if (nr == 0)
+ {
+ memset (counters, '\0', sizeof (counters));
+ memset (serial, '\0', sizeof (serial));
+ }
+
+ retval = pthread_barrier_wait (&barriers[NTHREADS - 1]);
+ if (retval != 0 && retval != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("thread %d failed to wait for all the others\n", nr);
+ result = (void *) 1;
+ }
+
+ for (j = nr; j < NTHREADS; ++j)
+ {
+ /* Increment the counter for this round. */
+ pthread_mutex_lock (&lock);
+ ++counters[j];
+ pthread_mutex_unlock (&lock);
+
+ /* Wait for the rest. */
+ retval = pthread_barrier_wait (&barriers[j]);
+
+ /* Test the result. */
+ if (nr == 0 && counters[j] != j + 1)
+ {
+ printf ("barrier in round %d released but count is %d\n",
+ j, counters[j]);
+ result = (void *) 1;
+ }
+
+ if (retval != 0)
+ {
+ if (retval != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("thread %d in round %d has nonzero return value != PTHREAD_BARRIER_SERIAL_THREAD\n",
+ nr, j);
+ result = (void *) 1;
+ }
+ else
+ {
+ pthread_mutex_lock (&lock);
+ ++serial[j];
+ pthread_mutex_unlock (&lock);
+ }
+ }
+
+ /* Wait for the rest again. */
+ retval = pthread_barrier_wait (&barriers[j]);
+
+ /* Now we can check whether exactly one thread was serializing. */
+ if (nr == 0 && serial[j] != 1)
+ {
+ printf ("not exactly one serial thread in round %d\n", j);
+ result = (void *) 1;
+ }
+ }
+ }
+
+ return result;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#define TIMEOUT 60
+static int
+do_test (void)
+{
+ pthread_t threads[NTHREADS];
+ int i;
+ void *res;
+ int result = 0;
+
+ /* Initialized the barrier variables. */
+ for (i = 0; i < NTHREADS; ++i)
+ if (pthread_barrier_init (&barriers[i], NULL, i + 1) != 0)
+ {
+ printf ("Failed to initialize barrier %d\n", i);
+ exit (1);
+ }
+
+ /* Start the threads. */
+ for (i = 0; i < NTHREADS; ++i)
+ if (pthread_create (&threads[i], NULL, worker, (void *) (long int) i) != 0)
+ {
+ printf ("Failed to start thread %d\n", i);
+ exit (1);
+ }
+
+ /* And wait for them. */
+ for (i = 0; i < NTHREADS; ++i)
+ if (pthread_join (threads[i], &res) != 0 || res != NULL)
+ {
+ printf ("thread %d returned a failure\n", i);
+ result = 1;
+ }
+ else
+ printf ("joined threads %d\n", i);
+
+ if (result == 0)
+ puts ("all OK");
+
+ return result;
+}
+
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-barrier4.c b/libc/nptl/tst-barrier4.c
new file mode 100644
index 000000000..56ea044e0
--- /dev/null
+++ b/libc/nptl/tst-barrier4.c
@@ -0,0 +1,121 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
+
+ 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. */
+
+/* This is a test for behavior not guaranteed by POSIX. */
+#include <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+
+
+static pthread_barrier_t b1;
+static pthread_barrier_t b2;
+
+
+#define N 20
+
+static void *
+tf (void *arg)
+{
+ int round = 0;
+
+ while (round++ < 30)
+ {
+ if (pthread_barrier_wait (&b1) == PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ pthread_barrier_destroy (&b1);
+ if (pthread_barrier_init (&b1, NULL, N) != 0)
+ {
+ puts ("tf: 1st barrier_init failed");
+ exit (1);
+ }
+ }
+
+ if (pthread_barrier_wait (&b2) == PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ pthread_barrier_destroy (&b2);
+ if (pthread_barrier_init (&b2, NULL, N) != 0)
+ {
+ puts ("tf: 2nd barrier_init failed");
+ exit (1);
+ }
+ }
+ }
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_attr_t at;
+ int cnt;
+
+ if (pthread_attr_init (&at) != 0)
+ {
+ puts ("attr_init failed");
+ return 1;
+ }
+
+ if (pthread_attr_setstacksize (&at, 1 * 1024 * 1024) != 0)
+ {
+ puts ("attr_setstacksize failed");
+ return 1;
+ }
+
+ if (pthread_barrier_init (&b1, NULL, N) != 0)
+ {
+ puts ("1st barrier_init failed");
+ return 1;
+ }
+
+ if (pthread_barrier_init (&b2, NULL, N) != 0)
+ {
+ puts ("2nd barrier_init failed");
+ return 1;
+ }
+
+ pthread_t th[N - 1];
+ for (cnt = 0; cnt < N - 1; ++cnt)
+ if (pthread_create (&th[cnt], &at, tf, NULL) != 0)
+ {
+ puts ("pthread_create failed");
+ return 1;
+ }
+
+ if (pthread_attr_destroy (&at) != 0)
+ {
+ puts ("attr_destroy failed");
+ return 1;
+ }
+
+ tf (NULL);
+
+ for (cnt = 0; cnt < N - 1; ++cnt)
+ if (pthread_join (th[cnt], NULL) != 0)
+ {
+ puts ("pthread_join failed");
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-basic1.c b/libc/nptl/tst-basic1.c
new file mode 100644
index 000000000..7637c8e49
--- /dev/null
+++ b/libc/nptl/tst-basic1.c
@@ -0,0 +1,82 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+
+static pid_t pid;
+
+static void *
+tf (void *a)
+{
+ if (getpid () != pid)
+ {
+ write (2, "pid mismatch\n", 13);
+ _exit (1);
+ }
+
+ return a;
+}
+
+
+int
+do_test (void)
+{
+ pid = getpid ();
+
+#define N 2
+ pthread_t t[N];
+ int i;
+
+ for (i = 0; i < N; ++i)
+ if (pthread_create (&t[i], NULL, tf, (void *) (long int) (i + 1)) != 0)
+ {
+ write (2, "create failed\n", 14);
+ _exit (1);
+ }
+ else
+ printf ("created thread %d\n", i);
+
+ for (i = 0; i < N; ++i)
+ {
+ void *r;
+ int e;
+ if ((e = pthread_join (t[i], &r)) != 0)
+ {
+ printf ("join failed: %d\n", e);
+ _exit (1);
+ }
+ else if (r != (void *) (long int) (i + 1))
+ {
+ write (2, "result wrong\n", 13);
+ _exit (1);
+ }
+ else
+ printf ("joined thread %d\n", i);
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-basic2.c b/libc/nptl/tst-basic2.c
new file mode 100644
index 000000000..1c4632ceb
--- /dev/null
+++ b/libc/nptl/tst-basic2.c
@@ -0,0 +1,121 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+#define N 20
+
+static pthread_t th[N];
+static pthread_mutex_t lock[N];
+
+
+static void *tf (void *a)
+{
+ uintptr_t idx = (uintptr_t) a;
+
+ pthread_mutex_lock (&lock[idx]);
+
+ return pthread_equal (pthread_self (), th[idx]) ? NULL : (void *) 1l;
+}
+
+
+int
+do_test (void)
+{
+ if (pthread_equal (pthread_self (), pthread_self ()) == 0)
+ {
+ puts ("pthread_equal (pthread_self (), pthread_self ()) failed");
+ exit (1);
+ }
+
+ pthread_attr_t at;
+
+ if (pthread_attr_init (&at) != 0)
+ {
+ puts ("attr_init failed");
+ return 1;
+ }
+
+ if (pthread_attr_setstacksize (&at, 1 * 1024 * 1024) != 0)
+ {
+ puts ("attr_setstacksize failed");
+ return 1;
+ }
+
+ int i;
+ for (i = 0; i < N; ++i)
+ {
+ if (pthread_mutex_init (&lock[i], NULL) != 0)
+ {
+ puts ("mutex_init failed");
+ exit (1);
+ }
+
+ if (pthread_mutex_lock (&lock[i]) != 0)
+ {
+ puts ("mutex_lock failed");
+ exit (1);
+ }
+
+ if (pthread_create (&th[i], &at, tf, (void *) (long int) i) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ if (pthread_mutex_unlock (&lock[i]) != 0)
+ {
+ puts ("mutex_unlock failed");
+ exit (1);
+ }
+
+ printf ("created thread %d\n", i);
+ }
+
+ if (pthread_attr_destroy (&at) != 0)
+ {
+ puts ("attr_destroy failed");
+ return 1;
+ }
+
+ int result = 0;
+ for (i = 0; i < N; ++i)
+ {
+ void *r;
+ int e;
+ if ((e = pthread_join (th[i], &r)) != 0)
+ {
+ printf ("join failed: %d\n", e);
+ _exit (1);
+ }
+ else if (r != NULL)
+ result = 1;
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-basic3.c b/libc/nptl/tst-basic3.c
new file mode 100644
index 000000000..cb4816d2a
--- /dev/null
+++ b/libc/nptl/tst-basic3.c
@@ -0,0 +1,87 @@
+/* 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>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static int nrunning = 1;
+
+
+static void
+final_test (void)
+{
+ puts ("final_test has been called");
+
+#define THE_SIGNAL SIGUSR1
+ kill (getpid (), SIGUSR1);
+}
+
+
+static void *
+tf (void *a)
+{
+ if (pthread_join ((pthread_t) a, NULL) != 0)
+ {
+ printf ("join failed while %d are running\n", nrunning);
+ _exit (1);
+ }
+
+ printf ("%2d left\n", --nrunning);
+
+ return NULL;
+}
+
+
+int
+do_test (void)
+{
+#define N 20
+ pthread_t t[N];
+ pthread_t last = pthread_self ();
+ int i;
+
+ atexit (final_test);
+
+ printf ("starting %d + 1 threads\n", N);
+ for (i = 0; i < N; ++i)
+ {
+ if (pthread_create (&t[i], NULL, tf, (void *) last) != 0)
+ {
+ puts ("create failed");
+ _exit (1);
+ }
+
+ ++nrunning;
+
+ last = t[i];
+ }
+
+ printf ("%2d left\n", --nrunning);
+
+ pthread_exit (NULL);
+}
+
+
+#define EXPECTED_SIGNAL THE_SIGNAL
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-basic4.c b/libc/nptl/tst-basic4.c
new file mode 100644
index 000000000..6eb6ea9f1
--- /dev/null
+++ b/libc/nptl/tst-basic4.c
@@ -0,0 +1,101 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+
+static void
+final_test (void)
+{
+ puts ("final_test has been called");
+
+#define THE_SIGNAL SIGUSR1
+ kill (getpid (), SIGUSR1);
+}
+
+
+static void *
+tf (void *a)
+{
+ pid_t pid = fork ();
+ if (pid == -1)
+ {
+ puts ("fork failed");
+ exit (1);
+ }
+
+ if (pid == 0)
+ {
+ atexit (final_test);
+
+ pthread_exit (NULL);
+ }
+
+ int r;
+ int e = TEMP_FAILURE_RETRY (waitpid (pid, &r, 0));
+ if (e != pid)
+ {
+ puts ("waitpid failed");
+ exit (1);
+ }
+
+ if (! WIFSIGNALED (r))
+ {
+ puts ("child not signled");
+ exit (1);
+ }
+
+ if (WTERMSIG (r) != THE_SIGNAL)
+ {
+ puts ("child's termination signal wrong");
+ exit (1);
+ }
+
+ return NULL;
+}
+
+
+int
+do_test (void)
+{
+ pthread_t th;
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ _exit (1);
+ }
+
+ if (pthread_join (th, NULL) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-basic5.c b/libc/nptl/tst-basic5.c
new file mode 100644
index 000000000..83a8810f1
--- /dev/null
+++ b/libc/nptl/tst-basic5.c
@@ -0,0 +1,74 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+
+int
+do_test (void)
+{
+ int c = pthread_getconcurrency ();
+ if (c != 0)
+ {
+ puts ("initial concurrencylevel wrong");
+ exit (1);
+ }
+
+ if (pthread_setconcurrency (1) != 0)
+ {
+ puts ("setconcurrency failed");
+ exit (1);
+ }
+
+ c = pthread_getconcurrency ();
+ if (c != 1)
+ {
+ puts ("getconcurrency didn't return the value previous set");
+ exit (1);
+ }
+
+ int e = pthread_setconcurrency (-1);
+ if (e == 0)
+ {
+ puts ("setconcurrency of negative value didn't failed");
+ exit (1);
+ }
+ if (e != EINVAL)
+ {
+ puts ("setconcurrency didn't return EINVAL for negative value");
+ exit (1);
+ }
+
+ c = pthread_getconcurrency ();
+ if (c != 1)
+ {
+ puts ("invalid getconcurrency changed level");
+ exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-basic6.c b/libc/nptl/tst-basic6.c
new file mode 100644
index 000000000..413ae034b
--- /dev/null
+++ b/libc/nptl/tst-basic6.c
@@ -0,0 +1,132 @@
+/* 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>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+
+static char *p;
+
+static pthread_barrier_t b;
+#define BT \
+ e = pthread_barrier_wait (&b); \
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD) \
+ { \
+ puts ("barrier_wait failed"); \
+ exit (1); \
+ }
+
+
+static void *
+tf (void *a)
+{
+ int e;
+
+ BT;
+
+ char *p2 = getcwd (NULL, 0);
+ if (p2 == NULL)
+ {
+ puts ("2nd getcwd failed");
+ exit (1);
+ }
+
+ if (strcmp (p, p2) != 0)
+ {
+ printf ("initial cwd mismatch: \"%s\" vs \"%s\"\n", p, p2);
+ exit (1);
+ }
+
+ free (p);
+ free (p2);
+
+ if (chdir ("..") != 0)
+ {
+ puts ("chdir failed");
+ exit (1);
+ }
+
+ p = getcwd (NULL, 0);
+ if (p == NULL)
+ {
+ puts ("getcwd failed");
+ exit (1);
+ }
+
+ return a;
+}
+
+
+int
+do_test (void)
+{
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ p = getcwd (NULL, 0);
+ if (p == NULL)
+ {
+ puts ("getcwd failed");
+ exit (1);
+ }
+
+ int e;
+ BT;
+
+ if (pthread_join (th, NULL) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ char *p2 = getcwd (NULL, 0);
+ if (p2 == NULL)
+ {
+ puts ("2nd getcwd failed");
+ exit (1);
+ }
+
+ if (strcmp (p, p2) != 0)
+ {
+ printf ("cwd after chdir mismatch: \"%s\" vs \"%s\"\n", p, p2);
+ exit (1);
+ }
+
+ free (p);
+ free (p2);
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel-wrappers.sh b/libc/nptl/tst-cancel-wrappers.sh
new file mode 100644
index 000000000..d6f16d1ed
--- /dev/null
+++ b/libc/nptl/tst-cancel-wrappers.sh
@@ -0,0 +1,92 @@
+#! /bin/sh
+# Test whether all cancelable functions are cancelable.
+# Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+# Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
+
+# 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.
+
+while [ $# -gt 0 ]; do
+ ( nm -P $1; echo 'end[end]:' ) | gawk ' BEGIN {
+C["accept"]=1
+C["close"]=1
+C["connect"]=1
+C["creat"]=1
+C["fcntl"]=1
+C["fsync"]=1
+C["msgrcv"]=1
+C["msgsnd"]=1
+C["msync"]=1
+C["nanosleep"]=1
+C["open"]=1
+C["open64"]=1
+C["pause"]=1
+C["poll"]=1
+C["pread"]=1
+C["pread64"]=1
+C["pselect"]=1
+C["pwrite"]=1
+C["pwrite64"]=1
+C["read"]=1
+C["readv"]=1
+C["recv"]=1
+C["recvfrom"]=1
+C["recvmsg"]=1
+C["select"]=1
+C["send"]=1
+C["sendmsg"]=1
+C["sendto"]=1
+C["sigpause"]=1
+C["sigsuspend"]=1
+C["sigwait"]=1
+C["sigwaitinfo"]=1
+C["system"]=1
+C["tcdrain"]=1
+C["wait"]=1
+C["waitid"]=1
+C["waitpid"]=1
+C["write"]=1
+C["writev"]=1
+C["__xpg_sigpause"]=1
+}
+/:$/ {
+ if (seen)
+ {
+ if (!seen_enable || !seen_disable)
+ {
+ printf "in '$1'(%s) %s'\''s cancellation missing\n", object, seen
+ ret = 1
+ }
+ }
+ seen=""
+ seen_enable=""
+ seen_disable=""
+ object=gensub(/^.*\[(.*)\]:$/,"\\1","",$0)
+ next
+}
+{
+ if (C[$1] && $2 ~ /^[TW]$/)
+ seen=$1
+ else if ($1 ~ /^([.]|)__(libc|pthread)_enable_asynccancel$/ && $2 == "U")
+ seen_enable=1
+ else if ($1 ~ /^([.]|)__(libc|pthread)_disable_asynccancel$/ && $2 == "U")
+ seen_disable=1
+}
+END {
+ exit ret
+}' || exit
+ shift
+done
diff --git a/libc/nptl/tst-cancel1.c b/libc/nptl/tst-cancel1.c
new file mode 100644
index 000000000..690319d8c
--- /dev/null
+++ b/libc/nptl/tst-cancel1.c
@@ -0,0 +1,163 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+static pthread_mutex_t m1 = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t m2 = PTHREAD_MUTEX_INITIALIZER;
+
+static int cntr;
+
+
+static void
+cleanup (void *arg)
+{
+ if (arg != (void *) 42l)
+ cntr = 42;
+ else
+ cntr = 1;
+}
+
+
+static void *
+tf (void *arg)
+{
+ /* Ignore all signals. This must not have any effect on delivering
+ the cancellation signal. */
+ sigset_t ss;
+
+ sigfillset (&ss);
+
+ if (pthread_sigmask (SIG_BLOCK, &ss, NULL) != 0)
+ {
+ puts ("pthread_sigmask failed");
+ exit (1);
+ }
+
+ pthread_cleanup_push (cleanup, (void *) 42l);
+
+ int err = pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+ if (err != 0)
+ {
+ printf ("setcanceltype failed: %s\n", strerror (err));
+ exit (1);
+ }
+ /* The following code is not standard compliant: the mutex functions
+ must not be called with asynchronous cancellation enabled. */
+
+ err = pthread_mutex_unlock (&m2);
+ if (err != 0)
+ {
+ printf ("child: mutex_unlock failed: %s\n", strerror (err));
+ exit (1);
+ }
+
+ err = pthread_mutex_lock (&m1);
+ if (err != 0)
+ {
+ printf ("child: 1st mutex_lock failed: %s\n", strerror (err));
+ exit (1);
+ }
+
+ /* We should never come here. */
+
+ pthread_cleanup_pop (0);
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ int err;
+ pthread_t th;
+ int result = 0;
+ void *retval;
+
+ /* Get the mutexes. */
+ err = pthread_mutex_lock (&m1);
+ if (err != 0)
+ {
+ printf ("parent: 1st mutex_lock failed: %s\n", strerror (err));
+ return 1;
+ }
+ err = pthread_mutex_lock (&m2);
+ if (err != 0)
+ {
+ printf ("parent: 2nd mutex_lock failed: %s\n", strerror (err));
+ return 1;
+ }
+
+ err = pthread_create (&th, NULL, tf, NULL);
+ if (err != 0)
+ {
+ printf ("create failed: %s\n", strerror (err));
+ return 1;
+ }
+
+ err = pthread_mutex_lock (&m2);
+ if (err != 0)
+ {
+ printf ("parent: 3rd mutex_lock failed: %s\n", strerror (err));
+ return 1;
+ }
+
+ err = pthread_cancel (th);
+ if (err != 0)
+ {
+ printf ("cancel failed: %s\n", strerror (err));
+ return 1;
+ }
+
+ err = pthread_join (th, &retval);
+ if (err != 0)
+ {
+ printf ("join failed: %s\n", strerror (err));
+ return 1;
+ }
+
+ if (retval != PTHREAD_CANCELED)
+ {
+ printf ("wrong return value: %p\n", retval);
+ result = 1;
+ }
+
+ if (cntr == 42)
+ {
+ puts ("cleanup handler called with wrong argument");
+ result = 1;
+ }
+ else if (cntr != 1)
+ {
+ puts ("cleanup handling not called");
+ result = 1;
+ }
+
+ return result;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel10.c b/libc/nptl/tst-cancel10.c
new file mode 100644
index 000000000..7af0f2f84
--- /dev/null
+++ b/libc/nptl/tst-cancel10.c
@@ -0,0 +1,126 @@
+/* Copyright (C) 2003, 2004 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>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+static void
+cleanup (void *arg)
+{
+ /* Just for fun. */
+ if (pthread_cancel (pthread_self ()) != 0)
+ {
+ puts ("cleanup: cancel failed");
+ exit (1);
+ }
+
+ printf ("cleanup for %ld\n", (long int) arg);
+}
+
+
+static void *
+tf (void *arg)
+{
+ long int n = (long int) arg;
+
+ pthread_cleanup_push (cleanup, arg);
+
+ if (pthread_setcanceltype ((n & 1) == 0
+ ? PTHREAD_CANCEL_DEFERRED
+ : PTHREAD_CANCEL_ASYNCHRONOUS, NULL) != 0)
+ {
+ puts ("setcanceltype failed");
+ exit (1);
+ }
+
+ if (pthread_cancel (pthread_self ()) != 0)
+ {
+ puts ("cancel failed");
+ exit (1);
+ }
+
+ pthread_testcancel ();
+
+ /* We should never come here. */
+
+ pthread_cleanup_pop (0);
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_attr_t at;
+
+ if (pthread_attr_init (&at) != 0)
+ {
+ puts ("attr_init failed");
+ return 1;
+ }
+
+ if (pthread_attr_setstacksize (&at, 1 * 1024 * 1024) != 0)
+ {
+ puts ("attr_setstacksize failed");
+ return 1;
+ }
+
+#define N 20
+ int i;
+ pthread_t th[N];
+
+ for (i = 0; i < N; ++i)
+ if (pthread_create (&th[i], &at, tf, (void *) (long int) i) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ if (pthread_attr_destroy (&at) != 0)
+ {
+ puts ("attr_destroy failed");
+ return 1;
+ }
+
+ for (i = 0; i < N; ++i)
+ {
+ void *r;
+ if (pthread_join (th[i], &r) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ if (r != PTHREAD_CANCELED)
+ {
+ puts ("thread not canceled");
+ exit (1);
+ }
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel11.c b/libc/nptl/tst-cancel11.c
new file mode 100644
index 000000000..235aef5c4
--- /dev/null
+++ b/libc/nptl/tst-cancel11.c
@@ -0,0 +1,123 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+
+static pthread_barrier_t bar;
+static int fd[2];
+
+
+static void
+cleanup (void *arg)
+{
+ static int ncall;
+
+ if (++ncall != 1)
+ {
+ puts ("second call to cleanup");
+ exit (1);
+ }
+
+ printf ("cleanup call #%d\n", ncall);
+}
+
+
+static void *
+tf (void *arg)
+{
+ pthread_cleanup_push (cleanup, NULL);
+
+ int e = pthread_barrier_wait (&bar);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("tf: 1st barrier_wait failed");
+ exit (1);
+ }
+
+ /* This call should block and be cancelable. */
+ char buf[20];
+ read (fd[0], buf, sizeof (buf));
+
+ pthread_cleanup_pop (0);
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t th;
+
+ if (pthread_barrier_init (&bar, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ if (pipe (fd) != 0)
+ {
+ puts ("pipe failed");
+ exit (1);
+ }
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ int e = pthread_barrier_wait (&bar);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("1st barrier_wait failed");
+ exit (1);
+ }
+
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("1st cancel failed");
+ exit (1);
+ }
+
+ void *r;
+ if (pthread_join (th, &r) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ if (r != PTHREAD_CANCELED)
+ {
+ puts ("thread not canceled");
+ exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel12.c b/libc/nptl/tst-cancel12.c
new file mode 100644
index 000000000..6fdf5cf5f
--- /dev/null
+++ b/libc/nptl/tst-cancel12.c
@@ -0,0 +1,127 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+
+static pthread_barrier_t bar;
+static sem_t sem;
+
+
+static void
+cleanup (void *arg)
+{
+ static int ncall;
+
+ if (++ncall != 1)
+ {
+ puts ("second call to cleanup");
+ exit (1);
+ }
+
+ printf ("cleanup call #%d\n", ncall);
+}
+
+
+static void *
+tf (void *arg)
+{
+ pthread_cleanup_push (cleanup, NULL);
+
+ int e = pthread_barrier_wait (&bar);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("tf: 1st barrier_wait failed");
+ exit (1);
+ }
+
+ /* This call should block and be cancelable. */
+ sem_wait (&sem);
+
+ pthread_cleanup_pop (0);
+
+ puts ("sem_wait returned");
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t th;
+
+ if (pthread_barrier_init (&bar, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ if (sem_init (&sem, 0, 1) != 0)
+ {
+ puts ("sem_init failed");
+ exit (1);
+ }
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ /* Check whether cancellation is honored even before sem_wait does
+ anything. */
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("1st cancel failed");
+ exit (1);
+ }
+
+ int e = pthread_barrier_wait (&bar);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("1st barrier_wait failed");
+ exit (1);
+ }
+
+ void *r;
+ if (pthread_join (th, &r) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ if (r != PTHREAD_CANCELED)
+ {
+ puts ("thread not canceled");
+ exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel13.c b/libc/nptl/tst-cancel13.c
new file mode 100644
index 000000000..66ab45509
--- /dev/null
+++ b/libc/nptl/tst-cancel13.c
@@ -0,0 +1,129 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+
+static pthread_barrier_t bar;
+static sem_t sem;
+
+
+static void
+cleanup (void *arg)
+{
+ static int ncall;
+
+ if (++ncall != 1)
+ {
+ puts ("second call to cleanup");
+ exit (1);
+ }
+
+ printf ("cleanup call #%d\n", ncall);
+}
+
+
+static void *
+tf (void *arg)
+{
+ pthread_cleanup_push (cleanup, NULL);
+
+ int e = pthread_barrier_wait (&bar);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("tf: 1st barrier_wait failed");
+ exit (1);
+ }
+
+ /* This call should block and be cancelable. */
+ sem_wait (&sem);
+
+ pthread_cleanup_pop (0);
+
+ puts ("sem_wait returned");
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t th;
+
+ if (pthread_barrier_init (&bar, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ if (sem_init (&sem, 0, 0) != 0)
+ {
+ puts ("sem_init failed");
+ exit (1);
+ }
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ int e = pthread_barrier_wait (&bar);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("1st barrier_wait failed");
+ exit (1);
+ }
+
+ /* Give the child a chance to go to sleep in sem_wait. */
+ sleep (1);
+
+ /* Check whether cancellation is honored when waiting in sem_wait. */
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("1st cancel failed");
+ exit (1);
+ }
+
+ void *r;
+ if (pthread_join (th, &r) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ if (r != PTHREAD_CANCELED)
+ {
+ puts ("thread not canceled");
+ exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel14.c b/libc/nptl/tst-cancel14.c
new file mode 100644
index 000000000..bc830ddff
--- /dev/null
+++ b/libc/nptl/tst-cancel14.c
@@ -0,0 +1,136 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+
+static pthread_barrier_t bar;
+static sem_t sem;
+
+
+static void
+cleanup (void *arg)
+{
+ static int ncall;
+
+ if (++ncall != 1)
+ {
+ puts ("second call to cleanup");
+ exit (1);
+ }
+
+ printf ("cleanup call #%d\n", ncall);
+}
+
+
+static void *
+tf (void *arg)
+{
+ pthread_cleanup_push (cleanup, NULL);
+
+ int e = pthread_barrier_wait (&bar);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("tf: 1st barrier_wait failed");
+ exit (1);
+ }
+
+ struct timeval tv;
+ (void) gettimeofday (&tv, NULL);
+
+ struct timespec ts;
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+
+ /* Timeout in 5 seconds. */
+ ts.tv_sec += 5;
+
+ /* This call should block and be cancelable. */
+ sem_timedwait (&sem, &ts);
+
+ pthread_cleanup_pop (0);
+
+ puts ("sem_timedwait returned");
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t th;
+
+ if (pthread_barrier_init (&bar, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ if (sem_init (&sem, 0, 1) != 0)
+ {
+ puts ("sem_init failed");
+ exit (1);
+ }
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ /* Check whether cancellation is honored even before sem_timedwait does
+ anything. */
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("1st cancel failed");
+ exit (1);
+ }
+
+ int e = pthread_barrier_wait (&bar);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("1st barrier_wait failed");
+ exit (1);
+ }
+
+ void *r;
+ if (pthread_join (th, &r) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ if (r != PTHREAD_CANCELED)
+ {
+ puts ("thread not canceled");
+ exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel15.c b/libc/nptl/tst-cancel15.c
new file mode 100644
index 000000000..88bacafef
--- /dev/null
+++ b/libc/nptl/tst-cancel15.c
@@ -0,0 +1,141 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+
+static pthread_barrier_t bar;
+static sem_t sem;
+
+
+static void
+cleanup (void *arg)
+{
+ static int ncall;
+
+ if (++ncall != 1)
+ {
+ puts ("second call to cleanup");
+ exit (1);
+ }
+
+ printf ("cleanup call #%d\n", ncall);
+}
+
+
+static void *
+tf (void *arg)
+{
+ int e;
+
+ pthread_cleanup_push (cleanup, NULL);
+
+ e = pthread_barrier_wait (&bar);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("tf: 1st barrier_wait failed");
+ exit (1);
+ }
+
+ struct timeval tv;
+ (void) gettimeofday (&tv, NULL);
+
+ struct timespec ts;
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+
+ /* Timeout in 5 seconds. */
+ ts.tv_sec += 5;
+
+ /* This call should block and be cancelable. */
+ errno = 0;
+ e = sem_timedwait (&sem, &ts);
+
+ pthread_cleanup_pop (0);
+
+ printf ("sem_timedwait returned, e = %d, errno = %d\n", e, errno);
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t th;
+
+ if (pthread_barrier_init (&bar, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ if (sem_init (&sem, 0, 0) != 0)
+ {
+ puts ("sem_init failed");
+ exit (1);
+ }
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ int e = pthread_barrier_wait (&bar);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("1st barrier_wait failed");
+ exit (1);
+ }
+
+ /* Give the child a chance to go to sleep in sem_wait. */
+ sleep (1);
+
+ /* Check whether cancellation is honored when waiting in sem_timedwait. */
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("1st cancel failed");
+ exit (1);
+ }
+
+ void *r;
+ if (pthread_join (th, &r) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ if (r != PTHREAD_CANCELED)
+ {
+ puts ("thread not canceled");
+ exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel16.c b/libc/nptl/tst-cancel16.c
new file mode 100644
index 000000000..709902e97
--- /dev/null
+++ b/libc/nptl/tst-cancel16.c
@@ -0,0 +1,231 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+
+
+static pthread_barrier_t b2;
+static int fd;
+static int called;
+
+
+static void
+cl (void *arg)
+{
+ called = 1;
+}
+
+
+static void *
+tf (void *arg)
+{
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("child thread: barrier_wait failed");
+ exit (1);
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ /* This call should never return. */
+ (void) lockf (fd, F_LOCK, 0);
+
+ pthread_cleanup_pop (0);
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ char fname[] = "/tmp/cancel16XXXXXX";
+ fd = mkstemp (fname);
+ if (fd == -1)
+ {
+ puts ("mkstemp failed");
+ return 1;
+ }
+ unlink (fname);
+
+ char mem[sizeof (pthread_barrier_t)];
+ memset (mem, '\0', sizeof (mem));
+ if (TEMP_FAILURE_RETRY (pwrite (fd, mem, sizeof (mem), 0)) != sizeof (mem))
+ {
+ puts ("pwrite failed");
+ return 1;
+ }
+
+ void *p = mmap (NULL, sizeof (mem), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+ if (p == MAP_FAILED)
+ {
+ puts ("mmap failed");
+ return 1;
+ }
+ pthread_barrier_t *b = (pthread_barrier_t *) p;
+
+ pthread_barrierattr_t ba;
+ if (pthread_barrierattr_init (&ba) != 0)
+ {
+ puts ("barrierattr_init failed");
+ return 1;
+ }
+ if (pthread_barrierattr_setpshared (&ba, 1) != 0)
+ {
+ puts ("barrierattr_setshared failed");
+ return 1;
+ }
+
+ if (pthread_barrier_init (b, &ba, 2) != 0)
+ {
+ puts ("1st barrier_init failed");
+ return 1;
+ }
+ if (pthread_barrierattr_destroy (&ba) != 0)
+ {
+ puts ("barrier_destroy failed");
+ return 1;
+ }
+
+ pid_t pid = fork ();
+ if (pid == 0)
+ {
+ /* Child. Lock the file and wait. */
+ if (lockf (fd, F_LOCK, 0) != 0)
+ {
+ puts ("child process: lockf failed");
+ _exit (1);
+ }
+
+ int r = pthread_barrier_wait (b);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("child process: 1st barrier_wait failed");
+ _exit (1);
+ }
+
+ /* Make sure the process dies. */
+ alarm (5);
+
+ r = pthread_barrier_wait (b);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("child process: 2nd barrier_wait failed");
+ _exit (1);
+ }
+
+ _exit (0);
+ }
+ if (pid == -1)
+ {
+ puts ("fork failed");
+ return 1;
+ }
+
+ int r = pthread_barrier_wait (b);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("main: 1st barrier_wait failed");
+ _exit (1);
+ }
+
+ if (pthread_barrier_init (&b2, NULL, 2) != 0)
+ {
+ puts ("2nd barrier_init failed");
+ return 1;
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ return 1;
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("main: 2nd barrier_wait failed");
+ return 1;
+ }
+
+ /* Delay. */
+ sleep (1);
+
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("cancel failed");
+ return 1;
+ }
+
+ void *result;
+ if (pthread_join (th, &result) != 0)
+ {
+ puts ("join failed");
+ return 1;
+ }
+ if (result != PTHREAD_CANCELED)
+ {
+ puts ("thread not canceled");
+ return 1;
+ }
+ if (called == 0)
+ {
+ puts ("cleanup handler not called");
+ return 1;
+ }
+
+ r = pthread_barrier_wait (b);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("main: 3rd barrier_wait failed");
+ return 1;
+ }
+
+ int status;
+ if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid)
+ {
+ puts ("waitpid failed");
+ return 1;
+ }
+ if (WEXITSTATUS (status) != 0)
+ {
+ printf ("child process exits with %d\n", WEXITSTATUS (status));
+ return 1;
+ }
+
+ if (lockf (fd, F_LOCK, 0) != 0)
+ {
+ puts ("main: lockf failed");
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel17.c b/libc/nptl/tst-cancel17.c
new file mode 100644
index 000000000..2a8c951af
--- /dev/null
+++ b/libc/nptl/tst-cancel17.c
@@ -0,0 +1,341 @@
+/* Copyright (C) 2003, 2005 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 <aio.h>
+#include <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+
+static pthread_barrier_t b;
+
+
+/* Cleanup handling test. */
+static int cl_called;
+
+static void
+cl (void *arg)
+{
+ ++cl_called;
+}
+
+
+static void *
+tf (void *arg)
+{
+ int r = pthread_barrier_wait (&b);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("tf: barrier_wait failed");
+ exit (1);
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ const struct aiocb *l[1] = { arg };
+
+ TEMP_FAILURE_RETRY (aio_suspend (l, 1, NULL));
+
+ pthread_cleanup_pop (0);
+
+ puts ("tf: aio_suspend returned");
+
+ exit (1);
+}
+
+
+static void *
+tf2 (void *arg)
+{
+ int r = pthread_barrier_wait (&b);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("tf2: barrier_wait failed");
+ exit (1);
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ const struct aiocb *l[1] = { arg };
+ struct timespec ts = { .tv_sec = 1000, .tv_nsec = 0 };
+
+ TEMP_FAILURE_RETRY (aio_suspend (l, 1, &ts));
+
+ pthread_cleanup_pop (0);
+
+ puts ("tf2: aio_suspend returned");
+
+ exit (1);
+}
+
+
+static int
+do_test (void)
+{
+ int fds[2];
+ if (pipe (fds) != 0)
+ {
+ puts ("pipe failed");
+ return 1;
+ }
+
+ struct aiocb a, a2, *ap;
+ char mem[1];
+ memset (&a, '\0', sizeof (a));
+ a.aio_fildes = fds[0];
+ a.aio_buf = mem;
+ a.aio_nbytes = sizeof (mem);
+ if (aio_read (&a) != 0)
+ {
+ puts ("aio_read failed");
+ return 1;
+ }
+
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ return 1;
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, &a) != 0)
+ {
+ puts ("1st create failed");
+ return 1;
+ }
+
+ int r = pthread_barrier_wait (&b);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
+ while (nanosleep (&ts, &ts) != 0)
+ continue;
+
+ puts ("going to cancel tf in-time");
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("1st cancel failed");
+ return 1;
+ }
+
+ void *status;
+ if (pthread_join (th, &status) != 0)
+ {
+ puts ("1st join failed");
+ return 1;
+ }
+ if (status != PTHREAD_CANCELED)
+ {
+ puts ("1st thread not canceled");
+ return 1;
+ }
+
+ if (cl_called == 0)
+ {
+ puts ("tf cleanup handler not called");
+ return 1;
+ }
+ if (cl_called > 1)
+ {
+ puts ("tf cleanup handler called more than once");
+ return 1;
+ }
+
+ cl_called = 0;
+
+ if (pthread_create (&th, NULL, tf2, &a) != 0)
+ {
+ puts ("2nd create failed");
+ return 1;
+ }
+
+ r = pthread_barrier_wait (&b);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("2nd barrier_wait failed");
+ exit (1);
+ }
+
+ ts.tv_sec = 0;
+ ts.tv_nsec = 100000000;
+ while (nanosleep (&ts, &ts) != 0)
+ continue;
+
+ puts ("going to cancel tf2 in-time");
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("2nd cancel failed");
+ return 1;
+ }
+
+ if (pthread_join (th, &status) != 0)
+ {
+ puts ("2nd join failed");
+ return 1;
+ }
+ if (status != PTHREAD_CANCELED)
+ {
+ puts ("2nd thread not canceled");
+ return 1;
+ }
+
+ if (cl_called == 0)
+ {
+ puts ("tf2 cleanup handler not called");
+ return 1;
+ }
+ if (cl_called > 1)
+ {
+ puts ("tf2 cleanup handler called more than once");
+ return 1;
+ }
+
+ puts ("in-time cancellation succeeded");
+
+ ap = &a;
+ if (aio_cancel (fds[0], &a) != AIO_CANCELED)
+ {
+ puts ("aio_cancel failed");
+ /* If aio_cancel failed, we cannot reuse aiocb a. */
+ ap = &a2;
+ }
+
+
+ cl_called = 0;
+
+ size_t len2 = fpathconf (fds[1], _PC_PIPE_BUF);
+ size_t page_size = sysconf (_SC_PAGESIZE);
+ len2 = 20 * (len2 < page_size ? page_size : len2) + sizeof (mem) + 1;
+ char *mem2 = malloc (len2);
+ if (mem2 == NULL)
+ {
+ puts ("could not allocate memory for pipe write");
+ return 1;
+ }
+
+ memset (ap, '\0', sizeof (*ap));
+ ap->aio_fildes = fds[1];
+ ap->aio_buf = mem2;
+ ap->aio_nbytes = len2;
+ if (aio_write (ap) != 0)
+ {
+ puts ("aio_write failed");
+ return 1;
+ }
+
+ if (pthread_create (&th, NULL, tf, ap) != 0)
+ {
+ puts ("3rd create failed");
+ return 1;
+ }
+
+ puts ("going to cancel tf early");
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("3rd cancel failed");
+ return 1;
+ }
+
+ r = pthread_barrier_wait (&b);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("3rd barrier_wait failed");
+ exit (1);
+ }
+
+ if (pthread_join (th, &status) != 0)
+ {
+ puts ("3rd join failed");
+ return 1;
+ }
+ if (status != PTHREAD_CANCELED)
+ {
+ puts ("3rd thread not canceled");
+ return 1;
+ }
+
+ if (cl_called == 0)
+ {
+ puts ("tf cleanup handler not called");
+ return 1;
+ }
+ if (cl_called > 1)
+ {
+ puts ("tf cleanup handler called more than once");
+ return 1;
+ }
+
+ cl_called = 0;
+
+ if (pthread_create (&th, NULL, tf2, ap) != 0)
+ {
+ puts ("4th create failed");
+ return 1;
+ }
+
+ puts ("going to cancel tf2 early");
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("4th cancel failed");
+ return 1;
+ }
+
+ r = pthread_barrier_wait (&b);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("4th barrier_wait failed");
+ exit (1);
+ }
+
+ if (pthread_join (th, &status) != 0)
+ {
+ puts ("4th join failed");
+ return 1;
+ }
+ if (status != PTHREAD_CANCELED)
+ {
+ puts ("4th thread not canceled");
+ return 1;
+ }
+
+ if (cl_called == 0)
+ {
+ puts ("tf2 cleanup handler not called");
+ return 1;
+ }
+ if (cl_called > 1)
+ {
+ puts ("tf2 cleanup handler called more than once");
+ return 1;
+ }
+
+ puts ("early cancellation succeeded");
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel18.c b/libc/nptl/tst-cancel18.c
new file mode 100644
index 000000000..15e9ddfbb
--- /dev/null
+++ b/libc/nptl/tst-cancel18.c
@@ -0,0 +1,174 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+
+
+static pthread_barrier_t b;
+
+
+/* Cleanup handling test. */
+static int cl_called;
+
+static void
+cl (void *arg)
+{
+ ++cl_called;
+}
+
+
+static void *
+tf (void *arg)
+{
+ int r = pthread_barrier_wait (&b);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ struct timespec ts = { .tv_sec = arg == NULL ? 10000000 : 0, .tv_nsec = 0 };
+ TEMP_FAILURE_RETRY (clock_nanosleep (CLOCK_REALTIME, 0, &ts, &ts));
+
+ pthread_cleanup_pop (0);
+
+ puts ("clock_nanosleep returned");
+
+ exit (1);
+}
+
+
+static int
+do_test (void)
+{
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ return 1;
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("1st create failed");
+ return 1;
+ }
+
+ int r = pthread_barrier_wait (&b);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
+ while (nanosleep (&ts, &ts) != 0)
+ continue;
+
+ puts ("going to cancel in-time");
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("1st cancel failed");
+ return 1;
+ }
+
+ void *status;
+ if (pthread_join (th, &status) != 0)
+ {
+ puts ("1st join failed");
+ return 1;
+ }
+ if (status != PTHREAD_CANCELED)
+ {
+ puts ("1st thread not canceled");
+ return 1;
+ }
+
+ if (cl_called == 0)
+ {
+ puts ("cleanup handler not called");
+ return 1;
+ }
+ if (cl_called > 1)
+ {
+ puts ("cleanup handler called more than once");
+ return 1;
+ }
+
+ puts ("in-time cancellation succeeded");
+
+
+ cl_called = 0;
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("2nd create failed");
+ return 1;
+ }
+
+ puts ("going to cancel early");
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("2nd cancel failed");
+ return 1;
+ }
+
+ r = pthread_barrier_wait (&b);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ if (pthread_join (th, &status) != 0)
+ {
+ puts ("2nd join failed");
+ return 1;
+ }
+ if (status != PTHREAD_CANCELED)
+ {
+ puts ("2nd thread not canceled");
+ return 1;
+ }
+
+ if (cl_called == 0)
+ {
+ printf ("cleanup handler not called\n");
+ return 1;
+ }
+ if (cl_called > 1)
+ {
+ printf ("cleanup handler called more than once\n");
+ return 1;
+ }
+
+ puts ("early cancellation succeeded");
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel19.c b/libc/nptl/tst-cancel19.c
new file mode 100644
index 000000000..7c248ae0f
--- /dev/null
+++ b/libc/nptl/tst-cancel19.c
@@ -0,0 +1,287 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 <errno.h>
+#include <error.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/select.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+static void *
+tf (void *arg)
+{
+ return NULL;
+}
+
+static void
+handler (int sig)
+{
+}
+
+static void __attribute__ ((noinline))
+clobber_lots_of_regs (void)
+{
+#define X1(n) long r##n = 10##n; __asm __volatile ("" : "+r" (r##n));
+#define X2(n) X1(n##0) X1(n##1) X1(n##2) X1(n##3) X1(n##4)
+#define X3(n) X2(n##0) X2(n##1) X2(n##2) X2(n##3) X2(n##4)
+ X3(0) X3(1) X3(2) X3(3) X3(4)
+#undef X1
+#define X1(n) __asm __volatile ("" : : "r" (r##n));
+ X3(0) X3(1) X3(2) X3(3) X3(4)
+#undef X1
+#undef X2
+#undef X3
+}
+
+static int
+do_test (void)
+{
+ pthread_t th;
+ int old, rc;
+ int ret = 0;
+ int fd[2];
+
+ rc = pipe (fd);
+ if (rc < 0)
+ error (EXIT_FAILURE, errno, "couldn't create pipe");
+
+ rc = pthread_create (&th, NULL, tf, NULL);
+ if (rc)
+ error (EXIT_FAILURE, rc, "couldn't create thread");
+
+ rc = pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, &old);
+ if (rc)
+ {
+ error (0, rc, "1st pthread_setcanceltype failed");
+ ret = 1;
+ }
+ if (old != PTHREAD_CANCEL_DEFERRED && old != PTHREAD_CANCEL_ASYNCHRONOUS)
+ {
+ error (0, 0, "1st pthread_setcanceltype returned invalid value %d",
+ old);
+ ret = 1;
+ }
+
+ clobber_lots_of_regs ();
+ close (fd[0]);
+
+ rc = pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &old);
+ if (rc)
+ {
+ error (0, rc, "pthread_setcanceltype after close failed");
+ ret = 1;
+ }
+ if (old != PTHREAD_CANCEL_DEFERRED)
+ {
+ error (0, 0, "pthread_setcanceltype after close returned invalid value %d",
+ old);
+ ret = 1;
+ }
+
+ clobber_lots_of_regs ();
+ close (fd[1]);
+
+ rc = pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, &old);
+ if (rc)
+ {
+ error (0, rc, "pthread_setcanceltype after 2nd close failed");
+ ret = 1;
+ }
+ if (old != PTHREAD_CANCEL_ASYNCHRONOUS)
+ {
+ error (0, 0, "pthread_setcanceltype after 2nd close returned invalid value %d",
+ old);
+ ret = 1;
+ }
+
+ struct sigaction sa = { .sa_handler = handler, .sa_flags = 0 };
+ sigemptyset (&sa.sa_mask);
+ sigaction (SIGALRM, &sa, NULL);
+
+ struct itimerval it;
+ it.it_value.tv_sec = 1;
+ it.it_value.tv_usec = 0;
+ it.it_interval = it.it_value;
+ setitimer (ITIMER_REAL, &it, NULL);
+
+ clobber_lots_of_regs ();
+ pause ();
+
+ memset (&it, 0, sizeof (it));
+ setitimer (ITIMER_REAL, &it, NULL);
+
+ rc = pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &old);
+ if (rc)
+ {
+ error (0, rc, "pthread_setcanceltype after pause failed");
+ ret = 1;
+ }
+ if (old != PTHREAD_CANCEL_DEFERRED)
+ {
+ error (0, 0, "pthread_setcanceltype after pause returned invalid value %d",
+ old);
+ ret = 1;
+ }
+
+ it.it_value.tv_sec = 1;
+ it.it_value.tv_usec = 0;
+ it.it_interval = it.it_value;
+ setitimer (ITIMER_REAL, &it, NULL);
+
+ clobber_lots_of_regs ();
+ pause ();
+
+ memset (&it, 0, sizeof (it));
+ setitimer (ITIMER_REAL, &it, NULL);
+
+ rc = pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, &old);
+ if (rc)
+ {
+ error (0, rc, "pthread_setcanceltype after 2nd pause failed");
+ ret = 1;
+ }
+ if (old != PTHREAD_CANCEL_ASYNCHRONOUS)
+ {
+ error (0, 0, "pthread_setcanceltype after 2nd pause returned invalid value %d",
+ old);
+ ret = 1;
+ }
+
+ char fname[] = "/tmp/tst-cancel19-dir-XXXXXX\0foo/bar";
+ char *enddir = strchr (fname, '\0');
+ if (mkdtemp (fname) == NULL)
+ {
+ error (0, errno, "mkdtemp failed");
+ ret = 1;
+ }
+ *enddir = '/';
+
+ clobber_lots_of_regs ();
+ creat (fname, 0400);
+
+ rc = pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &old);
+ if (rc)
+ {
+ error (0, rc, "pthread_setcanceltype after creat failed");
+ ret = 1;
+ }
+ if (old != PTHREAD_CANCEL_DEFERRED)
+ {
+ error (0, 0, "pthread_setcanceltype after creat returned invalid value %d",
+ old);
+ ret = 1;
+ }
+
+ clobber_lots_of_regs ();
+ creat (fname, 0400);
+
+ rc = pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, &old);
+ if (rc)
+ {
+ error (0, rc, "pthread_setcanceltype after 2nd creat failed");
+ ret = 1;
+ }
+ if (old != PTHREAD_CANCEL_ASYNCHRONOUS)
+ {
+ error (0, 0, "pthread_setcanceltype after 2nd creat returned invalid value %d",
+ old);
+ ret = 1;
+ }
+
+ clobber_lots_of_regs ();
+ open (fname, O_CREAT, 0400);
+
+ rc = pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &old);
+ if (rc)
+ {
+ error (0, rc, "pthread_setcanceltype after open failed");
+ ret = 1;
+ }
+ if (old != PTHREAD_CANCEL_DEFERRED)
+ {
+ error (0, 0, "pthread_setcanceltype after open returned invalid value %d",
+ old);
+ ret = 1;
+ }
+
+ clobber_lots_of_regs ();
+ open (fname, O_CREAT, 0400);
+
+ rc = pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, &old);
+ if (rc)
+ {
+ error (0, rc, "pthread_setcanceltype after 2nd open failed");
+ ret = 1;
+ }
+ if (old != PTHREAD_CANCEL_ASYNCHRONOUS)
+ {
+ error (0, 0, "pthread_setcanceltype after 2nd open returned invalid value %d",
+ old);
+ ret = 1;
+ }
+
+ *enddir = '\0';
+ rmdir (fname);
+
+ clobber_lots_of_regs ();
+ select (-1, NULL, NULL, NULL, NULL);
+
+ rc = pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &old);
+ if (rc)
+ {
+ error (0, rc, "pthread_setcanceltype after select failed");
+ ret = 1;
+ }
+ if (old != PTHREAD_CANCEL_DEFERRED)
+ {
+ error (0, 0, "pthread_setcanceltype after select returned invalid value %d",
+ old);
+ ret = 1;
+ }
+
+ clobber_lots_of_regs ();
+ select (-1, NULL, NULL, NULL, NULL);
+
+ rc = pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, &old);
+ if (rc)
+ {
+ error (0, rc, "pthread_setcanceltype after 2nd select failed");
+ ret = 1;
+ }
+ if (old != PTHREAD_CANCEL_ASYNCHRONOUS)
+ {
+ error (0, 0, "pthread_setcanceltype after 2nd select returned invalid value %d",
+ old);
+ ret = 1;
+ }
+
+ pthread_join (th, NULL);
+
+ return ret;
+}
+
+#define TIMEOUT 20
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel2.c b/libc/nptl/tst-cancel2.c
new file mode 100644
index 000000000..6d80f8ae5
--- /dev/null
+++ b/libc/nptl/tst-cancel2.c
@@ -0,0 +1,100 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+
+
+static int fd[2];
+
+
+static void *
+tf (void *arg)
+{
+ /* The buffer size must be larger than the pipe size so that the
+ write blocks. */
+ char buf[100000];
+
+ if (write (fd[1], buf, sizeof (buf)) == sizeof (buf))
+ {
+ puts ("write succeeded");
+ return (void *) 1l;
+ }
+
+ return (void *) 42l;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t th;
+ void *r;
+ struct sigaction sa;
+
+ sa.sa_handler = SIG_IGN;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = 0;
+
+ if (sigaction (SIGPIPE, &sa, NULL) != 0)
+ {
+ puts ("sigaction failed");
+ return 1;
+ }
+
+ if (pipe (fd) != 0)
+ {
+ puts ("pipe failed");
+ return 1;
+ }
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ return 1;
+ }
+
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("cancel failed");
+ return 1;
+ }
+
+ /* This will cause the write in the child to return. */
+ close (fd[0]);
+
+ if (pthread_join (th, &r) != 0)
+ {
+ puts ("join failed");
+ return 1;
+ }
+
+ if (r != PTHREAD_CANCELED)
+ {
+ printf ("result is wrong: expected %p, got %p\n", PTHREAD_CANCELED, r);
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel20.c b/libc/nptl/tst-cancel20.c
new file mode 100644
index 000000000..d88cb9caf
--- /dev/null
+++ b/libc/nptl/tst-cancel20.c
@@ -0,0 +1,264 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static int fd[4];
+static pthread_barrier_t b;
+volatile int in_sh_body;
+unsigned long cleanups;
+
+static void
+cl (void *arg)
+{
+ cleanups = (cleanups << 4) | (long) arg;
+}
+
+
+static void __attribute__((noinline))
+sh_body (void)
+{
+ char c;
+
+ pthread_cleanup_push (cl, (void *) 1L);
+
+ in_sh_body = 1;
+ if (read (fd[2], &c, 1) == 1)
+ {
+ puts ("read succeeded");
+ exit (1);
+ }
+
+ pthread_cleanup_pop (0);
+}
+
+
+static void
+sh (int sig)
+{
+ pthread_cleanup_push (cl, (void *) 2L);
+ sh_body ();
+ in_sh_body = 0;
+
+ pthread_cleanup_pop (0);
+}
+
+
+static void __attribute__((noinline))
+tf_body (void)
+{
+ char c;
+
+ pthread_cleanup_push (cl, (void *) 3L);
+
+ int r = pthread_barrier_wait (&b);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("child thread: barrier_wait failed");
+ exit (1);
+ }
+
+ if (read (fd[0], &c, 1) == 1)
+ {
+ puts ("read succeeded");
+ exit (1);
+ }
+
+ read (fd[0], &c, 1);
+
+ pthread_cleanup_pop (0);
+}
+
+
+static void *
+tf (void *arg)
+{
+ pthread_cleanup_push (cl, (void *) 4L);
+ tf_body ();
+ pthread_cleanup_pop (0);
+ return NULL;
+}
+
+
+static int
+do_one_test (void)
+{
+ in_sh_body = 0;
+ cleanups = 0;
+ if (pipe (fd) != 0 || pipe (fd + 2) != 0)
+ {
+ puts ("pipe failed");
+ return 1;
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ return 1;
+ }
+
+ int r = pthread_barrier_wait (&b);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("parent thread: barrier_wait failed");
+ return 1;
+ }
+
+ sleep (1);
+
+ r = pthread_kill (th, SIGHUP);
+ if (r)
+ {
+ errno = r;
+ printf ("pthread_kill failed %m\n");
+ return 1;
+ }
+
+ while (in_sh_body == 0)
+ sleep (1);
+
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("cancel failed");
+ return 1;
+ }
+
+ /* This will cause the read in the child to return. */
+ close (fd[0]);
+ close (fd[1]);
+ close (fd[2]);
+ close (fd[3]);
+
+ void *ret;
+ if (pthread_join (th, &ret) != 0)
+ {
+ puts ("join failed");
+ return 1;
+ }
+
+ if (ret != PTHREAD_CANCELED)
+ {
+ puts ("result is wrong");
+ return 1;
+ }
+
+ if (cleanups != 0x1234L)
+ {
+ printf ("called cleanups %lx\n", cleanups);
+ return 1;
+ }
+
+ return 0;
+}
+
+
+static int
+do_test (void)
+{
+ stack_t ss;
+ ss.ss_sp = malloc (2 * SIGSTKSZ);
+ if (ss.ss_sp == NULL)
+ {
+ puts ("failed to allocate alternate stack");
+ return 1;
+ }
+ ss.ss_flags = 0;
+ ss.ss_size = 2 * SIGSTKSZ;
+ if (sigaltstack (&ss, NULL) < 0)
+ {
+ printf ("sigaltstack failed %m\n");
+ return 1;
+ }
+
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ return 1;
+ }
+
+ struct sigaction sa;
+ sa.sa_handler = sh;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = 0;
+
+ if (sigaction (SIGHUP, &sa, NULL) != 0)
+ {
+ puts ("sigaction failed");
+ return 1;
+ }
+
+ puts ("sa_flags = 0 test");
+ if (do_one_test ())
+ return 1;
+
+ sa.sa_handler = sh;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = SA_ONSTACK;
+
+ if (sigaction (SIGHUP, &sa, NULL) != 0)
+ {
+ puts ("sigaction failed");
+ return 1;
+ }
+
+ puts ("sa_flags = SA_ONSTACK test");
+ if (do_one_test ())
+ return 1;
+
+ sa.sa_sigaction = (void (*)(int, siginfo_t *, void *)) sh;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = SA_SIGINFO;
+
+ if (sigaction (SIGHUP, &sa, NULL) != 0)
+ {
+ puts ("sigaction failed");
+ return 1;
+ }
+
+ puts ("sa_flags = SA_SIGINFO test");
+ if (do_one_test ())
+ return 1;
+
+ sa.sa_sigaction = (void (*)(int, siginfo_t *, void *)) sh;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = SA_SIGINFO | SA_ONSTACK;
+
+ if (sigaction (SIGHUP, &sa, NULL) != 0)
+ {
+ puts ("sigaction failed");
+ return 1;
+ }
+
+ puts ("sa_flags = SA_SIGINFO|SA_ONSTACK test");
+ if (do_one_test ())
+ return 1;
+
+ return 0;
+}
+
+#define TIMEOUT 40
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel21.c b/libc/nptl/tst-cancel21.c
new file mode 100644
index 000000000..cc00cc168
--- /dev/null
+++ b/libc/nptl/tst-cancel21.c
@@ -0,0 +1,294 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+
+static int fd[4];
+static pthread_barrier_t b;
+volatile int in_sh_body;
+unsigned long cleanups;
+
+static void
+cl (void *arg)
+{
+ cleanups = (cleanups << 4) | (long) arg;
+}
+
+
+static void __attribute__((noinline))
+sh_body (void)
+{
+ char c;
+
+ pthread_cleanup_push (cl, (void *) 1L);
+
+ in_sh_body = 1;
+ if (read (fd[2], &c, 1) == 1)
+ {
+ puts ("read succeeded");
+ exit (1);
+ }
+
+ pthread_cleanup_pop (0);
+}
+
+
+static void
+sh (int sig)
+{
+ pthread_cleanup_push (cl, (void *) 2L);
+ sh_body ();
+ in_sh_body = 0;
+
+ pthread_cleanup_pop (0);
+}
+
+
+static void __attribute__((noinline))
+tf_body (void)
+{
+ char c;
+
+ pthread_cleanup_push (cl, (void *) 3L);
+
+ int r = pthread_barrier_wait (&b);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("child thread: barrier_wait failed");
+ exit (1);
+ }
+
+ if (read (fd[0], &c, 1) == 1)
+ {
+ puts ("read succeeded");
+ exit (1);
+ }
+
+ read (fd[0], &c, 1);
+
+ pthread_cleanup_pop (0);
+}
+
+
+static void *
+tf (void *arg)
+{
+ pthread_t th = (pthread_t) arg;
+
+ int r = pthread_barrier_wait (&b);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("parent thread: barrier_wait failed");
+ exit (1);
+ }
+
+ sleep (1);
+
+ r = pthread_kill (th, SIGHUP);
+ if (r)
+ {
+ errno = r;
+ printf ("pthread_kill failed %m\n");
+ exit (1);
+ }
+
+ while (in_sh_body == 0)
+ sleep (1);
+
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("cancel failed");
+ exit (1);
+ }
+
+ /* This will cause the read in the initial thread to return. */
+ close (fd[0]);
+ close (fd[1]);
+ close (fd[2]);
+ close (fd[3]);
+
+ void *ret;
+ if (pthread_join (th, &ret) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ if (ret != PTHREAD_CANCELED)
+ {
+ puts ("result is wrong");
+ exit (1);
+ }
+
+ if (cleanups != 0x1234L)
+ {
+ printf ("called cleanups %lx\n", cleanups);
+ exit (1);
+ }
+
+ if (pthread_barrier_destroy (&b))
+ {
+ puts ("barrier destroy failed");
+ exit (1);
+ }
+
+ exit (0);
+}
+
+
+static int
+do_one_test (void)
+{
+ in_sh_body = 0;
+
+ pid_t pid = fork ();
+
+ if (pid == -1)
+ {
+ printf ("fork failed: %m\n");
+ return 1;
+ }
+
+ if (pid)
+ {
+ int status;
+ if (waitpid (pid, &status, 0) < 0)
+ {
+ printf ("waitpid failed %m\n");
+ return 1;
+ }
+
+ return !WIFEXITED (status) || WEXITSTATUS (status);
+ }
+
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ cleanups = 0;
+ if (pipe (fd) != 0 || pipe (fd + 2) != 0)
+ {
+ puts ("pipe failed");
+ exit (1);
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, (void *) pthread_self ()) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ pthread_cleanup_push (cl, (void *) 4L);
+ tf_body ();
+ pthread_cleanup_pop (0);
+ exit (1);
+}
+
+
+static int
+do_test (void)
+{
+ stack_t ss;
+ ss.ss_sp = malloc (2 * SIGSTKSZ);
+ if (ss.ss_sp == NULL)
+ {
+ puts ("failed to allocate alternate stack");
+ return 1;
+ }
+ ss.ss_flags = 0;
+ ss.ss_size = 2 * SIGSTKSZ;
+ if (sigaltstack (&ss, NULL) < 0)
+ {
+ printf ("sigaltstack failed %m\n");
+ return 1;
+ }
+
+ struct sigaction sa;
+ sa.sa_handler = sh;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = 0;
+
+ if (sigaction (SIGHUP, &sa, NULL) != 0)
+ {
+ puts ("sigaction failed");
+ return 1;
+ }
+
+ puts ("sa_flags = 0 test");
+ if (do_one_test ())
+ return 1;
+
+ sa.sa_handler = sh;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = SA_ONSTACK;
+
+ if (sigaction (SIGHUP, &sa, NULL) != 0)
+ {
+ puts ("sigaction failed");
+ return 1;
+ }
+
+ puts ("sa_flags = SA_ONSTACK test");
+ if (do_one_test ())
+ return 1;
+
+ sa.sa_sigaction = (void (*)(int, siginfo_t *, void *)) sh;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = SA_SIGINFO;
+
+ if (sigaction (SIGHUP, &sa, NULL) != 0)
+ {
+ puts ("sigaction failed");
+ return 1;
+ }
+
+ puts ("sa_flags = SA_SIGINFO test");
+ if (do_one_test ())
+ return 1;
+
+ sa.sa_sigaction = (void (*)(int, siginfo_t *, void *)) sh;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = SA_SIGINFO | SA_ONSTACK;
+
+ if (sigaction (SIGHUP, &sa, NULL) != 0)
+ {
+ puts ("sigaction failed");
+ return 1;
+ }
+
+ puts ("sa_flags = SA_SIGINFO|SA_ONSTACK test");
+ if (do_one_test ())
+ return 1;
+
+ return 0;
+}
+
+#define TIMEOUT 40
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel22.c b/libc/nptl/tst-cancel22.c
new file mode 100644
index 000000000..33bfc64a3
--- /dev/null
+++ b/libc/nptl/tst-cancel22.c
@@ -0,0 +1,121 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+pthread_barrier_t b;
+int seen;
+
+static void *
+tf (void *arg)
+{
+ int old;
+ int r = pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &old);
+ if (r != 0)
+ {
+ puts ("setcancelstate failed");
+ exit (1);
+ }
+
+ r = pthread_barrier_wait (&b);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ for (int i = 0; i < 10; ++i)
+ {
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
+ TEMP_FAILURE_RETRY (nanosleep (&ts, &ts));
+ }
+
+ seen = 1;
+ pthread_setcancelstate (old, NULL);
+
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
+ TEMP_FAILURE_RETRY (nanosleep (&ts, &ts));
+
+ exit (1);
+}
+
+
+static int
+do_test (void)
+{
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier init failed");
+ return 1;
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("thread creation failed");
+ return 1;
+ }
+
+ int r = pthread_barrier_wait (&b);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ return 1;
+ }
+
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("cancel failed");
+ return 1;
+ }
+
+ void *status;
+ if (pthread_join (th, &status) != 0)
+ {
+ puts ("join failed");
+ return 1;
+ }
+ if (status != PTHREAD_CANCELED)
+ {
+ puts ("thread not canceled");
+ return 1;
+ }
+
+ if (pthread_barrier_destroy (&b) != 0)
+ {
+ puts ("barrier_destroy failed");
+ return 1;
+ }
+
+ if (seen != 1)
+ {
+ puts ("thread cancelled when PTHREAD_CANCEL_DISABLED");
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TIMEOUT 5
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel23.c b/libc/nptl/tst-cancel23.c
new file mode 100644
index 000000000..211168748
--- /dev/null
+++ b/libc/nptl/tst-cancel23.c
@@ -0,0 +1 @@
+#include "tst-cancel22.c"
diff --git a/libc/nptl/tst-cancel24.cc b/libc/nptl/tst-cancel24.cc
new file mode 100644
index 000000000..1af709a8c
--- /dev/null
+++ b/libc/nptl/tst-cancel24.cc
@@ -0,0 +1,113 @@
+#include <pthread.h>
+#include <semaphore.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+
+static volatile bool destr_called;
+static volatile bool except_caught;
+
+static pthread_barrier_t b;
+
+
+struct monitor
+{
+ // gcc is broken and would generate a warning without this dummy
+ // constructor.
+ monitor () { }
+ ~monitor() { destr_called = true; }
+};
+
+
+static void *
+tf (void *arg)
+{
+ sem_t *s = static_cast<sem_t *> (arg);
+
+ try
+ {
+ monitor m;
+
+ pthread_barrier_wait (&b);
+
+ while (1)
+ sem_wait (s);
+ }
+ catch (...)
+ {
+ except_caught = true;
+ throw;
+ }
+
+ return NULL;
+}
+
+
+static int
+do_test ()
+{
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ return 1;
+ }
+
+ sem_t s;
+ if (sem_init (&s, 0, 0) != 0)
+ {
+ puts ("sem_init failed");
+ return 1;
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, &s) != 0)
+ {
+ puts ("pthread_create failed");
+ return 1;
+ }
+
+ pthread_barrier_wait (&b);
+
+ /* There is unfortunately no better method to try to assure the
+ child thread reached the sem_wait call and is actually waiting
+ than to sleep here. */
+ sleep (1);
+
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("cancel failed");
+ return 1;
+ }
+
+ void *res;
+ if (pthread_join (th, &res) != 0)
+ {
+ puts ("join failed");
+ return 1;
+ }
+
+ if (res != PTHREAD_CANCELED)
+ {
+ puts ("thread was not canceled");
+ return 1;
+ }
+
+ if (! except_caught)
+ {
+ puts ("exception not caught");
+ return 1;
+ }
+
+ if (! destr_called)
+ {
+ puts ("destructor not called");
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#define TIMEOUT 3
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel3.c b/libc/nptl/tst-cancel3.c
new file mode 100644
index 000000000..86c482bcc
--- /dev/null
+++ b/libc/nptl/tst-cancel3.c
@@ -0,0 +1,98 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+
+
+static int fd[2];
+
+
+static void *
+tf (void *arg)
+{
+ char buf[100];
+
+ if (read (fd[0], buf, sizeof (buf)) == sizeof (buf))
+ {
+ puts ("read succeeded");
+ return (void *) 1l;
+ }
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t th;
+ void *r;
+ struct sigaction sa;
+
+ sa.sa_handler = SIG_IGN;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = 0;
+
+ if (sigaction (SIGPIPE, &sa, NULL) != 0)
+ {
+ puts ("sigaction failed");
+ return 1;
+ }
+
+ if (pipe (fd) != 0)
+ {
+ puts ("pipe failed");
+ return 1;
+ }
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ return 1;
+ }
+
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("cancel failed");
+ return 1;
+ }
+
+ /* This will cause the read in the child to return. */
+ close (fd[0]);
+
+ if (pthread_join (th, &r) != 0)
+ {
+ puts ("join failed");
+ return 1;
+ }
+
+ if (r != PTHREAD_CANCELED)
+ {
+ puts ("result is wrong");
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel4.c b/libc/nptl/tst-cancel4.c
new file mode 100644
index 000000000..73cfa4461
--- /dev/null
+++ b/libc/nptl/tst-cancel4.c
@@ -0,0 +1,2330 @@
+/* Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+/* NOTE: this tests functionality beyond POSIX. POSIX does not allow
+ exit to be called more than once. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <pthread.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/msg.h>
+#include <sys/poll.h>
+#include <sys/select.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+#include <sys/un.h>
+#include <sys/wait.h>
+
+#include "pthreadP.h"
+
+
+/* Since STREAMS are not supported in the standard Linux kernel and
+ there we don't advertise STREAMS as supported is no need to test
+ the STREAMS related functions. This affects
+ getmsg() getpmsg() putmsg()
+ putpmsg()
+
+ lockf() and fcntl() are tested in tst-cancel16.
+
+ pthread_join() is tested in tst-join5.
+
+ pthread_testcancel()'s only purpose is to allow cancellation. This
+ is tested in several places.
+
+ sem_wait() and sem_timedwait() are checked in tst-cancel1[2345] tests.
+
+ mq_send(), mq_timedsend(), mq_receive() and mq_timedreceive() are checked
+ in tst-mqueue8{,x} tests.
+
+ aio_suspend() is tested in tst-cancel17.
+
+ clock_nanosleep() is tested in tst-cancel18.
+*/
+
+/* Pipe descriptors. */
+static int fds[2];
+
+/* Temporary file descriptor, to be closed after each round. */
+static int tempfd = -1;
+static int tempfd2 = -1;
+/* Name of temporary file to be removed after each round. */
+static char *tempfname;
+/* Temporary message queue. */
+static int tempmsg = -1;
+
+/* Often used barrier for two threads. */
+static pthread_barrier_t b2;
+
+
+#ifndef IPC_ADDVAL
+# define IPC_ADDVAL 0
+#endif
+
+#define WRITE_BUFFER_SIZE 4096
+
+/* Cleanup handling test. */
+static int cl_called;
+
+static void
+cl (void *arg)
+{
+ ++cl_called;
+}
+
+
+
+static void *
+tf_read (void *arg)
+{
+ int fd;
+ int r;
+
+ if (arg == NULL)
+ fd = fds[0];
+ else
+ {
+ char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
+ tempfd = fd = mkstemp (fname);
+ if (fd == -1)
+ printf ("%s: mkstemp failed\n", __FUNCTION__);
+ unlink (fname);
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ ssize_t s;
+ pthread_cleanup_push (cl, NULL);
+
+ char buf[100];
+ s = read (fd, buf, sizeof (buf));
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: read returns with %zd\n", __FUNCTION__, s);
+
+ exit (1);
+}
+
+
+static void *
+tf_readv (void *arg)
+{
+ int fd;
+ int r;
+
+ if (arg == NULL)
+ fd = fds[0];
+ else
+ {
+ char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
+ tempfd = fd = mkstemp (fname);
+ if (fd == -1)
+ printf ("%s: mkstemp failed\n", __FUNCTION__);
+ unlink (fname);
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ ssize_t s;
+ pthread_cleanup_push (cl, NULL);
+
+ char buf[100];
+ struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
+ s = readv (fd, iov, 1);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: readv returns with %zd\n", __FUNCTION__, s);
+
+ exit (1);
+}
+
+
+static void *
+tf_write (void *arg)
+{
+ int fd;
+ int r;
+
+ if (arg == NULL)
+ fd = fds[1];
+ else
+ {
+ char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
+ tempfd = fd = mkstemp (fname);
+ if (fd == -1)
+ printf ("%s: mkstemp failed\n", __FUNCTION__);
+ unlink (fname);
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ ssize_t s;
+ pthread_cleanup_push (cl, NULL);
+
+ char buf[WRITE_BUFFER_SIZE];
+ memset (buf, '\0', sizeof (buf));
+ s = write (fd, buf, sizeof (buf));
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: write returns with %zd\n", __FUNCTION__, s);
+
+ exit (1);
+}
+
+
+static void *
+tf_writev (void *arg)
+{
+ int fd;
+ int r;
+
+ if (arg == NULL)
+ fd = fds[1];
+ else
+ {
+ char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
+ tempfd = fd = mkstemp (fname);
+ if (fd == -1)
+ printf ("%s: mkstemp failed\n", __FUNCTION__);
+ unlink (fname);
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ ssize_t s;
+ pthread_cleanup_push (cl, NULL);
+
+ char buf[WRITE_BUFFER_SIZE];
+ memset (buf, '\0', sizeof (buf));
+ struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
+ s = writev (fd, iov, 1);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: writev returns with %zd\n", __FUNCTION__, s);
+
+ exit (1);
+}
+
+
+static void *
+tf_sleep (void *arg)
+{
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ if (arg != NULL)
+ {
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ sleep (arg == NULL ? 1000000 : 0);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: sleep returns\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_usleep (void *arg)
+{
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ if (arg != NULL)
+ {
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ usleep (arg == NULL ? (useconds_t) ULONG_MAX : 0);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: usleep returns\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_nanosleep (void *arg)
+{
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ if (arg != NULL)
+ {
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ struct timespec ts = { .tv_sec = arg == NULL ? 10000000 : 0, .tv_nsec = 0 };
+ TEMP_FAILURE_RETRY (nanosleep (&ts, &ts));
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: nanosleep returns\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_select (void *arg)
+{
+ int fd;
+ int r;
+
+ if (arg == NULL)
+ fd = fds[0];
+ else
+ {
+ char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
+ tempfd = fd = mkstemp (fname);
+ if (fd == -1)
+ printf ("%s: mkstemp failed\n", __FUNCTION__);
+ unlink (fname);
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ fd_set rfs;
+ FD_ZERO (&rfs);
+ FD_SET (fd, &rfs);
+
+ int s;
+ pthread_cleanup_push (cl, NULL);
+
+ s = select (fd + 1, &rfs, NULL, NULL, NULL);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: select returns with %d (%s)\n", __FUNCTION__, s,
+ strerror (errno));
+
+ exit (1);
+}
+
+
+static void *
+tf_pselect (void *arg)
+{
+ int fd;
+ int r;
+
+ if (arg == NULL)
+ fd = fds[0];
+ else
+ {
+ char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
+ tempfd = fd = mkstemp (fname);
+ if (fd == -1)
+ printf ("%s: mkstemp failed\n", __FUNCTION__);
+ unlink (fname);
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ fd_set rfs;
+ FD_ZERO (&rfs);
+ FD_SET (fd, &rfs);
+
+ int s;
+ pthread_cleanup_push (cl, NULL);
+
+ s = pselect (fd + 1, &rfs, NULL, NULL, NULL, NULL);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: pselect returns with %d (%s)\n", __FUNCTION__, s,
+ strerror (errno));
+
+ exit (1);
+}
+
+
+static void *
+tf_poll (void *arg)
+{
+ int fd;
+ int r;
+
+ if (arg == NULL)
+ fd = fds[0];
+ else
+ {
+ char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
+ tempfd = fd = mkstemp (fname);
+ if (fd == -1)
+ printf ("%s: mkstemp failed\n", __FUNCTION__);
+ unlink (fname);
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ struct pollfd rfs[1] = { [0] = { .fd = fd, .events = POLLIN } };
+
+ int s;
+ pthread_cleanup_push (cl, NULL);
+
+ s = poll (rfs, 1, -1);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: poll returns with %d (%s)\n", __FUNCTION__, s,
+ strerror (errno));
+
+ exit (1);
+}
+
+
+static void *
+tf_ppoll (void *arg)
+{
+ int fd;
+ int r;
+
+ if (arg == NULL)
+ fd = fds[0];
+ else
+ {
+ char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
+ tempfd = fd = mkstemp (fname);
+ if (fd == -1)
+ printf ("%s: mkstemp failed\n", __FUNCTION__);
+ unlink (fname);
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ struct pollfd rfs[1] = { [0] = { .fd = fd, .events = POLLIN } };
+
+ int s;
+ pthread_cleanup_push (cl, NULL);
+
+ s = ppoll (rfs, 1, NULL, NULL);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: ppoll returns with %d (%s)\n", __FUNCTION__, s,
+ strerror (errno));
+
+ exit (1);
+}
+
+
+static void *
+tf_wait (void *arg)
+{
+ pid_t pid = fork ();
+ if (pid == -1)
+ {
+ puts ("fork failed");
+ exit (1);
+ }
+
+ if (pid == 0)
+ {
+ /* Make the program disappear after a while. */
+ if (arg == NULL)
+ sleep (10);
+ exit (0);
+ }
+
+ int r;
+ if (arg != NULL)
+ {
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
+ while (nanosleep (&ts, &ts) != 0)
+ continue;
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ int s;
+ pthread_cleanup_push (cl, NULL);
+
+ s = wait (NULL);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: wait returns with %d (%s)\n", __FUNCTION__, s,
+ strerror (errno));
+
+ exit (1);
+}
+
+
+static void *
+tf_waitpid (void *arg)
+{
+
+ pid_t pid = fork ();
+ if (pid == -1)
+ {
+ puts ("fork failed");
+ exit (1);
+ }
+
+ if (pid == 0)
+ {
+ /* Make the program disappear after a while. */
+ if (arg == NULL)
+ sleep (10);
+ exit (0);
+ }
+
+ int r;
+ if (arg != NULL)
+ {
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
+ while (nanosleep (&ts, &ts) != 0)
+ continue;
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ int s;
+ pthread_cleanup_push (cl, NULL);
+
+ s = waitpid (-1, NULL, 0);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: waitpid returns with %d (%s)\n", __FUNCTION__, s,
+ strerror (errno));
+
+ exit (1);
+}
+
+
+static void *
+tf_waitid (void *arg)
+{
+ pid_t pid = fork ();
+ if (pid == -1)
+ {
+ puts ("fork failed");
+ exit (1);
+ }
+
+ if (pid == 0)
+ {
+ /* Make the program disappear after a while. */
+ if (arg == NULL)
+ sleep (10);
+ exit (0);
+ }
+
+ int r;
+ if (arg != NULL)
+ {
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
+ while (nanosleep (&ts, &ts) != 0)
+ continue;
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ int s;
+ pthread_cleanup_push (cl, NULL);
+
+#ifndef WEXITED
+# define WEXITED 0
+#endif
+ siginfo_t si;
+ s = waitid (P_PID, pid, &si, WEXITED);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: waitid returns with %d (%s)\n", __FUNCTION__, s,
+ strerror (errno));
+
+ exit (1);
+}
+
+
+static void *
+tf_sigpause (void *arg)
+{
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ if (arg != NULL)
+ {
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ /* Just for fun block the cancellation signal. We need to use
+ __xpg_sigpause since otherwise we will get the BSD version. */
+ __xpg_sigpause (SIGCANCEL);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: sigpause returned\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_sigsuspend (void *arg)
+{
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ if (arg != NULL)
+ {
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ /* Just for fun block all signals. */
+ sigset_t mask;
+ sigfillset (&mask);
+ sigsuspend (&mask);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: sigsuspend returned\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_sigwait (void *arg)
+{
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ if (arg != NULL)
+ {
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ /* Block SIGUSR1. */
+ sigset_t mask;
+ sigemptyset (&mask);
+ sigaddset (&mask, SIGUSR1);
+ if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
+ {
+ printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ int sig;
+ pthread_cleanup_push (cl, NULL);
+
+ /* Wait for SIGUSR1. */
+ sigwait (&mask, &sig);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: sigwait returned with signal %d\n", __FUNCTION__, sig);
+
+ exit (1);
+}
+
+
+static void *
+tf_sigwaitinfo (void *arg)
+{
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ if (arg != NULL)
+ {
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ /* Block SIGUSR1. */
+ sigset_t mask;
+ sigemptyset (&mask);
+ sigaddset (&mask, SIGUSR1);
+ if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
+ {
+ printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ siginfo_t info;
+ pthread_cleanup_push (cl, NULL);
+
+ /* Wait for SIGUSR1. */
+ sigwaitinfo (&mask, &info);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: sigwaitinfo returned with signal %d\n", __FUNCTION__,
+ info.si_signo);
+
+ exit (1);
+}
+
+
+static void *
+tf_sigtimedwait (void *arg)
+{
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ if (arg != NULL)
+ {
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ /* Block SIGUSR1. */
+ sigset_t mask;
+ sigemptyset (&mask);
+ sigaddset (&mask, SIGUSR1);
+ if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
+ {
+ printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ /* Wait for SIGUSR1. */
+ siginfo_t info;
+ struct timespec ts = { .tv_sec = 60, .tv_nsec = 0 };
+ pthread_cleanup_push (cl, NULL);
+
+ sigtimedwait (&mask, &info, &ts);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: sigtimedwait returned with signal %d\n", __FUNCTION__,
+ info.si_signo);
+
+ exit (1);
+}
+
+
+static void *
+tf_pause (void *arg)
+{
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ if (arg != NULL)
+ {
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ pause ();
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: pause returned\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_accept (void *arg)
+{
+ struct sockaddr_un sun;
+ /* To test a non-blocking accept call we make the call file by using
+ a datagrame socket. */
+ int pf = arg == NULL ? SOCK_STREAM : SOCK_DGRAM;
+
+ tempfd = socket (AF_UNIX, pf, 0);
+ if (tempfd == -1)
+ {
+ printf ("%s: socket call failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ int tries = 0;
+ do
+ {
+ if (++tries > 10)
+ {
+ printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
+ }
+
+ strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-1-XXXXXX");
+ if (mktemp (sun.sun_path) == NULL)
+ {
+ printf ("%s: cannot generate temp file name\n", __FUNCTION__);
+ exit (1);
+ }
+
+ sun.sun_family = AF_UNIX;
+ }
+ while (bind (tempfd, (struct sockaddr *) &sun,
+ offsetof (struct sockaddr_un, sun_path)
+ + strlen (sun.sun_path) + 1) != 0);
+
+ unlink (sun.sun_path);
+
+ listen (tempfd, 5);
+
+ socklen_t len = sizeof (sun);
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ if (arg != NULL)
+ {
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ accept (tempfd, (struct sockaddr *) &sun, &len);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: accept returned\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_send (void *arg)
+{
+ struct sockaddr_un sun;
+
+ tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
+ if (tempfd == -1)
+ {
+ printf ("%s: first socket call failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ int tries = 0;
+ do
+ {
+ if (++tries > 10)
+ {
+ printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
+ }
+
+ strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
+ if (mktemp (sun.sun_path) == NULL)
+ {
+ printf ("%s: cannot generate temp file name\n", __FUNCTION__);
+ exit (1);
+ }
+
+ sun.sun_family = AF_UNIX;
+ }
+ while (bind (tempfd, (struct sockaddr *) &sun,
+ offsetof (struct sockaddr_un, sun_path)
+ + strlen (sun.sun_path) + 1) != 0);
+
+ listen (tempfd, 5);
+
+ tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
+ if (tempfd2 == -1)
+ {
+ printf ("%s: second socket call failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
+ {
+ printf ("%s: connect failed\n", __FUNCTION__);
+ exit(1);
+ }
+
+ unlink (sun.sun_path);
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ if (arg != NULL)
+ {
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ /* Very large block, so that the send call blocks. */
+ char mem[700000];
+
+ send (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: send returned\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_recv (void *arg)
+{
+ struct sockaddr_un sun;
+
+ tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
+ if (tempfd == -1)
+ {
+ printf ("%s: first socket call failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ int tries = 0;
+ do
+ {
+ if (++tries > 10)
+ {
+ printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
+ }
+
+ strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-3-XXXXXX");
+ if (mktemp (sun.sun_path) == NULL)
+ {
+ printf ("%s: cannot generate temp file name\n", __FUNCTION__);
+ exit (1);
+ }
+
+ sun.sun_family = AF_UNIX;
+ }
+ while (bind (tempfd, (struct sockaddr *) &sun,
+ offsetof (struct sockaddr_un, sun_path)
+ + strlen (sun.sun_path) + 1) != 0);
+
+ listen (tempfd, 5);
+
+ tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
+ if (tempfd2 == -1)
+ {
+ printf ("%s: second socket call failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
+ {
+ printf ("%s: connect failed\n", __FUNCTION__);
+ exit(1);
+ }
+
+ unlink (sun.sun_path);
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ if (arg != NULL)
+ {
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ char mem[70];
+
+ recv (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: recv returned\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_recvfrom (void *arg)
+{
+ struct sockaddr_un sun;
+
+ tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
+ if (tempfd == -1)
+ {
+ printf ("%s: first socket call failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ int tries = 0;
+ do
+ {
+ if (++tries > 10)
+ {
+ printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
+ }
+
+ strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-4-XXXXXX");
+ if (mktemp (sun.sun_path) == NULL)
+ {
+ printf ("%s: cannot generate temp file name\n", __FUNCTION__);
+ exit (1);
+ }
+
+ sun.sun_family = AF_UNIX;
+ }
+ while (bind (tempfd, (struct sockaddr *) &sun,
+ offsetof (struct sockaddr_un, sun_path)
+ + strlen (sun.sun_path) + 1) != 0);
+
+ tempfname = strdup (sun.sun_path);
+
+ tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
+ if (tempfd2 == -1)
+ {
+ printf ("%s: second socket call failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ if (arg != NULL)
+ {
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ char mem[70];
+ socklen_t len = sizeof (sun);
+
+ recvfrom (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0,
+ (struct sockaddr *) &sun, &len);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: recvfrom returned\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_recvmsg (void *arg)
+{
+ struct sockaddr_un sun;
+
+ tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
+ if (tempfd == -1)
+ {
+ printf ("%s: first socket call failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ int tries = 0;
+ do
+ {
+ if (++tries > 10)
+ {
+ printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
+ }
+
+ strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-5-XXXXXX");
+ if (mktemp (sun.sun_path) == NULL)
+ {
+ printf ("%s: cannot generate temp file name\n", __FUNCTION__);
+ exit (1);
+ }
+
+ sun.sun_family = AF_UNIX;
+ }
+ while (bind (tempfd, (struct sockaddr *) &sun,
+ offsetof (struct sockaddr_un, sun_path)
+ + strlen (sun.sun_path) + 1) != 0);
+
+ tempfname = strdup (sun.sun_path);
+
+ tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
+ if (tempfd2 == -1)
+ {
+ printf ("%s: second socket call failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ if (arg != NULL)
+ {
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ char mem[70];
+ struct iovec iov[1];
+ iov[0].iov_base = mem;
+ iov[0].iov_len = arg == NULL ? sizeof (mem) : 0;
+
+ struct msghdr m;
+ m.msg_name = &sun;
+ m.msg_namelen = sizeof (sun);
+ m.msg_iov = iov;
+ m.msg_iovlen = 1;
+ m.msg_control = NULL;
+ m.msg_controllen = 0;
+
+ recvmsg (tempfd2, &m, 0);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: recvmsg returned\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_open (void *arg)
+{
+ if (arg == NULL)
+ // XXX If somebody can provide a portable test case in which open()
+ // blocks we can enable this test to run in both rounds.
+ abort ();
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ open ("Makefile", O_RDONLY);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: open returned\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_close (void *arg)
+{
+ if (arg == NULL)
+ // XXX If somebody can provide a portable test case in which close()
+ // blocks we can enable this test to run in both rounds.
+ abort ();
+
+ char fname[] = "/tmp/tst-cancel-fd-XXXXXX";
+ tempfd = mkstemp (fname);
+ if (tempfd == -1)
+ {
+ printf ("%s: mkstemp failed\n", __FUNCTION__);
+ exit (1);
+ }
+ unlink (fname);
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ close (tempfd);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: close returned\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_pread (void *arg)
+{
+ if (arg == NULL)
+ // XXX If somebody can provide a portable test case in which pread()
+ // blocks we can enable this test to run in both rounds.
+ abort ();
+
+ tempfd = open ("Makefile", O_RDONLY);
+ if (tempfd == -1)
+ {
+ printf ("%s: cannot open Makefile\n", __FUNCTION__);
+ exit (1);
+ }
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ char mem[10];
+ pread (tempfd, mem, sizeof (mem), 0);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: pread returned\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_pwrite (void *arg)
+{
+ if (arg == NULL)
+ // XXX If somebody can provide a portable test case in which pwrite()
+ // blocks we can enable this test to run in both rounds.
+ abort ();
+
+ char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
+ tempfd = mkstemp (fname);
+ if (tempfd == -1)
+ {
+ printf ("%s: mkstemp failed\n", __FUNCTION__);
+ exit (1);
+ }
+ unlink (fname);
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ char mem[10];
+ pwrite (tempfd, mem, sizeof (mem), 0);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: pwrite returned\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_fsync (void *arg)
+{
+ if (arg == NULL)
+ // XXX If somebody can provide a portable test case in which fsync()
+ // blocks we can enable this test to run in both rounds.
+ abort ();
+
+ tempfd = open ("Makefile", O_RDONLY);
+ if (tempfd == -1)
+ {
+ printf ("%s: cannot open Makefile\n", __FUNCTION__);
+ exit (1);
+ }
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ fsync (tempfd);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: fsync returned\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_msync (void *arg)
+{
+ if (arg == NULL)
+ // XXX If somebody can provide a portable test case in which msync()
+ // blocks we can enable this test to run in both rounds.
+ abort ();
+
+ tempfd = open ("Makefile", O_RDONLY);
+ if (tempfd == -1)
+ {
+ printf ("%s: cannot open Makefile\n", __FUNCTION__);
+ exit (1);
+ }
+ void *p = mmap (NULL, 10, PROT_READ, MAP_SHARED, tempfd, 0);
+ if (p == MAP_FAILED)
+ {
+ printf ("%s: mmap failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ msync (p, 10, 0);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: msync returned\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_sendto (void *arg)
+{
+ if (arg == NULL)
+ // XXX If somebody can provide a portable test case in which sendto()
+ // blocks we can enable this test to run in both rounds.
+ abort ();
+
+ struct sockaddr_un sun;
+
+ tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
+ if (tempfd == -1)
+ {
+ printf ("%s: first socket call failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ int tries = 0;
+ do
+ {
+ if (++tries > 10)
+ {
+ printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
+ }
+
+ strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-6-XXXXXX");
+ if (mktemp (sun.sun_path) == NULL)
+ {
+ printf ("%s: cannot generate temp file name\n", __FUNCTION__);
+ exit (1);
+ }
+
+ sun.sun_family = AF_UNIX;
+ }
+ while (bind (tempfd, (struct sockaddr *) &sun,
+ offsetof (struct sockaddr_un, sun_path)
+ + strlen (sun.sun_path) + 1) != 0);
+ tempfname = strdup (sun.sun_path);
+
+ tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
+ if (tempfd2 == -1)
+ {
+ printf ("%s: second socket call failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ char mem[1];
+
+ sendto (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0,
+ (struct sockaddr *) &sun,
+ offsetof (struct sockaddr_un, sun_path) + strlen (sun.sun_path) + 1);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: sendto returned\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_sendmsg (void *arg)
+{
+ if (arg == NULL)
+ // XXX If somebody can provide a portable test case in which sendmsg()
+ // blocks we can enable this test to run in both rounds.
+ abort ();
+
+ struct sockaddr_un sun;
+
+ tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
+ if (tempfd == -1)
+ {
+ printf ("%s: first socket call failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ int tries = 0;
+ do
+ {
+ if (++tries > 10)
+ {
+ printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
+ }
+
+ strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-7-XXXXXX");
+ if (mktemp (sun.sun_path) == NULL)
+ {
+ printf ("%s: cannot generate temp file name\n", __FUNCTION__);
+ exit (1);
+ }
+
+ sun.sun_family = AF_UNIX;
+ }
+ while (bind (tempfd, (struct sockaddr *) &sun,
+ offsetof (struct sockaddr_un, sun_path)
+ + strlen (sun.sun_path) + 1) != 0);
+ tempfname = strdup (sun.sun_path);
+
+ tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
+ if (tempfd2 == -1)
+ {
+ printf ("%s: second socket call failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ char mem[1];
+ struct iovec iov[1];
+ iov[0].iov_base = mem;
+ iov[0].iov_len = 1;
+
+ struct msghdr m;
+ m.msg_name = &sun;
+ m.msg_namelen = (offsetof (struct sockaddr_un, sun_path)
+ + strlen (sun.sun_path) + 1);
+ m.msg_iov = iov;
+ m.msg_iovlen = 1;
+ m.msg_control = NULL;
+ m.msg_controllen = 0;
+
+ sendmsg (tempfd2, &m, 0);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: sendmsg returned\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_creat (void *arg)
+{
+ if (arg == NULL)
+ // XXX If somebody can provide a portable test case in which sendmsg()
+ // blocks we can enable this test to run in both rounds.
+ abort ();
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ creat ("tmp/tst-cancel-4-should-not-exist", 0666);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: creat returned\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_connect (void *arg)
+{
+ if (arg == NULL)
+ // XXX If somebody can provide a portable test case in which connect()
+ // blocks we can enable this test to run in both rounds.
+ abort ();
+
+ struct sockaddr_un sun;
+
+ tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
+ if (tempfd == -1)
+ {
+ printf ("%s: first socket call failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ int tries = 0;
+ do
+ {
+ if (++tries > 10)
+ {
+ printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
+ }
+
+ strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
+ if (mktemp (sun.sun_path) == NULL)
+ {
+ printf ("%s: cannot generate temp file name\n", __FUNCTION__);
+ exit (1);
+ }
+
+ sun.sun_family = AF_UNIX;
+ }
+ while (bind (tempfd, (struct sockaddr *) &sun,
+ offsetof (struct sockaddr_un, sun_path)
+ + strlen (sun.sun_path) + 1) != 0);
+ tempfname = strdup (sun.sun_path);
+
+ listen (tempfd, 5);
+
+ tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
+ if (tempfd2 == -1)
+ {
+ printf ("%s: second socket call failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ if (arg != NULL)
+ {
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun));
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: connect returned\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_tcdrain (void *arg)
+{
+ if (arg == NULL)
+ // XXX If somebody can provide a portable test case in which tcdrain()
+ // blocks we can enable this test to run in both rounds.
+ abort ();
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ if (arg != NULL)
+ {
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ /* Regardless of stderr being a terminal, the tcdrain call should be
+ canceled. */
+ tcdrain (STDERR_FILENO);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: tcdrain returned\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
+tf_msgrcv (void *arg)
+{
+ tempmsg = msgget (IPC_PRIVATE, 0666 | IPC_CREAT);
+ if (tempmsg == -1)
+ {
+ printf ("%s: msgget failed: %s\n", __FUNCTION__, strerror (errno));
+ exit (1);
+ }
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ if (arg != NULL)
+ {
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+ }
+
+ ssize_t s;
+
+ pthread_cleanup_push (cl, NULL);
+
+ struct
+ {
+ long int type;
+ char mem[10];
+ } m;
+ int randnr;
+ /* We need a positive random number. */
+ do
+ randnr = random () % 64000;
+ while (randnr <= 0);
+ do
+ {
+ errno = 0;
+ s = msgrcv (tempmsg, (struct msgbuf *) &m, 10, randnr, 0);
+ }
+ while (errno == EIDRM || errno == EINTR);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: msgrcv returned %zd with errno = %m\n", __FUNCTION__, s);
+
+ msgctl (tempmsg, IPC_RMID, NULL);
+
+ exit (1);
+}
+
+
+static void *
+tf_msgsnd (void *arg)
+{
+ if (arg == NULL)
+ // XXX If somebody can provide a portable test case in which msgsnd()
+ // blocks we can enable this test to run in both rounds.
+ abort ();
+
+ tempmsg = msgget (IPC_PRIVATE, 0666 | IPC_CREAT);
+ if (tempmsg == -1)
+ {
+ printf ("%s: msgget failed: %s\n", __FUNCTION__, strerror (errno));
+ exit (1);
+ }
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ struct
+ {
+ long int type;
+ char mem[1];
+ } m;
+ /* We need a positive random number. */
+ do
+ m.type = random () % 64000;
+ while (m.type <= 0);
+ msgsnd (tempmsg, (struct msgbuf *) &m, sizeof (m.mem), 0);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: msgsnd returned\n", __FUNCTION__);
+
+ msgctl (tempmsg, IPC_RMID, NULL);
+
+ exit (1);
+}
+
+
+static struct
+{
+ const char *name;
+ void *(*tf) (void *);
+ int nb;
+ int only_early;
+} tests[] =
+{
+#define ADD_TEST(name, nbar, early) { #name, tf_##name, nbar, early }
+ ADD_TEST (read, 2, 0),
+ ADD_TEST (readv, 2, 0),
+ ADD_TEST (select, 2, 0),
+ ADD_TEST (pselect, 2, 0),
+ ADD_TEST (poll, 2, 0),
+ ADD_TEST (ppoll, 2, 0),
+ ADD_TEST (write, 2, 0),
+ ADD_TEST (writev, 2, 0),
+ ADD_TEST (sleep, 2, 0),
+ ADD_TEST (usleep, 2, 0),
+ ADD_TEST (nanosleep, 2, 0),
+ ADD_TEST (wait, 2, 0),
+ ADD_TEST (waitid, 2, 0),
+ ADD_TEST (waitpid, 2, 0),
+ ADD_TEST (sigpause, 2, 0),
+ ADD_TEST (sigsuspend, 2, 0),
+ ADD_TEST (sigwait, 2, 0),
+ ADD_TEST (sigwaitinfo, 2, 0),
+ ADD_TEST (sigtimedwait, 2, 0),
+ ADD_TEST (pause, 2, 0),
+ ADD_TEST (accept, 2, 0),
+ ADD_TEST (send, 2, 0),
+ ADD_TEST (recv, 2, 0),
+ ADD_TEST (recvfrom, 2, 0),
+ ADD_TEST (recvmsg, 2, 0),
+ ADD_TEST (open, 2, 1),
+ ADD_TEST (close, 2, 1),
+ ADD_TEST (pread, 2, 1),
+ ADD_TEST (pwrite, 2, 1),
+ ADD_TEST (fsync, 2, 1),
+ ADD_TEST (msync, 2, 1),
+ ADD_TEST (sendto, 2, 1),
+ ADD_TEST (sendmsg, 2, 1),
+ ADD_TEST (creat, 2, 1),
+ ADD_TEST (connect, 2, 1),
+ ADD_TEST (tcdrain, 2, 1),
+ ADD_TEST (msgrcv, 2, 0),
+ ADD_TEST (msgsnd, 2, 1),
+};
+#define ntest_tf (sizeof (tests) / sizeof (tests[0]))
+
+
+static int
+do_test (void)
+{
+ int val;
+ socklen_t len;
+
+ if (socketpair (AF_UNIX, SOCK_STREAM, PF_UNIX, fds) != 0)
+ {
+ perror ("socketpair");
+ exit (1);
+ }
+
+ val = 1;
+ len = sizeof(val);
+ setsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val));
+ if (getsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, &len) < 0)
+ {
+ perror ("getsockopt");
+ exit (1);
+ }
+ if (val >= WRITE_BUFFER_SIZE)
+ {
+ puts ("minimum write buffer size too large");
+ exit (1);
+ }
+ setsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val));
+
+ int result = 0;
+ size_t cnt;
+ for (cnt = 0; cnt < ntest_tf; ++cnt)
+ {
+ if (tests[cnt].only_early)
+ continue;
+
+ if (pthread_barrier_init (&b2, NULL, tests[cnt].nb) != 0)
+ {
+ puts ("b2 init failed");
+ exit (1);
+ }
+
+ /* Reset the counter for the cleanup handler. */
+ cl_called = 0;
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tests[cnt].tf, NULL) != 0)
+ {
+ printf ("create for '%s' test failed\n", tests[cnt].name);
+ result = 1;
+ continue;
+ }
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ result = 1;
+ continue;
+ }
+
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
+ while (nanosleep (&ts, &ts) != 0)
+ continue;
+
+ if (pthread_cancel (th) != 0)
+ {
+ printf ("cancel for '%s' failed\n", tests[cnt].name);
+ result = 1;
+ continue;
+ }
+
+ void *status;
+ if (pthread_join (th, &status) != 0)
+ {
+ printf ("join for '%s' failed\n", tests[cnt].name);
+ result = 1;
+ continue;
+ }
+ if (status != PTHREAD_CANCELED)
+ {
+ printf ("thread for '%s' not canceled\n", tests[cnt].name);
+ result = 1;
+ continue;
+ }
+
+ if (pthread_barrier_destroy (&b2) != 0)
+ {
+ puts ("barrier_destroy failed");
+ result = 1;
+ continue;
+ }
+
+ if (cl_called == 0)
+ {
+ printf ("cleanup handler not called for '%s'\n", tests[cnt].name);
+ result = 1;
+ continue;
+ }
+ if (cl_called > 1)
+ {
+ printf ("cleanup handler called more than once for '%s'\n",
+ tests[cnt].name);
+ result = 1;
+ continue;
+ }
+
+ printf ("in-time cancel test of '%s' successful\n", tests[cnt].name);
+
+ if (tempfd != -1)
+ {
+ close (tempfd);
+ tempfd = -1;
+ }
+ if (tempfd2 != -1)
+ {
+ close (tempfd2);
+ tempfd2 = -1;
+ }
+ if (tempfname != NULL)
+ {
+ unlink (tempfname);
+ free (tempfname);
+ tempfname = NULL;
+ }
+ if (tempmsg != -1)
+ {
+ msgctl (tempmsg, IPC_RMID, NULL);
+ tempmsg = -1;
+ }
+ }
+
+ for (cnt = 0; cnt < ntest_tf; ++cnt)
+ {
+ if (pthread_barrier_init (&b2, NULL, tests[cnt].nb) != 0)
+ {
+ puts ("b2 init failed");
+ exit (1);
+ }
+
+ /* Reset the counter for the cleanup handler. */
+ cl_called = 0;
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tests[cnt].tf, (void *) 1l) != 0)
+ {
+ printf ("create for '%s' test failed\n", tests[cnt].name);
+ result = 1;
+ continue;
+ }
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ result = 1;
+ continue;
+ }
+
+ if (pthread_cancel (th) != 0)
+ {
+ printf ("cancel for '%s' failed\n", tests[cnt].name);
+ result = 1;
+ continue;
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ result = 1;
+ continue;
+ }
+
+ void *status;
+ if (pthread_join (th, &status) != 0)
+ {
+ printf ("join for '%s' failed\n", tests[cnt].name);
+ result = 1;
+ continue;
+ }
+ if (status != PTHREAD_CANCELED)
+ {
+ printf ("thread for '%s' not canceled\n", tests[cnt].name);
+ result = 1;
+ continue;
+ }
+
+ if (pthread_barrier_destroy (&b2) != 0)
+ {
+ puts ("barrier_destroy failed");
+ result = 1;
+ continue;
+ }
+
+ if (cl_called == 0)
+ {
+ printf ("cleanup handler not called for '%s'\n", tests[cnt].name);
+ result = 1;
+ continue;
+ }
+ if (cl_called > 1)
+ {
+ printf ("cleanup handler called more than once for '%s'\n",
+ tests[cnt].name);
+ result = 1;
+ continue;
+ }
+
+ printf ("early cancel test of '%s' successful\n", tests[cnt].name);
+
+ if (tempfd != -1)
+ {
+ close (tempfd);
+ tempfd = -1;
+ }
+ if (tempfd2 != -1)
+ {
+ close (tempfd2);
+ tempfd2 = -1;
+ }
+ if (tempfname != NULL)
+ {
+ unlink (tempfname);
+ free (tempfname);
+ tempfname = NULL;
+ }
+ if (tempmsg != -1)
+ {
+ msgctl (tempmsg, IPC_RMID, NULL);
+ tempmsg = -1;
+ }
+ }
+
+ return result;
+}
+
+#define TIMEOUT 60
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel5.c b/libc/nptl/tst-cancel5.c
new file mode 100644
index 000000000..1c879eba8
--- /dev/null
+++ b/libc/nptl/tst-cancel5.c
@@ -0,0 +1 @@
+#include "tst-cancel4.c"
diff --git a/libc/nptl/tst-cancel6.c b/libc/nptl/tst-cancel6.c
new file mode 100644
index 000000000..94de85830
--- /dev/null
+++ b/libc/nptl/tst-cancel6.c
@@ -0,0 +1,79 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static void *
+tf (void *arg)
+{
+ char buf[100];
+ fgets (buf, sizeof (buf), arg);
+ /* This call should never return. */
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ int fd[2];
+ if (pipe (fd) != 0)
+ {
+ puts ("pipe failed");
+ return 1;
+ }
+
+ FILE *fp = fdopen (fd[0], "r");
+ if (fp == NULL)
+ {
+ puts ("fdopen failed");
+ return 1;
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, fp) != 0)
+ {
+ puts ("pthread_create failed");
+ return 1;
+ }
+
+ sleep (1);
+
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("pthread_cancel failed");
+ return 1;
+ }
+
+ void *r;
+ if (pthread_join (th, &r) != 0)
+ {
+ puts ("pthread_join failed");
+ return 1;
+ }
+
+ return r != PTHREAD_CANCELED;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel7.c b/libc/nptl/tst-cancel7.c
new file mode 100644
index 000000000..be9b1c606
--- /dev/null
+++ b/libc/nptl/tst-cancel7.c
@@ -0,0 +1,211 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+const char *command;
+const char *pidfile;
+char pidfilename[] = "/tmp/tst-cancel7-XXXXXX";
+
+static void *
+tf (void *arg)
+{
+ const char *args = " --direct --pidfile ";
+ char *cmd = alloca (strlen (command) + strlen (args)
+ + strlen (pidfilename) + 1);
+
+ strcpy (stpcpy (stpcpy (cmd, command), args), pidfilename);
+ system (cmd);
+ /* This call should never return. */
+ return NULL;
+}
+
+
+static void
+sl (void)
+{
+ FILE *f = fopen (pidfile, "w");
+ if (f == NULL)
+ exit (1);
+
+ fprintf (f, "%lld\n", (long long) getpid ());
+ fflush (f);
+
+ struct flock fl =
+ {
+ .l_type = F_WRLCK,
+ .l_start = 0,
+ .l_whence = SEEK_SET,
+ .l_len = 1
+ };
+ if (fcntl (fileno (f), F_SETLK, &fl) != 0)
+ exit (1);
+
+ sigset_t ss;
+ sigfillset (&ss);
+ sigsuspend (&ss);
+ exit (0);
+}
+
+
+static void
+do_prepare (int argc, char *argv[])
+{
+ if (command == NULL)
+ command = argv[0];
+
+ if (pidfile)
+ sl ();
+
+ int fd = mkstemp (pidfilename);
+ if (fd == -1)
+ {
+ puts ("mkstemp failed");
+ exit (1);
+ }
+
+ write (fd, " ", 1);
+ close (fd);
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("pthread_create failed");
+ return 1;
+ }
+
+ do
+ sleep (1);
+ while (access (pidfilename, R_OK) != 0);
+
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("pthread_cancel failed");
+ return 1;
+ }
+
+ void *r;
+ if (pthread_join (th, &r) != 0)
+ {
+ puts ("pthread_join failed");
+ return 1;
+ }
+
+ sleep (1);
+
+ FILE *f = fopen (pidfilename, "r+");
+ if (f == NULL)
+ {
+ puts ("no pidfile");
+ return 1;
+ }
+
+ long long ll;
+ if (fscanf (f, "%lld\n", &ll) != 1)
+ {
+ puts ("could not read pid");
+ unlink (pidfilename);
+ return 1;
+ }
+
+ struct flock fl =
+ {
+ .l_type = F_WRLCK,
+ .l_start = 0,
+ .l_whence = SEEK_SET,
+ .l_len = 1
+ };
+ if (fcntl (fileno (f), F_GETLK, &fl) != 0)
+ {
+ puts ("F_GETLK failed");
+ unlink (pidfilename);
+ return 1;
+ }
+
+ if (fl.l_type != F_UNLCK)
+ {
+ printf ("child %lld still running\n", (long long) fl.l_pid);
+ if (fl.l_pid == ll)
+ kill (fl.l_pid, SIGKILL);
+
+ unlink (pidfilename);
+ return 1;
+ }
+
+ fclose (f);
+
+ unlink (pidfilename);
+
+ return r != PTHREAD_CANCELED;
+}
+
+static void
+do_cleanup (void)
+{
+ FILE *f = fopen (pidfilename, "r+");
+ long long ll;
+
+ if (f != NULL && fscanf (f, "%lld\n", &ll) == 1)
+ {
+ struct flock fl =
+ {
+ .l_type = F_WRLCK,
+ .l_start = 0,
+ .l_whence = SEEK_SET,
+ .l_len = 1
+ };
+ if (fcntl (fileno (f), F_GETLK, &fl) == 0 && fl.l_type != F_UNLCK
+ && fl.l_pid == ll)
+ kill (fl.l_pid, SIGKILL);
+
+ fclose (f);
+ }
+
+ unlink (pidfilename);
+}
+
+#define OPT_COMMAND 10000
+#define OPT_PIDFILE 10001
+#define CMDLINE_OPTIONS \
+ { "command", required_argument, NULL, OPT_COMMAND }, \
+ { "pidfile", required_argument, NULL, OPT_PIDFILE },
+#define CMDLINE_PROCESS \
+ case OPT_COMMAND: \
+ command = optarg; \
+ break; \
+ case OPT_PIDFILE: \
+ pidfile = optarg; \
+ break;
+// #define CLEANUP_HANDLER do_cleanup ()
+#define PREPARE(argc, argv) do_prepare (argc, argv)
+#define TEST_FUNCTION do_test ()
+#define TIMEOUT 5
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel8.c b/libc/nptl/tst-cancel8.c
new file mode 100644
index 000000000..fc836627d
--- /dev/null
+++ b/libc/nptl/tst-cancel8.c
@@ -0,0 +1,143 @@
+/* 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>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static pthread_barrier_t bar;
+
+static int global;
+
+
+static void
+cleanup (void *arg)
+{
+ global = 1;
+}
+
+
+static void *
+tf (void *arg)
+{
+ /* Enable cancellation, but defer it. */
+ if (pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL) != 0)
+ {
+ puts ("setcancelstate failed");
+ exit (1);
+ }
+ if (pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, NULL) != 0)
+ {
+ puts ("setcanceltype failed");
+ exit (1);
+ }
+
+ /* Add cleanup handler. */
+ pthread_cleanup_push (cleanup, NULL);
+
+ /* Synchronize with the main thread. */
+ int r = pthread_barrier_wait (&bar);
+ if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("tf: first barrier_wait failed");
+ exit (1);
+ }
+
+ /* And again. Once this is done the main thread should have canceled
+ this thread. */
+ r = pthread_barrier_wait (&bar);
+ if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("tf: second barrier_wait failed");
+ exit (1);
+ }
+
+ /* Remove the cleanup handler without executing it. */
+ pthread_cleanup_pop (0);
+
+ /* Now react on the cancellation. */
+ pthread_testcancel ();
+
+ /* This call should never return. */
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ if (pthread_barrier_init (&bar, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("pthread_create failed");
+ return 1;
+ }
+
+ int r = pthread_barrier_wait (&bar);
+ if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("first barrier_wait failed");
+ exit (1);
+ }
+
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("pthread_cancel failed");
+ return 1;
+ }
+
+ r = pthread_barrier_wait (&bar);
+ if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("second barrier_wait failed");
+ exit (1);
+ }
+
+ void *result;
+ if (pthread_join (th, &result) != 0)
+ {
+ puts ("pthread_join failed");
+ return 1;
+ }
+
+ if (result != PTHREAD_CANCELED)
+ {
+ puts ("thread was not canceled");
+ exit (1);
+ }
+
+ if (global != 0)
+ {
+ puts ("cancellation handler has been called");
+ exit (1);
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancel9.c b/libc/nptl/tst-cancel9.c
new file mode 100644
index 000000000..037ef30fd
--- /dev/null
+++ b/libc/nptl/tst-cancel9.c
@@ -0,0 +1,126 @@
+/* Copyright (C) 2003, 2004 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 <fcntl.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+
+static pthread_barrier_t b;
+
+
+static void
+cleanup (void *arg)
+{
+ fputs ("in cleanup\n", stdout);
+}
+
+
+static void *
+tf (void *arg)
+{
+ int fd = open ("/dev/null", O_RDWR);
+ if (fd == -1)
+ {
+ puts ("cannot open /dev/null");
+ exit (1);
+ }
+ FILE *fp = fdopen (fd, "w");
+ if (fp == NULL)
+ {
+ puts ("fdopen failed");
+ exit (1);
+ }
+
+ pthread_cleanup_push (cleanup, NULL);
+
+ int e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ while (1)
+ /* fprintf() uses write() which is a cancallation point. */
+ fprintf (fp, "foo");
+
+ pthread_cleanup_pop (0);
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ return 1;
+ }
+
+ int e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ sleep (1);
+
+ puts ("cancel now");
+
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("cancel failed");
+ exit (1);
+ }
+
+ puts ("waiting for the child");
+
+ void *r;
+ if (pthread_join (th, &r) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ if (r != PTHREAD_CANCELED)
+ {
+ puts ("thread wasn't canceled");
+ exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cancelx1.c b/libc/nptl/tst-cancelx1.c
new file mode 100644
index 000000000..594f09559
--- /dev/null
+++ b/libc/nptl/tst-cancelx1.c
@@ -0,0 +1 @@
+#include "tst-cancel1.c"
diff --git a/libc/nptl/tst-cancelx10.c b/libc/nptl/tst-cancelx10.c
new file mode 100644
index 000000000..e5bbb34e6
--- /dev/null
+++ b/libc/nptl/tst-cancelx10.c
@@ -0,0 +1 @@
+#include "tst-cancel10.c"
diff --git a/libc/nptl/tst-cancelx11.c b/libc/nptl/tst-cancelx11.c
new file mode 100644
index 000000000..ffcc2eefc
--- /dev/null
+++ b/libc/nptl/tst-cancelx11.c
@@ -0,0 +1 @@
+#include "tst-cancel11.c"
diff --git a/libc/nptl/tst-cancelx12.c b/libc/nptl/tst-cancelx12.c
new file mode 100644
index 000000000..f90ae61ba
--- /dev/null
+++ b/libc/nptl/tst-cancelx12.c
@@ -0,0 +1 @@
+#include "tst-cancel12.c"
diff --git a/libc/nptl/tst-cancelx13.c b/libc/nptl/tst-cancelx13.c
new file mode 100644
index 000000000..37c4c39c3
--- /dev/null
+++ b/libc/nptl/tst-cancelx13.c
@@ -0,0 +1 @@
+#include "tst-cancel13.c"
diff --git a/libc/nptl/tst-cancelx14.c b/libc/nptl/tst-cancelx14.c
new file mode 100644
index 000000000..ba4e77584
--- /dev/null
+++ b/libc/nptl/tst-cancelx14.c
@@ -0,0 +1 @@
+#include "tst-cancel14.c"
diff --git a/libc/nptl/tst-cancelx15.c b/libc/nptl/tst-cancelx15.c
new file mode 100644
index 000000000..005c1f6e3
--- /dev/null
+++ b/libc/nptl/tst-cancelx15.c
@@ -0,0 +1 @@
+#include "tst-cancel15.c"
diff --git a/libc/nptl/tst-cancelx16.c b/libc/nptl/tst-cancelx16.c
new file mode 100644
index 000000000..99af3b197
--- /dev/null
+++ b/libc/nptl/tst-cancelx16.c
@@ -0,0 +1 @@
+#include "tst-cancel16.c"
diff --git a/libc/nptl/tst-cancelx17.c b/libc/nptl/tst-cancelx17.c
new file mode 100644
index 000000000..c6c833b60
--- /dev/null
+++ b/libc/nptl/tst-cancelx17.c
@@ -0,0 +1 @@
+#include "tst-cancel17.c"
diff --git a/libc/nptl/tst-cancelx18.c b/libc/nptl/tst-cancelx18.c
new file mode 100644
index 000000000..56da18f38
--- /dev/null
+++ b/libc/nptl/tst-cancelx18.c
@@ -0,0 +1 @@
+#include "tst-cancel18.c"
diff --git a/libc/nptl/tst-cancelx2.c b/libc/nptl/tst-cancelx2.c
new file mode 100644
index 000000000..95dc8a857
--- /dev/null
+++ b/libc/nptl/tst-cancelx2.c
@@ -0,0 +1 @@
+#include "tst-cancel2.c"
diff --git a/libc/nptl/tst-cancelx20.c b/libc/nptl/tst-cancelx20.c
new file mode 100644
index 000000000..6bd86376c
--- /dev/null
+++ b/libc/nptl/tst-cancelx20.c
@@ -0,0 +1 @@
+#include "tst-cancel20.c"
diff --git a/libc/nptl/tst-cancelx21.c b/libc/nptl/tst-cancelx21.c
new file mode 100644
index 000000000..2a01061ea
--- /dev/null
+++ b/libc/nptl/tst-cancelx21.c
@@ -0,0 +1 @@
+#include "tst-cancel21.c"
diff --git a/libc/nptl/tst-cancelx3.c b/libc/nptl/tst-cancelx3.c
new file mode 100644
index 000000000..3937f10b9
--- /dev/null
+++ b/libc/nptl/tst-cancelx3.c
@@ -0,0 +1 @@
+#include "tst-cancel3.c"
diff --git a/libc/nptl/tst-cancelx4.c b/libc/nptl/tst-cancelx4.c
new file mode 100644
index 000000000..1c879eba8
--- /dev/null
+++ b/libc/nptl/tst-cancelx4.c
@@ -0,0 +1 @@
+#include "tst-cancel4.c"
diff --git a/libc/nptl/tst-cancelx5.c b/libc/nptl/tst-cancelx5.c
new file mode 100644
index 000000000..c0a18840a
--- /dev/null
+++ b/libc/nptl/tst-cancelx5.c
@@ -0,0 +1 @@
+#include "tst-cancel5.c"
diff --git a/libc/nptl/tst-cancelx6.c b/libc/nptl/tst-cancelx6.c
new file mode 100644
index 000000000..6926e21c2
--- /dev/null
+++ b/libc/nptl/tst-cancelx6.c
@@ -0,0 +1 @@
+#include "tst-cancel6.c"
diff --git a/libc/nptl/tst-cancelx7.c b/libc/nptl/tst-cancelx7.c
new file mode 100644
index 000000000..4df1a5881
--- /dev/null
+++ b/libc/nptl/tst-cancelx7.c
@@ -0,0 +1 @@
+#include "tst-cancel7.c"
diff --git a/libc/nptl/tst-cancelx8.c b/libc/nptl/tst-cancelx8.c
new file mode 100644
index 000000000..0555c7ceb
--- /dev/null
+++ b/libc/nptl/tst-cancelx8.c
@@ -0,0 +1 @@
+#include "tst-cancel8.c"
diff --git a/libc/nptl/tst-cancelx9.c b/libc/nptl/tst-cancelx9.c
new file mode 100644
index 000000000..9d84663d7
--- /dev/null
+++ b/libc/nptl/tst-cancelx9.c
@@ -0,0 +1 @@
+#include "tst-cancel9.c"
diff --git a/libc/nptl/tst-cleanup0.c b/libc/nptl/tst-cleanup0.c
new file mode 100644
index 000000000..a73dee3df
--- /dev/null
+++ b/libc/nptl/tst-cleanup0.c
@@ -0,0 +1,76 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static int global;
+
+
+static void
+ch (void *arg)
+{
+ int val = (long int) arg;
+
+ printf ("ch (%d)\n", val);
+
+ global *= val;
+ global += val;
+}
+
+
+static void
+endfct (void)
+{
+ /* We force exit right here. */
+ _exit (global);
+}
+
+
+static int
+do_test (void)
+{
+ atexit (endfct);
+
+ pthread_cancel (pthread_self ());
+
+ pthread_cleanup_push (ch, (void *) 1l);
+
+ pthread_cleanup_push (ch, (void *) 2l);
+
+ pthread_cleanup_push (ch, (void *) 3l);
+
+ pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+
+ pthread_cleanup_pop (1);
+
+ pthread_cleanup_pop (1);
+
+ pthread_cleanup_pop (1);
+
+ return 100;
+}
+
+
+#define EXPECTED_STATUS 9
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cleanup0.expect b/libc/nptl/tst-cleanup0.expect
new file mode 100644
index 000000000..4e3c58180
--- /dev/null
+++ b/libc/nptl/tst-cleanup0.expect
@@ -0,0 +1,3 @@
+ch (3)
+ch (2)
+ch (1)
diff --git a/libc/nptl/tst-cleanup1.c b/libc/nptl/tst-cleanup1.c
new file mode 100644
index 000000000..2230e0fbe
--- /dev/null
+++ b/libc/nptl/tst-cleanup1.c
@@ -0,0 +1,100 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static int global;
+
+
+static void
+ch (void *arg)
+{
+ int val = (long int) arg;
+
+ printf ("ch (%d)\n", val);
+
+ global *= val;
+ global += val;
+}
+
+
+static void *
+tf (void *a)
+{
+ pthread_cancel (pthread_self ());
+
+ pthread_cleanup_push (ch, (void *) 1l);
+
+ pthread_cleanup_push (ch, (void *) 2l);
+
+ pthread_cleanup_push (ch, (void *) 3l);
+
+ pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+
+ pthread_cleanup_pop (1);
+
+ pthread_cleanup_pop (1);
+
+ pthread_cleanup_pop (1);
+
+ return NULL;
+}
+
+
+int
+do_test (void)
+{
+ pthread_t th;
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ write (2, "create failed\n", 14);
+ _exit (1);
+ }
+
+ void *r;
+ int e;
+ if ((e = pthread_join (th, &r)) != 0)
+ {
+ printf ("join failed: %d\n", e);
+ _exit (1);
+ }
+
+ if (r != PTHREAD_CANCELED)
+ {
+ puts ("thread not canceled");
+ exit (1);
+ }
+
+ if (global != 9)
+ {
+ printf ("global = %d, expected 9\n", global);
+ exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cleanup2.c b/libc/nptl/tst-cleanup2.c
new file mode 100644
index 000000000..30e10b120
--- /dev/null
+++ b/libc/nptl/tst-cleanup2.c
@@ -0,0 +1,63 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Bao Duong <bduong@progress.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 <setjmp.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+
+static sigjmp_buf jmpbuf;
+
+static void
+sig_handler (int signo)
+{
+ siglongjmp (jmpbuf, 1);
+}
+
+static int
+do_test (void)
+{
+ char *p = NULL;
+ struct sigaction sa;
+
+ sa.sa_handler = sig_handler;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = SA_SIGINFO;
+
+ if (sigaction (SIGSEGV, &sa, 0))
+ {
+ perror ("installing SIGSEGV handler\n");
+ exit (1);
+ }
+
+ puts ("Attempting to sprintf to null ptr");
+ if (setjmp (jmpbuf))
+ {
+ puts ("Exiting main...");
+ return 0;
+ }
+
+ sprintf (p, "This should segv\n");
+
+ return 1;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cleanup3.c b/libc/nptl/tst-cleanup3.c
new file mode 100644
index 000000000..c44277370
--- /dev/null
+++ b/libc/nptl/tst-cleanup3.c
@@ -0,0 +1,98 @@
+/* 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>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static int global;
+
+
+static void
+ch (void *arg)
+{
+ int val = (long int) arg;
+
+ printf ("ch (%d)\n", val);
+
+ global *= val;
+ global += val;
+}
+
+
+static void *
+tf (void *a)
+{
+ pthread_cleanup_push (ch, (void *) 1l);
+
+ pthread_cleanup_push (ch, (void *) 2l);
+
+ pthread_cleanup_push (ch, (void *) 3l);
+
+ pthread_exit ((void *) 1l);
+
+ pthread_cleanup_pop (1);
+
+ pthread_cleanup_pop (1);
+
+ pthread_cleanup_pop (1);
+
+ return NULL;
+}
+
+
+int
+do_test (void)
+{
+ pthread_t th;
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ write (2, "create failed\n", 14);
+ _exit (1);
+ }
+
+ void *r;
+ int e;
+ if ((e = pthread_join (th, &r)) != 0)
+ {
+ printf ("join failed: %d\n", e);
+ _exit (1);
+ }
+
+ if (r != (void *) 1l)
+ {
+ puts ("thread not canceled");
+ exit (1);
+ }
+
+ if (global != 9)
+ {
+ printf ("global = %d, expected 9\n", global);
+ exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cleanup4.c b/libc/nptl/tst-cleanup4.c
new file mode 100644
index 000000000..1489fd31b
--- /dev/null
+++ b/libc/nptl/tst-cleanup4.c
@@ -0,0 +1,198 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+/* LinuxThreads pthread_cleanup_{push,pop} helpers. */
+extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer *__buffer,
+ void (*__routine) (void *),
+ void *__arg);
+extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *__buffer,
+ int __execute);
+
+static int fds[2];
+static pthread_barrier_t b2;
+static int global;
+
+/* Defined in tst-cleanup4aux.c, never compiled with -fexceptions. */
+extern void fn5 (void);
+extern void fn7 (void);
+extern void fn9 (void);
+
+void
+clh (void *arg)
+{
+ int val = (long int) arg;
+
+ printf ("clh (%d)\n", val);
+
+ global *= val;
+ global += val;
+}
+
+
+static __attribute__((noinline)) void
+fn_read (void)
+{
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ char c;
+ read (fds[0], &c, 1);
+}
+
+
+__attribute__((noinline)) void
+fn0 (void)
+{
+ pthread_cleanup_push (clh, (void *) 1l);
+
+ fn_read ();
+
+ pthread_cleanup_pop (1);
+}
+
+
+__attribute__((noinline)) void
+fn1 (void)
+{
+ /* This is the old LinuxThreads pthread_cleanup_{push,pop}. */
+ struct _pthread_cleanup_buffer b;
+ _pthread_cleanup_push (&b, clh, (void *) 2l);
+
+ fn0 ();
+
+ _pthread_cleanup_pop (&b, 1);
+}
+
+
+static __attribute__((noinline)) void
+fn2 (void)
+{
+ pthread_cleanup_push (clh, (void *) 3l);
+
+ fn1 ();
+
+ pthread_cleanup_pop (1);
+}
+
+
+static void *
+tf (void *a)
+{
+ switch ((long) a)
+ {
+ case 0:
+ fn2 ();
+ break;
+ case 1:
+ fn5 ();
+ break;
+ case 2:
+ fn7 ();
+ break;
+ case 3:
+ fn9 ();
+ break;
+ }
+
+ return NULL;
+}
+
+
+int
+do_test (void)
+{
+ int result = 0;
+
+ if (pipe (fds) != 0)
+ {
+ puts ("pipe failed");
+ exit (1);
+ }
+
+ if (pthread_barrier_init (&b2, NULL, 2) != 0)
+ {
+ puts ("b2 init failed");
+ exit (1);
+ }
+
+ const int expect[] =
+ {
+ 15, /* 1 2 3 */
+ 276, /* 1 4 5 6 */
+ 120, /* 1 7 8 */
+ 460 /* 1 2 9 10 */
+ };
+
+ long i;
+ for (i = 0; i < 4; ++i)
+ {
+ global = 0;
+
+ printf ("test %ld\n", i);
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, (void *) i) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ int e = pthread_barrier_wait (&b2);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ pthread_cancel (th);
+
+ void *r;
+ if ((e = pthread_join (th, &r)) != 0)
+ {
+ printf ("join failed: %d\n", e);
+ _exit (1);
+ }
+
+ if (r != PTHREAD_CANCELED)
+ {
+ puts ("thread not canceled");
+ exit (1);
+ }
+
+ if (global != expect[i])
+ {
+ printf ("global = %d, expected %d\n", global, expect[i]);
+ result = 1;
+ }
+ }
+
+ return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cleanup4aux.c b/libc/nptl/tst-cleanup4aux.c
new file mode 100644
index 000000000..cd1a89ac1
--- /dev/null
+++ b/libc/nptl/tst-cleanup4aux.c
@@ -0,0 +1,121 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer *__buffer,
+ void (*__routine) (void *),
+ void *__arg);
+extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *__buffer,
+ int __execute);
+
+extern void clh (void *arg);
+extern void fn0 (void);
+extern void fn1 (void);
+extern void fn5 (void);
+extern void fn7 (void);
+extern void fn9 (void);
+
+
+static __attribute__((noinline)) void
+fn3 (void)
+{
+ /* This is the old LinuxThreads pthread_cleanup_{push,pop}. */
+ struct _pthread_cleanup_buffer b;
+ _pthread_cleanup_push (&b, clh, (void *) 4l);
+
+ fn0 ();
+
+ _pthread_cleanup_pop (&b, 1);
+}
+
+
+static __attribute__((noinline)) void
+fn4 (void)
+{
+ pthread_cleanup_push (clh, (void *) 5l);
+
+ fn3 ();
+
+ pthread_cleanup_pop (1);
+}
+
+
+void
+fn5 (void)
+{
+ /* This is the old LinuxThreads pthread_cleanup_{push,pop}. */
+ struct _pthread_cleanup_buffer b;
+ _pthread_cleanup_push (&b, clh, (void *) 6l);
+
+ fn4 ();
+
+ _pthread_cleanup_pop (&b, 1);
+}
+
+
+static __attribute__((noinline)) void
+fn6 (void)
+{
+ pthread_cleanup_push (clh, (void *) 7l);
+
+ fn0 ();
+
+ pthread_cleanup_pop (1);
+}
+
+
+void
+fn7 (void)
+{
+ /* This is the old LinuxThreads pthread_cleanup_{push,pop}. */
+ struct _pthread_cleanup_buffer b;
+ _pthread_cleanup_push (&b, clh, (void *) 8l);
+
+ fn6 ();
+
+ _pthread_cleanup_pop (&b, 1);
+}
+
+
+static __attribute__((noinline)) void
+fn8 (void)
+{
+ pthread_cleanup_push (clh, (void *) 9l);
+
+ fn1 ();
+
+ pthread_cleanup_pop (1);
+}
+
+
+void
+fn9 (void)
+{
+ /* This is the old LinuxThreads pthread_cleanup_{push,pop}. */
+ struct _pthread_cleanup_buffer b;
+ _pthread_cleanup_push (&b, clh, (void *) 10l);
+
+ fn8 ();
+
+ _pthread_cleanup_pop (&b, 1);
+}
diff --git a/libc/nptl/tst-cleanupx0.c b/libc/nptl/tst-cleanupx0.c
new file mode 100644
index 000000000..0012ab1b2
--- /dev/null
+++ b/libc/nptl/tst-cleanupx0.c
@@ -0,0 +1 @@
+#include "tst-cleanup0.c"
diff --git a/libc/nptl/tst-cleanupx0.expect b/libc/nptl/tst-cleanupx0.expect
new file mode 100644
index 000000000..4e3c58180
--- /dev/null
+++ b/libc/nptl/tst-cleanupx0.expect
@@ -0,0 +1,3 @@
+ch (3)
+ch (2)
+ch (1)
diff --git a/libc/nptl/tst-cleanupx1.c b/libc/nptl/tst-cleanupx1.c
new file mode 100644
index 000000000..21e9e58bd
--- /dev/null
+++ b/libc/nptl/tst-cleanupx1.c
@@ -0,0 +1 @@
+#include "tst-cleanup1.c"
diff --git a/libc/nptl/tst-cleanupx2.c b/libc/nptl/tst-cleanupx2.c
new file mode 100644
index 000000000..8b9e35093
--- /dev/null
+++ b/libc/nptl/tst-cleanupx2.c
@@ -0,0 +1 @@
+#include "tst-cleanup2.c"
diff --git a/libc/nptl/tst-cleanupx3.c b/libc/nptl/tst-cleanupx3.c
new file mode 100644
index 000000000..90baf904f
--- /dev/null
+++ b/libc/nptl/tst-cleanupx3.c
@@ -0,0 +1 @@
+#include "tst-cleanup3.c"
diff --git a/libc/nptl/tst-cleanupx4.c b/libc/nptl/tst-cleanupx4.c
new file mode 100644
index 000000000..8dea954b5
--- /dev/null
+++ b/libc/nptl/tst-cleanupx4.c
@@ -0,0 +1 @@
+#include "tst-cleanup4.c"
diff --git a/libc/nptl/tst-clock1.c b/libc/nptl/tst-clock1.c
new file mode 100644
index 000000000..0848d7701
--- /dev/null
+++ b/libc/nptl/tst-clock1.c
@@ -0,0 +1,51 @@
+/* Copyright (C) 2003, 2004 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>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+
+
+int
+do_test (void)
+{
+#if defined _POSIX_THREAD_CPUTIME && _POSIX_THREAD_CPUTIME >= 0
+ clockid_t cl;
+ /* This is really only a linking-test here. */
+ int e = pthread_getcpuclockid (pthread_self (), &cl);
+ if (e != 0)
+ {
+# if _POSIX_THREAD_CPUTIME == 0
+ if (sysconf (_SC_THREAD_CPUTIME) >= 0)
+# endif
+ {
+ puts ("cpuclock advertized, but cannot get ID");
+ exit (1);
+ }
+ }
+#endif
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-clock2.c b/libc/nptl/tst-clock2.c
new file mode 100644
index 000000000..bca40956e
--- /dev/null
+++ b/libc/nptl/tst-clock2.c
@@ -0,0 +1,202 @@
+/* Copyright (C) 2003, 2004 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+
+
+#if defined _POSIX_THREAD_CPUTIME && _POSIX_THREAD_CPUTIME >= 0
+static pthread_barrier_t b2;
+static pthread_barrier_t bN;
+
+
+static void *
+tf (void *arg)
+{
+ int e = pthread_barrier_wait (&b2);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ e = pthread_barrier_wait (&bN);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ return NULL;
+}
+#endif
+
+
+int
+do_test (void)
+{
+#if defined _POSIX_THREAD_CPUTIME && _POSIX_THREAD_CPUTIME >= 0
+# define N 10
+
+# if _POSIX_THREAD_CPUTIME == 0
+ if (sysconf (_SC_THREAD_CPUTIME) < 0)
+ {
+ puts ("_POSIX_THREAD_CPUTIME option not available");
+ return 0;
+ }
+# endif
+
+ if (pthread_barrier_init (&b2, NULL, 2) != 0
+ || pthread_barrier_init (&bN, NULL, N + 1) != 0)
+ {
+ puts ("barrier_init failed");
+ return 1;
+ }
+
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
+ TEMP_FAILURE_RETRY (nanosleep (&ts, &ts));
+
+ pthread_t th[N + 1];
+ clockid_t cl[N + 1];
+# ifndef CLOCK_THREAD_CPUTIME_ID
+ if (pthread_getcpuclockid (pthread_self (), &cl[0]) != 0)
+ {
+ puts ("own pthread_getcpuclockid failed");
+ return 1;
+ }
+# else
+ cl[0] = CLOCK_THREAD_CPUTIME_ID;
+# endif
+
+ pthread_attr_t at;
+
+ if (pthread_attr_init (&at) != 0)
+ {
+ puts ("attr_init failed");
+ return 1;
+ }
+
+ if (pthread_attr_setstacksize (&at, 1 * 1024 * 1024) != 0)
+ {
+ puts ("attr_setstacksize failed");
+ return 1;
+ }
+
+ int i;
+ int e;
+ for (i = 0; i < N; ++i)
+ {
+ if (pthread_create (&th[i], &at, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ return 1;
+ }
+
+ e = pthread_barrier_wait (&b2);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ return 1;
+ }
+
+ ts.tv_sec = 0;
+ ts.tv_nsec = 100000000;
+ TEMP_FAILURE_RETRY (nanosleep (&ts, &ts));
+
+ if (pthread_getcpuclockid (th[i], &cl[i + 1]) != 0)
+ {
+ puts ("pthread_getcpuclockid failed");
+ return 1;
+ }
+ }
+
+ if (pthread_attr_destroy (&at) != 0)
+ {
+ puts ("attr_destroy failed");
+ return 1;
+ }
+
+ struct timespec t[N + 1];
+ for (i = 0; i < N + 1; ++i)
+ if (clock_gettime (cl[i], &t[i]) != 0)
+ {
+ printf ("clock_gettime round %d failed\n", i);
+ return 1;
+ }
+
+ for (i = 0; i < N; ++i)
+ {
+ struct timespec diff;
+
+ diff.tv_sec = t[i].tv_sec - t[i + 1].tv_sec;
+ diff.tv_nsec = t[i].tv_nsec - t[i + 1].tv_nsec;
+ if (diff.tv_nsec < 0)
+ {
+ diff.tv_nsec += 1000000000;
+ --diff.tv_sec;
+ }
+
+ if (diff.tv_sec < 0 || (diff.tv_sec == 0 && diff.tv_nsec < 100000000))
+ {
+ printf ("\
+difference between thread %d and %d too small (%ld.%09ld)\n",
+ i, i + 1, (long int) diff.tv_sec, (long int) diff.tv_nsec);
+ return 1;
+ }
+
+ printf ("diff %d->%d: %ld.%09ld\n",
+ i, i + 1, (long int) diff.tv_sec, (long int) diff.tv_nsec);
+ }
+
+ ts.tv_sec = 0;
+ ts.tv_nsec = 0;
+ for (i = 0; i < N + 1; ++i)
+ if (clock_settime (cl[i], &ts) != 0)
+ {
+ printf ("clock_settime(%d) round %d failed\n", cl[i], i);
+ return 1;
+ }
+
+ for (i = 0; i < N + 1; ++i)
+ {
+ if (clock_gettime (cl[i], &ts) != 0)
+ {
+ puts ("clock_gettime failed");
+ return 1;
+ }
+
+ if (ts.tv_sec > t[i].tv_sec
+ || (ts.tv_sec == t[i].tv_sec && ts.tv_nsec > t[i].tv_nsec))
+ {
+ puts ("clock_settime didn't reset clock");
+ return 1;
+ }
+ }
+#endif
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cond1.c b/libc/nptl/tst-cond1.c
new file mode 100644
index 000000000..46085c2b7
--- /dev/null
+++ b/libc/nptl/tst-cond1.c
@@ -0,0 +1,94 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <error.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
+
+
+static void *
+tf (void *p)
+{
+ int err;
+
+ err = pthread_mutex_lock (&mut);
+ if (err != 0)
+ error (EXIT_FAILURE, err, "child: cannot get mutex");
+
+ puts ("child: got mutex; signalling");
+
+ pthread_cond_signal (&cond);
+
+ puts ("child: unlock");
+
+ err = pthread_mutex_unlock (&mut);
+ if (err != 0)
+ error (EXIT_FAILURE, err, "child: cannot unlock");
+
+ puts ("child: done");
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t th;
+ int err;
+
+ printf ("&cond = %p\n&mut = %p\n", &cond, &mut);
+
+ puts ("parent: get mutex");
+
+ err = pthread_mutex_lock (&mut);
+ if (err != 0)
+ error (EXIT_FAILURE, err, "parent: cannot get mutex");
+
+ puts ("parent: create child");
+
+ err = pthread_create (&th, NULL, tf, NULL);
+ if (err != 0)
+ error (EXIT_FAILURE, err, "parent: cannot create thread");
+
+ puts ("parent: wait for condition");
+
+ err = pthread_cond_wait (&cond, &mut);
+ if (err != 0)
+ error (EXIT_FAILURE, err, "parent: cannot wait fir signal");
+
+ puts ("parent: got signal");
+
+ err = pthread_join (th, NULL);
+ if (err != 0)
+ error (EXIT_FAILURE, err, "parent: failed to join");
+
+ puts ("done");
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cond10.c b/libc/nptl/tst-cond10.c
new file mode 100644
index 000000000..34956d468
--- /dev/null
+++ b/libc/nptl/tst-cond10.c
@@ -0,0 +1,173 @@
+/* Copyright (C) 2003, 2004 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 <error.h>
+#include <pthread.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+#define N 10
+#define ROUNDS 100
+
+static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
+static pthread_barrier_t bN1;
+static pthread_barrier_t b2;
+
+
+static void *
+tf (void *p)
+{
+ if (pthread_mutex_lock (&mut) != 0)
+ {
+ puts ("child: 1st mutex_lock failed");
+ exit (1);
+ }
+
+ int e = pthread_barrier_wait (&b2);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("child: 1st barrier_wait failed");
+ exit (1);
+ }
+
+ if (pthread_cond_wait (&cond, &mut) != 0)
+ {
+ puts ("child: cond_wait failed");
+ exit (1);
+ }
+
+ if (pthread_mutex_unlock (&mut) != 0)
+ {
+ puts ("child: mutex_unlock failed");
+ exit (1);
+ }
+
+ e = pthread_barrier_wait (&bN1);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("child: 2nd barrier_wait failed");
+ exit (1);
+ }
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ if (pthread_barrier_init (&bN1, NULL, N + 1) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ if (pthread_barrier_init (&b2, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ pthread_attr_t at;
+
+ if (pthread_attr_init (&at) != 0)
+ {
+ puts ("attr_init failed");
+ return 1;
+ }
+
+ if (pthread_attr_setstacksize (&at, 1 * 1024 * 1024) != 0)
+ {
+ puts ("attr_setstacksize failed");
+ return 1;
+ }
+
+ int r;
+ for (r = 0; r < ROUNDS; ++r)
+ {
+ printf ("round %d\n", r + 1);
+
+ int i;
+ pthread_t th[N];
+ for (i = 0; i < N; ++i)
+ {
+ if (pthread_create (&th[i], &at, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ int e = pthread_barrier_wait (&b2);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("parent: 1st barrier_wait failed");
+ exit (1);
+ }
+ }
+
+ if (pthread_mutex_lock (&mut) != 0)
+ {
+ puts ("parent: mutex_lock failed");
+ exit (1);
+ }
+ if (pthread_mutex_unlock (&mut) != 0)
+ {
+ puts ("parent: mutex_unlock failed");
+ exit (1);
+ }
+
+ /* N single signal calls. Without locking. This tests that no
+ signal gets lost. */
+ for (i = 0; i < N; ++i)
+ if (pthread_cond_signal (&cond) != 0)
+ {
+ puts ("cond_signal failed");
+ exit (1);
+ }
+
+ int e = pthread_barrier_wait (&bN1);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("parent: 2nd barrier_wait failed");
+ exit (1);
+ }
+
+ for (i = 0; i < N; ++i)
+ if (pthread_join (th[i], NULL) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+ }
+
+ if (pthread_attr_destroy (&at) != 0)
+ {
+ puts ("attr_destroy failed");
+ return 1;
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cond11.c b/libc/nptl/tst-cond11.c
new file mode 100644
index 000000000..0de4d5613
--- /dev/null
+++ b/libc/nptl/tst-cond11.c
@@ -0,0 +1,191 @@
+/* Copyright (C) 2003, 2004 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <time.h>
+#include <unistd.h>
+
+
+#if defined _POSIX_CLOCK_SELECTION && _POSIX_CLOCK_SELECTION >= 0
+static int
+run_test (clockid_t cl)
+{
+ pthread_condattr_t condattr;
+ pthread_cond_t cond;
+ pthread_mutexattr_t mutattr;
+ pthread_mutex_t mut;
+
+ printf ("clock = %d\n", (int) cl);
+
+ if (pthread_condattr_init (&condattr) != 0)
+ {
+ puts ("condattr_init failed");
+ return 1;
+ }
+
+ if (pthread_condattr_setclock (&condattr, cl) != 0)
+ {
+ puts ("condattr_setclock failed");
+ return 1;
+ }
+
+ clockid_t cl2;
+ if (pthread_condattr_getclock (&condattr, &cl2) != 0)
+ {
+ puts ("condattr_getclock failed");
+ return 1;
+ }
+ if (cl != cl2)
+ {
+ printf ("condattr_getclock returned wrong value: %d, expected %d\n",
+ (int) cl2, (int) cl);
+ return 1;
+ }
+
+ if (pthread_cond_init (&cond, &condattr) != 0)
+ {
+ puts ("cond_init failed");
+ return 1;
+ }
+
+ if (pthread_condattr_destroy (&condattr) != 0)
+ {
+ puts ("condattr_destroy failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_init (&mutattr) != 0)
+ {
+ puts ("mutexattr_init failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_settype (&mutattr, PTHREAD_MUTEX_ERRORCHECK) != 0)
+ {
+ puts ("mutexattr_settype failed");
+ return 1;
+ }
+
+ if (pthread_mutex_init (&mut, &mutattr) != 0)
+ {
+ puts ("mutex_init failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_destroy (&mutattr) != 0)
+ {
+ puts ("mutexattr_destroy failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (&mut) != 0)
+ {
+ puts ("mutex_lock failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (&mut) != EDEADLK)
+ {
+ puts ("2nd mutex_lock did not return EDEADLK");
+ return 1;
+ }
+
+ struct timespec ts;
+ if (clock_gettime (cl, &ts) != 0)
+ {
+ puts ("clock_gettime failed");
+ return 1;
+ }
+
+ /* Wait one second. */
+ ++ts.tv_sec;
+
+ int e = pthread_cond_timedwait (&cond, &mut, &ts);
+ if (e == 0)
+ {
+ puts ("cond_timedwait succeeded");
+ return 1;
+ }
+ else if (e != ETIMEDOUT)
+ {
+ puts ("cond_timedwait did not return ETIMEDOUT");
+ return 1;
+ }
+
+ if (pthread_mutex_unlock (&mut) != 0)
+ {
+ puts ("mutex_unlock failed");
+ return 1;
+ }
+
+ if (pthread_mutex_destroy (&mut) != 0)
+ {
+ puts ("mutex_destroy failed");
+ return 1;
+ }
+
+ if (pthread_cond_destroy (&cond) != 0)
+ {
+ puts ("cond_destroy failed");
+ return 1;
+ }
+
+ return 0;
+}
+#endif
+
+
+static int
+do_test (void)
+{
+#if !defined _POSIX_CLOCK_SELECTION || _POSIX_CLOCK_SELECTION == -1
+
+ puts ("_POSIX_CLOCK_SELECTION not supported, test skipped");
+ return 0;
+
+#else
+
+ int res = run_test (CLOCK_REALTIME);
+
+# if defined _POSIX_MONOTONIC_CLOCK && _POSIX_MONOTONIC_CLOCK >= 0
+# if _POSIX_MONOTONIC_CLOCK == 0
+ int e = sysconf (_SC_MONOTONIC_CLOCK);
+ if (e < 0)
+ puts ("CLOCK_MONOTONIC not supported");
+ else if (e == 0)
+ {
+ puts ("sysconf (_SC_MONOTONIC_CLOCK) must not return 0");
+ res = 1;
+ }
+ else
+# endif
+ res |= run_test (CLOCK_MONOTONIC);
+# else
+ puts ("_POSIX_MONOTONIC_CLOCK not defined");
+# endif
+
+ return res;
+#endif
+}
+
+#define TIMEOUT 3
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cond12.c b/libc/nptl/tst-cond12.c
new file mode 100644
index 000000000..03e4881c9
--- /dev/null
+++ b/libc/nptl/tst-cond12.c
@@ -0,0 +1,196 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+
+
+static char fname[] = "/tmp/tst-cond12-XXXXXX";
+static int fd;
+
+
+static void prepare (void);
+#define PREPARE(argc, argv) prepare ()
+
+static int do_test (void);
+#define TEST_FUNCTION do_test ()
+
+#include "../test-skeleton.c"
+
+
+static void
+prepare (void)
+{
+ fd = mkstemp (fname);
+ if (fd == -1)
+ {
+ printf ("mkstemp failed: %m\n");
+ exit (1);
+ }
+ add_temp_file (fname);
+ if (ftruncate (fd, 1000) < 0)
+ {
+ printf ("ftruncate failed: %m\n");
+ exit (1);
+ }
+}
+
+
+static int
+do_test (void)
+{
+ struct
+ {
+ pthread_mutex_t m;
+ pthread_cond_t c;
+ int var;
+ } *p = mmap (NULL, sizeof (*p), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+ if (p == MAP_FAILED)
+ {
+ printf ("initial mmap failed: %m\n");
+ return 1;
+ }
+
+ pthread_mutexattr_t ma;
+ if (pthread_mutexattr_init (&ma) != 0)
+ {
+ puts ("mutexattr_init failed");
+ return 1;
+ }
+ if (pthread_mutexattr_setpshared (&ma, 1) != 0)
+ {
+ puts ("mutexattr_setpshared failed");
+ return 1;
+ }
+ if (pthread_mutex_init (&p->m, &ma) != 0)
+ {
+ puts ("mutex_init failed");
+ return 1;
+ }
+ if (pthread_mutexattr_destroy (&ma) != 0)
+ {
+ puts ("mutexattr_destroy failed");
+ return 1;
+ }
+
+ pthread_condattr_t ca;
+ if (pthread_condattr_init (&ca) != 0)
+ {
+ puts ("condattr_init failed");
+ return 1;
+ }
+ if (pthread_condattr_setpshared (&ca, 1) != 0)
+ {
+ puts ("condattr_setpshared failed");
+ return 1;
+ }
+ if (pthread_cond_init (&p->c, &ca) != 0)
+ {
+ puts ("mutex_init failed");
+ return 1;
+ }
+ if (pthread_condattr_destroy (&ca) != 0)
+ {
+ puts ("condattr_destroy failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (&p->m) != 0)
+ {
+ puts ("initial mutex_lock failed");
+ return 1;
+ }
+
+ p->var = 42;
+
+ pid_t pid = fork ();
+ if (pid == -1)
+ {
+ printf ("fork failed: %m\n");
+ return 1;
+ }
+
+ if (pid == 0)
+ {
+ void *oldp = p;
+ p = mmap (NULL, sizeof (*p), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+
+ if (p == oldp)
+ {
+ puts ("child: mapped to same address");
+ kill (getppid (), SIGKILL);
+ exit (1);
+ }
+
+ munmap (oldp, sizeof (*p));
+
+ if (pthread_mutex_lock (&p->m) != 0)
+ {
+ puts ("child: mutex_lock failed");
+ kill (getppid (), SIGKILL);
+ exit (1);
+ }
+
+ p->var = 0;
+
+#ifndef USE_COND_SIGNAL
+ if (pthread_cond_broadcast (&p->c) != 0)
+ {
+ puts ("child: cond_broadcast failed");
+ kill (getppid (), SIGKILL);
+ exit (1);
+ }
+#else
+ if (pthread_cond_signal (&p->c) != 0)
+ {
+ puts ("child: cond_signal failed");
+ kill (getppid (), SIGKILL);
+ exit (1);
+ }
+#endif
+
+ if (pthread_mutex_unlock (&p->m) != 0)
+ {
+ puts ("child: mutex_unlock failed");
+ kill (getppid (), SIGKILL);
+ exit (1);
+ }
+
+ exit (0);
+ }
+
+ do
+ pthread_cond_wait (&p->c, &p->m);
+ while (p->var != 0);
+
+ if (TEMP_FAILURE_RETRY (waitpid (pid, NULL, 0)) != pid)
+ {
+ printf ("waitpid failed: %m\n");
+ kill (pid, SIGKILL);
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/libc/nptl/tst-cond13.c b/libc/nptl/tst-cond13.c
new file mode 100644
index 000000000..29d79b533
--- /dev/null
+++ b/libc/nptl/tst-cond13.c
@@ -0,0 +1,2 @@
+#define USE_COND_SIGNAL 1
+#include "tst-cond12.c"
diff --git a/libc/nptl/tst-cond14.c b/libc/nptl/tst-cond14.c
new file mode 100644
index 000000000..106fa8c21
--- /dev/null
+++ b/libc/nptl/tst-cond14.c
@@ -0,0 +1,118 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
+
+ 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>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+
+static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t mut = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+static pthread_mutex_t mut2 = PTHREAD_MUTEX_INITIALIZER;
+
+static void *
+tf (void *p)
+{
+ if (pthread_mutex_lock (&mut) != 0)
+ {
+ printf ("%s: 1st mutex_lock failed\n", __func__);
+ exit (1);
+ }
+ if (pthread_mutex_lock (&mut) != 0)
+ {
+ printf ("%s: 2nd mutex_lock failed\n", __func__);
+ exit (1);
+ }
+ if (pthread_mutex_lock (&mut) != 0)
+ {
+ printf ("%s: 3rd mutex_lock failed\n", __func__);
+ exit (1);
+ }
+
+ if (pthread_mutex_unlock (&mut2) != 0)
+ {
+ printf ("%s: mutex_unlock failed\n", __func__);
+ exit (1);
+ }
+
+ if (pthread_cond_wait (&cond, &mut) != 0)
+ {
+ printf ("%s: cond_wait failed\n", __func__);
+ exit (1);
+ }
+
+ puts ("child: done");
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ if (pthread_mutex_lock (&mut2) != 0)
+ {
+ puts ("1st mutex_lock failed");
+ return 1;
+ }
+
+ puts ("parent: create child");
+
+ pthread_t th;
+ int err = pthread_create (&th, NULL, tf, NULL);
+ if (err != 0)
+ {
+ printf ("parent: cannot create thread: %s\n", strerror (err));
+ return 1;
+ }
+
+ /* We have to synchronize with the child. */
+ if (pthread_mutex_lock (&mut2) != 0)
+ {
+ puts ("2nd mutex_lock failed");
+ return 1;
+ }
+
+ /* Give the child to reach to pthread_cond_wait. */
+ sleep (1);
+
+ if (pthread_cond_signal (&cond) != 0)
+ {
+ puts ("cond_signal failed");
+ return 1;
+ }
+
+ err = pthread_join (th, NULL);
+ if (err != 0)
+ {
+ printf ("parent: failed to join: %s\n", strerror (err));
+ return 1;
+ }
+
+ puts ("done");
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#define TIMEOUT 3
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cond15.c b/libc/nptl/tst-cond15.c
new file mode 100644
index 000000000..e815e253b
--- /dev/null
+++ b/libc/nptl/tst-cond15.c
@@ -0,0 +1,160 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+
+static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t mut = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+static pthread_mutex_t mut2 = PTHREAD_MUTEX_INITIALIZER;
+
+static void *
+tf (void *p)
+{
+ if (pthread_mutex_lock (&mut) != 0)
+ {
+ printf ("%s: 1st mutex_lock failed\n", __func__);
+ exit (1);
+ }
+ if (pthread_mutex_lock (&mut) != 0)
+ {
+ printf ("%s: 2nd mutex_lock failed\n", __func__);
+ exit (1);
+ }
+ if (pthread_mutex_lock (&mut) != 0)
+ {
+ printf ("%s: 3rd mutex_lock failed\n", __func__);
+ exit (1);
+ }
+
+ if (pthread_mutex_unlock (&mut2) != 0)
+ {
+ printf ("%s: mutex_unlock failed\n", __func__);
+ exit (1);
+ }
+
+ struct timeval tv;
+ gettimeofday (&tv, NULL);
+ struct timespec ts;
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+ ts.tv_sec += p == NULL ? 100 : 1;
+
+ int err = pthread_cond_timedwait (&cond, &mut, &ts);
+ if ((err != 0 && p == NULL) || (err != ETIMEDOUT && p != NULL))
+ {
+ printf ("%s: cond_wait failed\n", __func__);
+ exit (1);
+ }
+
+ if (pthread_mutex_unlock (&mut) != 0)
+ {
+ printf ("%s: 1st mutex_unlock failed\n", __func__);
+ exit (1);
+ }
+ if (pthread_mutex_unlock (&mut) != 0)
+ {
+ printf ("%s: 2nd mutex_unlock failed\n", __func__);
+ exit (1);
+ }
+ if (pthread_mutex_unlock (&mut) != 0)
+ {
+ printf ("%s: 3rd mutex_unlock failed\n", __func__);
+ exit (1);
+ }
+
+ puts ("child: done");
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ if (pthread_mutex_lock (&mut2) != 0)
+ {
+ puts ("1st mutex_lock failed");
+ return 1;
+ }
+
+ puts ("parent: create 1st child");
+
+ pthread_t th;
+ int err = pthread_create (&th, NULL, tf, NULL);
+ if (err != 0)
+ {
+ printf ("parent: cannot 1st create thread: %s\n", strerror (err));
+ return 1;
+ }
+
+ /* We have to synchronize with the child. */
+ if (pthread_mutex_lock (&mut2) != 0)
+ {
+ puts ("2nd mutex_lock failed");
+ return 1;
+ }
+
+ /* Give the child to reach to pthread_cond_wait. */
+ sleep (1);
+
+ if (pthread_cond_signal (&cond) != 0)
+ {
+ puts ("cond_signal failed");
+ return 1;
+ }
+
+ err = pthread_join (th, NULL);
+ if (err != 0)
+ {
+ printf ("parent: failed to join: %s\n", strerror (err));
+ return 1;
+ }
+
+
+ puts ("parent: create 2nd child");
+
+ err = pthread_create (&th, NULL, tf, (void *) 1l);
+ if (err != 0)
+ {
+ printf ("parent: cannot 2nd create thread: %s\n", strerror (err));
+ return 1;
+ }
+
+ err = pthread_join (th, NULL);
+ if (err != 0)
+ {
+ printf ("parent: failed to join: %s\n", strerror (err));
+ return 1;
+ }
+
+ puts ("done");
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#define TIMEOUT 6
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cond16.c b/libc/nptl/tst-cond16.c
new file mode 100644
index 000000000..00c27eced
--- /dev/null
+++ b/libc/nptl/tst-cond16.c
@@ -0,0 +1,105 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+pthread_cond_t cv = PTHREAD_COND_INITIALIZER;
+pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+bool n, exiting;
+FILE *f;
+int count;
+
+void *
+tf (void *dummy)
+{
+ bool loop = true;
+
+ while (loop)
+ {
+ pthread_mutex_lock (&lock);
+ while (n && !exiting)
+ pthread_cond_wait (&cv, &lock);
+ n = true;
+ pthread_mutex_unlock (&lock);
+
+ fputs (".", f);
+
+ pthread_mutex_lock (&lock);
+ n = false;
+ if (exiting)
+ loop = false;
+#ifdef UNLOCK_AFTER_BROADCAST
+ pthread_cond_broadcast (&cv);
+ pthread_mutex_unlock (&lock);
+#else
+ pthread_mutex_unlock (&lock);
+ pthread_cond_broadcast (&cv);
+#endif
+ }
+
+ return NULL;
+}
+
+int
+do_test (void)
+{
+ f = fopen ("/dev/null", "w");
+ if (f == NULL)
+ {
+ printf ("couldn't open /dev/null, %m\n");
+ return 1;
+ }
+
+ count = sysconf (_SC_NPROCESSORS_ONLN);
+ if (count <= 0)
+ count = 1;
+ count *= 4;
+
+ pthread_t th[count];
+ int i, ret;
+ for (i = 0; i < count; ++i)
+ if ((ret = pthread_create (&th[i], NULL, tf, NULL)) != 0)
+ {
+ errno = ret;
+ printf ("pthread_create %d failed: %m\n", i);
+ return 1;
+ }
+
+ struct timespec ts = { .tv_sec = 20, .tv_nsec = 0 };
+ while (nanosleep (&ts, &ts) != 0);
+
+ pthread_mutex_lock (&lock);
+ exiting = true;
+ pthread_mutex_unlock (&lock);
+
+ for (i = 0; i < count; ++i)
+ pthread_join (th[i], NULL);
+
+ fclose (f);
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#define TIMEOUT 40
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cond17.c b/libc/nptl/tst-cond17.c
new file mode 100644
index 000000000..0586fa59a
--- /dev/null
+++ b/libc/nptl/tst-cond17.c
@@ -0,0 +1,2 @@
+#define UNLOCK_AFTER_BROADCAST 1
+#include "tst-cond16.c"
diff --git a/libc/nptl/tst-cond18.c b/libc/nptl/tst-cond18.c
new file mode 100644
index 000000000..9fd81d298
--- /dev/null
+++ b/libc/nptl/tst-cond18.c
@@ -0,0 +1,117 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
+
+ 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 <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+pthread_cond_t cv = PTHREAD_COND_INITIALIZER;
+pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+bool exiting;
+int fd, count, spins, nn;
+
+void *
+tf (void *id)
+{
+ pthread_mutex_lock (&lock);
+
+ if ((long) id == 0)
+ {
+ while (!exiting)
+ {
+ if ((spins++ % 1000) == 0)
+ write (fd, ".", 1);
+ pthread_mutex_unlock (&lock);
+
+ pthread_mutex_lock (&lock);
+ int njobs = rand () % (count + 1);
+ nn = njobs;
+ if ((rand () % 30) == 0)
+ pthread_cond_broadcast (&cv);
+ else
+ while (njobs--)
+ pthread_cond_signal (&cv);
+ }
+
+ pthread_cond_broadcast (&cv);
+ }
+ else
+ {
+ while (!exiting)
+ {
+ while (!nn && !exiting)
+ pthread_cond_wait (&cv, &lock);
+ --nn;
+ pthread_mutex_unlock (&lock);
+
+ pthread_mutex_lock (&lock);
+ }
+ }
+
+ pthread_mutex_unlock (&lock);
+ return NULL;
+}
+
+int
+do_test (void)
+{
+ fd = open ("/dev/null", O_WRONLY);
+ if (fd < 0)
+ {
+ printf ("couldn't open /dev/null, %m\n");
+ return 1;
+ }
+
+ count = sysconf (_SC_NPROCESSORS_ONLN);
+ if (count <= 0)
+ count = 1;
+ count *= 8;
+
+ pthread_t th[count + 1];
+ int i, ret;
+
+ for (i = 0; i <= count; ++i)
+ if ((ret = pthread_create (&th[i], NULL, tf, (void *) (long) i)) != 0)
+ {
+ errno = ret;
+ printf ("pthread_create %d failed: %m\n", i);
+ return 1;
+ }
+
+ struct timespec ts = { .tv_sec = 20, .tv_nsec = 0 };
+ while (nanosleep (&ts, &ts) != 0);
+
+ pthread_mutex_lock (&lock);
+ exiting = true;
+ pthread_mutex_unlock (&lock);
+
+ for (i = 0; i < count; ++i)
+ pthread_join (th[i], NULL);
+
+ close (fd);
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#define TIMEOUT 40
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cond19.c b/libc/nptl/tst-cond19.c
new file mode 100644
index 000000000..1c9bb7dd7
--- /dev/null
+++ b/libc/nptl/tst-cond19.c
@@ -0,0 +1,76 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+
+static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
+
+
+static int
+do_test (void)
+{
+ int result = 0;
+ struct timespec ts;
+
+ if (clock_gettime (CLOCK_REALTIME, &ts) != 0)
+ {
+ puts ("clock_gettime failed");
+ return 1;
+ }
+
+ ts.tv_nsec = -1;
+
+ int e = pthread_cond_timedwait (&cond, &mut, &ts);
+ if (e == 0)
+ {
+ puts ("first cond_timedwait did not fail");
+ result = 1;
+ }
+ else if (e != EINVAL)
+ {
+ puts ("first cond_timedwait did not return EINVAL");
+ result = 1;
+ }
+
+ ts.tv_nsec = 2000000000;
+
+ e = pthread_cond_timedwait (&cond, &mut, &ts);
+ if (e == 0)
+ {
+ puts ("second cond_timedwait did not fail");
+ result = 1;
+ }
+ else if (e != EINVAL)
+ {
+ puts ("second cond_timedwait did not return EINVAL");
+ result = 1;
+ }
+
+ return result;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cond2.c b/libc/nptl/tst-cond2.c
new file mode 100644
index 000000000..36f0f2941
--- /dev/null
+++ b/libc/nptl/tst-cond2.c
@@ -0,0 +1,163 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <error.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+
+static pthread_barrier_t bar;
+
+
+static void *
+tf (void *a)
+{
+ int i = (long int) a;
+ int err;
+
+ printf ("child %d: lock\n", i);
+
+ err = pthread_mutex_lock (&mut);
+ if (err != 0)
+ error (EXIT_FAILURE, err, "locking in child failed");
+
+ printf ("child %d: sync\n", i);
+
+ int e = pthread_barrier_wait (&bar);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("child: barrier_wait failed");
+ exit (1);
+ }
+
+ printf ("child %d: wait\n", i);
+
+ err = pthread_cond_wait (&cond, &mut);
+ if (err != 0)
+ error (EXIT_FAILURE, err, "child %d: failed to wait", i);
+
+ printf ("child %d: woken up\n", i);
+
+ err = pthread_mutex_unlock (&mut);
+ if (err != 0)
+ error (EXIT_FAILURE, err, "child %d: unlock[2] failed", i);
+
+ printf ("child %d: done\n", i);
+
+ return NULL;
+}
+
+
+#define N 10
+
+
+static int
+do_test (void)
+{
+ pthread_t th[N];
+ int i;
+ int err;
+
+ printf ("&cond = %p\n&mut = %p\n", &cond, &mut);
+
+ if (pthread_barrier_init (&bar, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ pthread_attr_t at;
+
+ if (pthread_attr_init (&at) != 0)
+ {
+ puts ("attr_init failed");
+ return 1;
+ }
+
+ if (pthread_attr_setstacksize (&at, 1 * 1024 * 1024) != 0)
+ {
+ puts ("attr_setstacksize failed");
+ return 1;
+ }
+
+ for (i = 0; i < N; ++i)
+ {
+ printf ("create thread %d\n", i);
+
+ err = pthread_create (&th[i], &at, tf, (void *) (long int) i);
+ if (err != 0)
+ error (EXIT_FAILURE, err, "cannot create thread %d", i);
+
+ printf ("wait for child %d\n", i);
+
+ /* Wait for the child to start up and get the mutex for the
+ conditional variable. */
+ int e = pthread_barrier_wait (&bar);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+ }
+
+ if (pthread_attr_destroy (&at) != 0)
+ {
+ puts ("attr_destroy failed");
+ return 1;
+ }
+
+ puts ("get lock outselves");
+
+ err = pthread_mutex_lock (&mut);
+ if (err != 0)
+ error (EXIT_FAILURE, err, "mut locking failed");
+
+ puts ("broadcast");
+
+ /* Wake up all threads. */
+ err = pthread_cond_broadcast (&cond);
+ if (err != 0)
+ error (EXIT_FAILURE, err, "parent: broadcast failed");
+
+ err = pthread_mutex_unlock (&mut);
+ if (err != 0)
+ error (EXIT_FAILURE, err, "mut unlocking failed");
+
+ /* Join all threads. */
+ for (i = 0; i < N; ++i)
+ {
+ printf ("join thread %d\n", i);
+
+ err = pthread_join (th[i], NULL);
+ if (err != 0)
+ error (EXIT_FAILURE, err, "join of child %d failed", i);
+ }
+
+ puts ("done");
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cond20.c b/libc/nptl/tst-cond20.c
new file mode 100644
index 000000000..18918f32e
--- /dev/null
+++ b/libc/nptl/tst-cond20.c
@@ -0,0 +1,170 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
+
+ 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>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define N 10
+#define ROUNDS 1000
+static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+static pthread_cond_t cond2 = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
+static pthread_barrier_t b;
+static int count;
+
+static void *
+tf (void *p)
+{
+ int i;
+ for (i = 0; i < ROUNDS; ++i)
+ {
+ pthread_mutex_lock (&mut);
+
+ if (++count == N)
+ pthread_cond_signal (&cond2);
+
+#ifdef TIMED
+ struct timeval tv;
+ gettimeofday (&tv, NULL);
+ struct timespec ts;
+ /* Wait three seconds. */
+ ts.tv_sec = tv.tv_sec + 3;
+ ts.tv_nsec = tv.tv_usec * 1000;
+ pthread_cond_timedwait (&cond, &mut, &ts);
+#else
+ pthread_cond_wait (&cond, &mut);
+#endif
+
+ pthread_mutex_unlock (&mut);
+
+ int err = pthread_barrier_wait (&b);
+ if (err != 0 && err != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("child: barrier_wait failed");
+ exit (1);
+ }
+
+ err = pthread_barrier_wait (&b);
+ if (err != 0 && err != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("child: barrier_wait failed");
+ exit (1);
+ }
+ }
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ if (pthread_barrier_init (&b, NULL, N + 1) != 0)
+ {
+ puts ("barrier_init failed");
+ return 1;
+ }
+
+ pthread_mutex_lock (&mut);
+
+ int i, j, err;
+ pthread_t th[N];
+ for (i = 0; i < N; ++i)
+ if ((err = pthread_create (&th[i], NULL, tf, NULL)) != 0)
+ {
+ printf ("cannot create thread %d: %s\n", i, strerror (err));
+ return 1;
+ }
+
+ for (i = 0; i < ROUNDS; ++i)
+ {
+ pthread_cond_wait (&cond2, &mut);
+
+ if (i & 1)
+ pthread_mutex_unlock (&mut);
+
+ if (i & 2)
+ pthread_cond_broadcast (&cond);
+ else if (i & 4)
+ for (j = 0; j < N; ++j)
+ pthread_cond_signal (&cond);
+ else
+ {
+ for (j = 0; j < (i / 8) % N; ++j)
+ pthread_cond_signal (&cond);
+ pthread_cond_broadcast (&cond);
+ }
+
+ if ((i & 1) == 0)
+ pthread_mutex_unlock (&mut);
+
+ err = pthread_cond_destroy (&cond);
+ if (err)
+ {
+ printf ("pthread_cond_destroy failed: %s\n", strerror (err));
+ return 1;
+ }
+
+ /* Now clobber the cond variable which has been successfully
+ destroyed above. */
+ memset (&cond, (char) i, sizeof (cond));
+
+ err = pthread_barrier_wait (&b);
+ if (err != 0 && err != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("parent: barrier_wait failed");
+ return 1;
+ }
+
+ pthread_mutex_lock (&mut);
+
+ err = pthread_barrier_wait (&b);
+ if (err != 0 && err != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("parent: barrier_wait failed");
+ return 1;
+ }
+
+ count = 0;
+ err = pthread_cond_init (&cond, NULL);
+ if (err)
+ {
+ printf ("pthread_cond_init failed: %s\n", strerror (err));
+ return 1;
+ }
+ }
+
+ for (i = 0; i < N; ++i)
+ if ((err = pthread_join (th[i], NULL)) != 0)
+ {
+ printf ("failed to join thread %d: %s\n", i, strerror (err));
+ return 1;
+ }
+
+ puts ("done");
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cond21.c b/libc/nptl/tst-cond21.c
new file mode 100644
index 000000000..89cb771b5
--- /dev/null
+++ b/libc/nptl/tst-cond21.c
@@ -0,0 +1,3 @@
+#include <sys/time.h>
+#define TIMED 1
+#include "tst-cond20.c"
diff --git a/libc/nptl/tst-cond3.c b/libc/nptl/tst-cond3.c
new file mode 100644
index 000000000..cb9eb8558
--- /dev/null
+++ b/libc/nptl/tst-cond3.c
@@ -0,0 +1,113 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+
+/* Note that this test requires more than the standard. It is
+ required that there are no spurious wakeups if only more readers
+ are added. This is a reasonable demand. */
+
+
+static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
+
+
+#define N 10
+
+
+static void *
+tf (void *arg)
+{
+ int i = (long int) arg;
+ int err;
+
+ /* Get the mutex. */
+ err = pthread_mutex_lock (&mut);
+ if (err != 0)
+ {
+ printf ("child %d mutex_lock failed: %s\n", i, strerror (err));
+ exit (1);
+ }
+
+ /* This call should never return. */
+ pthread_cond_wait (&cond, &mut);
+
+ /* We should never get here. */
+ exit (1);
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ int err;
+ int i;
+
+ for (i = 0; i < N; ++i)
+ {
+ pthread_t th;
+
+ if (i != 0)
+ {
+ /* Release the mutex. */
+ err = pthread_mutex_unlock (&mut);
+ if (err != 0)
+ {
+ printf ("mutex_unlock %d failed: %s\n", i, strerror (err));
+ return 1;
+ }
+ }
+
+ err = pthread_create (&th, NULL, tf, (void *) (long int) i);
+ if (err != 0)
+ {
+ printf ("create %d failed: %s\n", i, strerror (err));
+ return 1;
+ }
+
+ /* Get the mutex. */
+ err = pthread_mutex_lock (&mut);
+ if (err != 0)
+ {
+ printf ("mutex_lock %d failed: %s\n", i, strerror (err));
+ return 1;
+ }
+ }
+
+ /* Set an alarm for 1 second. The wrapper will expect this. */
+ alarm (1);
+
+ /* This call should never return. */
+ pthread_cond_wait (&cond, &mut);
+
+ puts ("cond_wait returned");
+ return 1;
+}
+
+
+#define EXPECTED_SIGNAL SIGALRM
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cond4.c b/libc/nptl/tst-cond4.c
new file mode 100644
index 000000000..58c2bdaf0
--- /dev/null
+++ b/libc/nptl/tst-cond4.c
@@ -0,0 +1,263 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+
+
+int *condition;
+
+static int
+do_test (void)
+{
+ size_t ps = sysconf (_SC_PAGESIZE);
+ char tmpfname[] = "/tmp/tst-cond4.XXXXXX";
+ char data[ps];
+ void *mem;
+ int fd;
+ pthread_mutexattr_t ma;
+ pthread_mutex_t *mut1;
+ pthread_mutex_t *mut2;
+ pthread_condattr_t ca;
+ pthread_cond_t *cond;
+ pid_t pid;
+ int result = 0;
+ int p;
+
+ fd = mkstemp (tmpfname);
+ if (fd == -1)
+ {
+ printf ("cannot open temporary file: %m\n");
+ return 1;
+ }
+
+ /* Make sure it is always removed. */
+ unlink (tmpfname);
+
+ /* Create one page of data. */
+ memset (data, '\0', ps);
+
+ /* Write the data to the file. */
+ if (write (fd, data, ps) != (ssize_t) ps)
+ {
+ puts ("short write");
+ return 1;
+ }
+
+ mem = mmap (NULL, ps, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if (mem == MAP_FAILED)
+ {
+ printf ("mmap failed: %m\n");
+ return 1;
+ }
+
+ mut1 = (pthread_mutex_t *) (((uintptr_t) mem
+ + __alignof (pthread_mutex_t))
+ & ~(__alignof (pthread_mutex_t) - 1));
+ mut2 = mut1 + 1;
+
+ cond = (pthread_cond_t *) (((uintptr_t) (mut2 + 1)
+ + __alignof (pthread_cond_t))
+ & ~(__alignof (pthread_cond_t) - 1));
+
+ condition = (int *) (((uintptr_t) (cond + 1) + __alignof (int))
+ & ~(__alignof (int) - 1));
+
+ if (pthread_mutexattr_init (&ma) != 0)
+ {
+ puts ("mutexattr_init failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_getpshared (&ma, &p) != 0)
+ {
+ puts ("1st mutexattr_getpshared failed");
+ return 1;
+ }
+
+ if (p != PTHREAD_PROCESS_PRIVATE)
+ {
+ puts ("default pshared value wrong");
+ return 1;
+ }
+
+ if (pthread_mutexattr_setpshared (&ma, PTHREAD_PROCESS_SHARED) != 0)
+ {
+ puts ("mutexattr_setpshared failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_getpshared (&ma, &p) != 0)
+ {
+ puts ("2nd mutexattr_getpshared failed");
+ return 1;
+ }
+
+ if (p != PTHREAD_PROCESS_SHARED)
+ {
+ puts ("pshared value after setpshared call wrong");
+ return 1;
+ }
+
+ if (pthread_mutex_init (mut1, &ma) != 0)
+ {
+ puts ("1st mutex_init failed");
+ return 1;
+ }
+
+ if (pthread_mutex_init (mut2, &ma) != 0)
+ {
+ puts ("2nd mutex_init failed");
+ return 1;
+ }
+
+ if (pthread_condattr_init (&ca) != 0)
+ {
+ puts ("condattr_init failed");
+ return 1;
+ }
+
+ if (pthread_condattr_getpshared (&ca, &p) != 0)
+ {
+ puts ("1st condattr_getpshared failed");
+ return 1;
+ }
+
+ if (p != PTHREAD_PROCESS_PRIVATE)
+ {
+ puts ("default value for pshared in condattr wrong");
+ return 1;
+ }
+
+ if (pthread_condattr_setpshared (&ca, PTHREAD_PROCESS_SHARED) != 0)
+ {
+ puts ("condattr_setpshared failed");
+ return 1;
+ }
+
+ if (pthread_condattr_getpshared (&ca, &p) != 0)
+ {
+ puts ("2nd condattr_getpshared failed");
+ return 1;
+ }
+
+ if (p != PTHREAD_PROCESS_SHARED)
+ {
+ puts ("pshared condattr still not set");
+ return 1;
+ }
+
+ if (pthread_cond_init (cond, &ca) != 0)
+ {
+ puts ("cond_init failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (mut1) != 0)
+ {
+ puts ("parent: 1st mutex_lock failed");
+ return 1;
+ }
+
+ puts ("going to fork now");
+ pid = fork ();
+ if (pid == -1)
+ {
+ puts ("fork failed");
+ return 1;
+ }
+ else if (pid == 0)
+ {
+ if (pthread_mutex_lock (mut2) != 0)
+ {
+ puts ("child: mutex_lock failed");
+ return 1;
+ }
+
+ if (pthread_mutex_unlock (mut1) != 0)
+ {
+ puts ("child: 1st mutex_unlock failed");
+ return 1;
+ }
+
+ do
+ if (pthread_cond_wait (cond, mut2) != 0)
+ {
+ puts ("child: cond_wait failed");
+ return 1;
+ }
+ while (*condition == 0);
+
+ if (pthread_mutex_unlock (mut2) != 0)
+ {
+ puts ("child: 2nd mutex_unlock failed");
+ return 1;
+ }
+
+ puts ("child done");
+ }
+ else
+ {
+ int status;
+
+ if (pthread_mutex_lock (mut1) != 0)
+ {
+ puts ("parent: 2nd mutex_lock failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (mut2) != 0)
+ {
+ puts ("parent: 3rd mutex_lock failed");
+ return 1;
+ }
+
+ if (pthread_cond_signal (cond) != 0)
+ {
+ puts ("parent: cond_signal failed");
+ return 1;
+ }
+
+ *condition = 1;
+
+ if (pthread_mutex_unlock (mut2) != 0)
+ {
+ puts ("parent: mutex_unlock failed");
+ return 1;
+ }
+
+ puts ("waiting for child");
+
+ waitpid (pid, &status, 0);
+ result |= status;
+
+ puts ("parent done");
+ }
+
+ return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cond5.c b/libc/nptl/tst-cond5.c
new file mode 100644
index 000000000..efa207b5d
--- /dev/null
+++ b/libc/nptl/tst-cond5.c
@@ -0,0 +1,106 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <sys/time.h>
+
+
+static pthread_mutex_t mut;
+static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+
+
+static int
+do_test (void)
+{
+ pthread_mutexattr_t ma;
+ int err;
+ struct timespec ts;
+ struct timeval tv;
+
+ if (pthread_mutexattr_init (&ma) != 0)
+ {
+ puts ("mutexattr_init failed");
+ exit (1);
+ }
+
+ if (pthread_mutexattr_settype (&ma, PTHREAD_MUTEX_ERRORCHECK) != 0)
+ {
+ puts ("mutexattr_settype failed");
+ exit (1);
+ }
+
+ if (pthread_mutex_init (&mut, &ma) != 0)
+ {
+ puts ("mutex_init failed");
+ exit (1);
+ }
+
+ /* Get the mutex. */
+ if (pthread_mutex_lock (&mut) != 0)
+ {
+ puts ("mutex_lock failed");
+ exit (1);
+ }
+
+ /* Waiting for the condition will fail. But we want the timeout here. */
+ if (gettimeofday (&tv, NULL) != 0)
+ {
+ puts ("gettimeofday failed");
+ exit (1);
+ }
+
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+ ts.tv_nsec += 500000000;
+ if (ts.tv_nsec >= 1000000000)
+ {
+ ts.tv_nsec -= 1000000000;
+ ++ts.tv_sec;
+ }
+ err = pthread_cond_timedwait (&cond, &mut, &ts);
+ if (err == 0)
+ {
+ /* This could in theory happen but here without any signal and
+ additional waiter it should not. */
+ puts ("cond_timedwait succeeded");
+ exit (1);
+ }
+ else if (err != ETIMEDOUT)
+ {
+ printf ("cond_timedwait returned with %s\n", strerror (err));
+ exit (1);
+ }
+
+ err = pthread_mutex_unlock (&mut);
+ if (err != 0)
+ {
+ printf ("mutex_unlock failed: %s\n", strerror (err));
+ exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cond6.c b/libc/nptl/tst-cond6.c
new file mode 100644
index 000000000..b5dcaa810
--- /dev/null
+++ b/libc/nptl/tst-cond6.c
@@ -0,0 +1,233 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+
+
+int *condition;
+
+static int
+do_test (void)
+{
+ size_t ps = sysconf (_SC_PAGESIZE);
+ char tmpfname[] = "/tmp/tst-cond6.XXXXXX";
+ char data[ps];
+ void *mem;
+ int fd;
+ pthread_mutexattr_t ma;
+ pthread_mutex_t *mut1;
+ pthread_mutex_t *mut2;
+ pthread_condattr_t ca;
+ pthread_cond_t *cond;
+ pid_t pid;
+ int result = 0;
+
+ fd = mkstemp (tmpfname);
+ if (fd == -1)
+ {
+ printf ("cannot open temporary file: %m\n");
+ exit (1);
+ }
+
+ /* Make sure it is always removed. */
+ unlink (tmpfname);
+
+ /* Create one page of data. */
+ memset (data, '\0', ps);
+
+ /* Write the data to the file. */
+ if (write (fd, data, ps) != (ssize_t) ps)
+ {
+ puts ("short write");
+ exit (1);
+ }
+
+ mem = mmap (NULL, ps, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if (mem == MAP_FAILED)
+ {
+ printf ("mmap failed: %m\n");
+ exit (1);
+ }
+
+ mut1 = (pthread_mutex_t *) (((uintptr_t) mem
+ + __alignof (pthread_mutex_t))
+ & ~(__alignof (pthread_mutex_t) - 1));
+ mut2 = mut1 + 1;
+
+ cond = (pthread_cond_t *) (((uintptr_t) (mut2 + 1)
+ + __alignof (pthread_cond_t))
+ & ~(__alignof (pthread_cond_t) - 1));
+
+ condition = (int *) (((uintptr_t) (cond + 1) + __alignof (int))
+ & ~(__alignof (int) - 1));
+
+ if (pthread_mutexattr_init (&ma) != 0)
+ {
+ puts ("mutexattr_init failed");
+ exit (1);
+ }
+
+ if (pthread_mutexattr_setpshared (&ma, PTHREAD_PROCESS_SHARED) != 0)
+ {
+ puts ("mutexattr_setpshared failed");
+ exit (1);
+ }
+
+ if (pthread_mutex_init (mut1, &ma) != 0)
+ {
+ puts ("1st mutex_init failed");
+ exit (1);
+ }
+
+ if (pthread_mutex_init (mut2, &ma) != 0)
+ {
+ puts ("2nd mutex_init failed");
+ exit (1);
+ }
+
+ if (pthread_condattr_init (&ca) != 0)
+ {
+ puts ("condattr_init failed");
+ exit (1);
+ }
+
+ if (pthread_condattr_setpshared (&ca, PTHREAD_PROCESS_SHARED) != 0)
+ {
+ puts ("condattr_setpshared failed");
+ exit (1);
+ }
+
+ if (pthread_cond_init (cond, &ca) != 0)
+ {
+ puts ("cond_init failed");
+ exit (1);
+ }
+
+ if (pthread_mutex_lock (mut1) != 0)
+ {
+ puts ("parent: 1st mutex_lock failed");
+ exit (1);
+ }
+
+ puts ("going to fork now");
+ pid = fork ();
+ if (pid == -1)
+ {
+ puts ("fork failed");
+ exit (1);
+ }
+ else if (pid == 0)
+ {
+ struct timespec ts;
+ struct timeval tv;
+
+ if (pthread_mutex_lock (mut2) != 0)
+ {
+ puts ("child: mutex_lock failed");
+ exit (1);
+ }
+
+ if (pthread_mutex_unlock (mut1) != 0)
+ {
+ puts ("child: 1st mutex_unlock failed");
+ exit (1);
+ }
+
+ if (gettimeofday (&tv, NULL) != 0)
+ {
+ puts ("gettimeofday failed");
+ exit (1);
+ }
+
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+ ts.tv_nsec += 500000000;
+ if (ts.tv_nsec >= 1000000000)
+ {
+ ts.tv_nsec -= 1000000000;
+ ++ts.tv_sec;
+ }
+
+ do
+ if (pthread_cond_timedwait (cond, mut2, &ts) != 0)
+ {
+ puts ("child: cond_wait failed");
+ exit (1);
+ }
+ while (*condition == 0);
+
+ if (pthread_mutex_unlock (mut2) != 0)
+ {
+ puts ("child: 2nd mutex_unlock failed");
+ exit (1);
+ }
+
+ puts ("child done");
+ }
+ else
+ {
+ int status;
+
+ if (pthread_mutex_lock (mut1) != 0)
+ {
+ puts ("parent: 2nd mutex_lock failed");
+ exit (1);
+ }
+
+ if (pthread_mutex_lock (mut2) != 0)
+ {
+ puts ("parent: 3rd mutex_lock failed");
+ exit (1);
+ }
+
+ if (pthread_cond_signal (cond) != 0)
+ {
+ puts ("parent: cond_signal failed");
+ exit (1);
+ }
+
+ *condition = 1;
+
+ if (pthread_mutex_unlock (mut2) != 0)
+ {
+ puts ("parent: mutex_unlock failed");
+ exit (1);
+ }
+
+ puts ("waiting for child");
+
+ waitpid (pid, &status, 0);
+ result |= status;
+
+ puts ("parent done");
+ }
+
+ return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cond7.c b/libc/nptl/tst-cond7.c
new file mode 100644
index 000000000..5ab7b8f8f
--- /dev/null
+++ b/libc/nptl/tst-cond7.c
@@ -0,0 +1,168 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 <errno.h>
+#include <pthread.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <sys/time.h>
+
+
+typedef struct
+ {
+ pthread_cond_t cond;
+ pthread_mutex_t lock;
+ pthread_t h;
+ } T;
+
+
+static volatile bool done;
+
+
+static void *
+tf (void *arg)
+{
+ puts ("child created");
+
+ if (pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL) != 0
+ || pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, NULL) != 0)
+ {
+ puts ("cannot set cancellation options");
+ exit (1);
+ }
+
+ T *t = (T *) arg;
+
+ if (pthread_mutex_lock (&t->lock) != 0)
+ {
+ puts ("child: lock failed");
+ exit (1);
+ }
+
+ done = true;
+
+ if (pthread_cond_signal (&t->cond) != 0)
+ {
+ puts ("child: cond_signal failed");
+ exit (1);
+ }
+
+ if (pthread_cond_wait (&t->cond, &t->lock) != 0)
+ {
+ puts ("child: cond_wait failed");
+ exit (1);
+ }
+
+ if (pthread_mutex_unlock (&t->lock) != 0)
+ {
+ puts ("child: unlock failed");
+ exit (1);
+ }
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ int i;
+#define N 100
+ T *t[N];
+ for (i = 0; i < N; ++i)
+ {
+ printf ("round %d\n", i);
+
+ t[i] = (T *) malloc (sizeof (T));
+ if (t[i] == NULL)
+ {
+ puts ("out of memory");
+ exit (1);
+ }
+
+ if (pthread_mutex_init (&t[i]->lock, NULL) != 0
+ || pthread_cond_init (&t[i]->cond, NULL) != 0)
+ {
+ puts ("an _init function failed");
+ exit (1);
+ }
+
+ if (pthread_mutex_lock (&t[i]->lock) != 0)
+ {
+ puts ("initial mutex_lock failed");
+ exit (1);
+ }
+
+ done = false;
+
+ if (pthread_create (&t[i]->h, NULL, tf, t[i]) != 0)
+ {
+ puts ("pthread_create failed");
+ exit (1);
+ }
+
+ do
+ if (pthread_cond_wait (&t[i]->cond, &t[i]->lock) != 0)
+ {
+ puts ("cond_wait failed");
+ exit (1);
+ }
+ while (! done);
+
+ /* Release the lock since the cancel handler will get it. */
+ if (pthread_mutex_unlock (&t[i]->lock) != 0)
+ {
+ puts ("mutex_unlock failed");
+ exit (1);
+ }
+
+ if (pthread_cancel (t[i]->h) != 0)
+ {
+ puts ("cancel failed");
+ exit (1);
+ }
+
+ puts ("parent: joining now");
+
+ void *result;
+ if (pthread_join (t[i]->h, &result) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ if (result != PTHREAD_CANCELED)
+ {
+ puts ("result != PTHREAD_CANCELED");
+ exit (1);
+ }
+ }
+
+ for (i = 0; i < N; ++i)
+ free (t[i]);
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cond8.c b/libc/nptl/tst-cond8.c
new file mode 100644
index 000000000..9c97a96fa
--- /dev/null
+++ b/libc/nptl/tst-cond8.c
@@ -0,0 +1,277 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/time.h>
+
+
+static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t mut = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
+
+static pthread_barrier_t bar;
+
+
+static void
+ch (void *arg)
+{
+ int e = pthread_mutex_lock (&mut);
+ if (e == 0)
+ {
+ puts ("mutex not locked at all by cond_wait");
+ exit (1);
+ }
+
+ if (e != EDEADLK)
+ {
+ puts ("no deadlock error signaled");
+ exit (1);
+ }
+
+ if (pthread_mutex_unlock (&mut) != 0)
+ {
+ puts ("ch: cannot unlock mutex");
+ exit (1);
+ }
+
+ puts ("ch done");
+}
+
+
+static void *
+tf1 (void *p)
+{
+ int err;
+
+ if (pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL) != 0
+ || pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, NULL) != 0)
+ {
+ puts ("cannot set cancellation options");
+ exit (1);
+ }
+
+ err = pthread_mutex_lock (&mut);
+ if (err != 0)
+ {
+ puts ("child: cannot get mutex");
+ exit (1);
+ }
+
+ err = pthread_barrier_wait (&bar);
+ if (err != 0 && err != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("barrier_wait returned %d\n", err);
+ exit (1);
+ }
+
+ puts ("child: got mutex; waiting");
+
+ pthread_cleanup_push (ch, NULL);
+
+ pthread_cond_wait (&cond, &mut);
+
+ pthread_cleanup_pop (0);
+
+ puts ("child: cond_wait should not have returned");
+
+ return NULL;
+}
+
+
+static void *
+tf2 (void *p)
+{
+ int err;
+
+ if (pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL) != 0
+ || pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, NULL) != 0)
+ {
+ puts ("cannot set cancellation options");
+ exit (1);
+ }
+
+ err = pthread_mutex_lock (&mut);
+ if (err != 0)
+ {
+ puts ("child: cannot get mutex");
+ exit (1);
+ }
+
+ err = pthread_barrier_wait (&bar);
+ if (err != 0 && err != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("barrier_wait returned %d\n", err);
+ exit (1);
+ }
+
+ puts ("child: got mutex; waiting");
+
+ pthread_cleanup_push (ch, NULL);
+
+ /* Current time. */
+ struct timeval tv;
+ (void) gettimeofday (&tv, NULL);
+ /* +1000 seconds in correct format. */
+ struct timespec ts;
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+ ts.tv_sec += 1000;
+
+ pthread_cond_timedwait (&cond, &mut, &ts);
+
+ pthread_cleanup_pop (0);
+
+ puts ("child: cond_wait should not have returned");
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t th;
+ int err;
+
+ printf ("&cond = %p\n&mut = %p\n", &cond, &mut);
+
+ puts ("parent: get mutex");
+
+ err = pthread_barrier_init (&bar, NULL, 2);
+ if (err != 0)
+ {
+ puts ("parent: cannot init barrier");
+ exit (1);
+ }
+
+ puts ("parent: create child");
+
+ err = pthread_create (&th, NULL, tf1, NULL);
+ if (err != 0)
+ {
+ puts ("parent: cannot create thread");
+ exit (1);
+ }
+
+ puts ("parent: wait for child to lock mutex");
+
+ err = pthread_barrier_wait (&bar);
+ if (err != 0 && err != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("parent: cannot wait for barrier");
+ exit (1);
+ }
+
+ err = pthread_mutex_lock (&mut);
+ if (err != 0)
+ {
+ puts ("parent: mutex_lock failed");
+ exit (1);
+ }
+
+ err = pthread_mutex_unlock (&mut);
+ if (err != 0)
+ {
+ puts ("parent: mutex_unlock failed");
+ exit (1);
+ }
+
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("cannot cancel thread");
+ exit (1);
+ }
+
+ void *r;
+ err = pthread_join (th, &r);
+ if (err != 0)
+ {
+ puts ("parent: failed to join");
+ exit (1);
+ }
+
+ if (r != PTHREAD_CANCELED)
+ {
+ puts ("child hasn't been canceled");
+ exit (1);
+ }
+
+
+
+ puts ("parent: create 2nd child");
+
+ err = pthread_create (&th, NULL, tf2, NULL);
+ if (err != 0)
+ {
+ puts ("parent: cannot create thread");
+ exit (1);
+ }
+
+ puts ("parent: wait for child to lock mutex");
+
+ err = pthread_barrier_wait (&bar);
+ if (err != 0 && err != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("parent: cannot wait for barrier");
+ exit (1);
+ }
+
+ err = pthread_mutex_lock (&mut);
+ if (err != 0)
+ {
+ puts ("parent: mutex_lock failed");
+ exit (1);
+ }
+
+ err = pthread_mutex_unlock (&mut);
+ if (err != 0)
+ {
+ puts ("parent: mutex_unlock failed");
+ exit (1);
+ }
+
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("cannot cancel thread");
+ exit (1);
+ }
+
+ err = pthread_join (th, &r);
+ if (err != 0)
+ {
+ puts ("parent: failed to join");
+ exit (1);
+ }
+
+ if (r != PTHREAD_CANCELED)
+ {
+ puts ("child hasn't been canceled");
+ exit (1);
+ }
+
+ puts ("done");
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-cond9.c b/libc/nptl/tst-cond9.c
new file mode 100644
index 000000000..2a8477dd8
--- /dev/null
+++ b/libc/nptl/tst-cond9.c
@@ -0,0 +1,150 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/time.h>
+
+
+static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t mut = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
+
+
+static void *
+tf (void *arg)
+{
+ int err = pthread_cond_wait (&cond, &mut);
+ if (err == 0)
+ {
+ puts ("cond_wait did not fail");
+ exit (1);
+ }
+
+ if (err != EPERM)
+ {
+ printf ("cond_wait didn't return EPERM but %d\n", err);
+ exit (1);
+ }
+
+
+ /* Current time. */
+ struct timeval tv;
+ (void) gettimeofday (&tv, NULL);
+ /* +1000 seconds in correct format. */
+ struct timespec ts;
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+ ts.tv_sec += 1000;
+
+ err = pthread_cond_timedwait (&cond, &mut, &ts);
+ if (err == 0)
+ {
+ puts ("cond_timedwait did not fail");
+ exit (1);
+ }
+
+ if (err != EPERM)
+ {
+ printf ("cond_timedwait didn't return EPERM but %d\n", err);
+ exit (1);
+ }
+
+ return (void *) 1l;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t th;
+ int err;
+
+ printf ("&cond = %p\n&mut = %p\n", &cond, &mut);
+
+ err = pthread_cond_wait (&cond, &mut);
+ if (err == 0)
+ {
+ puts ("cond_wait did not fail");
+ exit (1);
+ }
+
+ if (err != EPERM)
+ {
+ printf ("cond_wait didn't return EPERM but %d\n", err);
+ exit (1);
+ }
+
+
+ /* Current time. */
+ struct timeval tv;
+ (void) gettimeofday (&tv, NULL);
+ /* +1000 seconds in correct format. */
+ struct timespec ts;
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+ ts.tv_sec += 1000;
+
+ err = pthread_cond_timedwait (&cond, &mut, &ts);
+ if (err == 0)
+ {
+ puts ("cond_timedwait did not fail");
+ exit (1);
+ }
+
+ if (err != EPERM)
+ {
+ printf ("cond_timedwait didn't return EPERM but %d\n", err);
+ exit (1);
+ }
+
+ if (pthread_mutex_lock (&mut) != 0)
+ {
+ puts ("parent: mutex_lock failed");
+ exit (1);
+ }
+
+ puts ("creating thread");
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ void *r;
+ if (pthread_join (th, &r) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+ if (r != (void *) 1l)
+ {
+ puts ("thread has wrong return value");
+ exit (1);
+ }
+
+ puts ("done");
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-context1.c b/libc/nptl/tst-context1.c
new file mode 100644
index 000000000..fcbeadeea
--- /dev/null
+++ b/libc/nptl/tst-context1.c
@@ -0,0 +1,206 @@
+/* Copyright (C) 2003, 2004 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 <errno.h>
+#include <error.h>
+#include <limits.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ucontext.h>
+
+#define N 4
+#if __WORDSIZE == 64
+#define GUARD_PATTERN 0xdeadbeafdeadbeaf
+#else
+#define GUARD_PATTERN 0xdeadbeaf
+#endif
+
+typedef struct {
+ ucontext_t uctx;
+ unsigned long guard[3];
+ } tst_context_t;
+
+static char stacks[N][2 * PTHREAD_STACK_MIN];
+static tst_context_t ctx[N][2];
+static volatile int failures;
+
+
+static void
+fct (long int n)
+{
+ char on_stack[1];
+
+ /* Just to use the thread local descriptor. */
+ printf ("%ld: in %s now, on_stack = %p\n", n, __FUNCTION__, on_stack);
+ errno = 0;
+
+ if (ctx[n][1].uctx.uc_link != &ctx[n][0].uctx)
+ {
+ printf ("context[%ld][1] uc_link damaged, = %p\n", n,
+ ctx[n][1].uctx.uc_link);
+ exit (1);
+ }
+
+ if ((ctx[n][0].guard[0] != GUARD_PATTERN)
+ || (ctx[n][0].guard[1] != GUARD_PATTERN)
+ || (ctx[n][0].guard[2] != GUARD_PATTERN))
+ {
+ printf ("%ld: %s context[0] overflow detected!\n", n, __FUNCTION__);
+ ++failures;
+ }
+
+ if ((ctx[n][1].guard[0] != GUARD_PATTERN)
+ || (ctx[n][1].guard[1] != GUARD_PATTERN)
+ || (ctx[n][1].guard[2] != GUARD_PATTERN))
+ {
+ printf ("%ld: %s context[1] overflow detected!\n", n, __FUNCTION__);
+ ++failures;
+ }
+
+ if (n < 0 || n >= N)
+ {
+ printf ("%ld out of range\n", n);
+ exit (1);
+ }
+
+ if (on_stack < stacks[n] || on_stack >= stacks[n] + sizeof (stacks[0]))
+ {
+ printf ("%ld: on_stack not on appropriate stack\n", n);
+ exit (1);
+ }
+}
+
+
+static void *
+tf (void *arg)
+{
+ int n = (int) (long int) arg;
+
+ ctx[n][0].guard[0] = GUARD_PATTERN;
+ ctx[n][0].guard[1] = GUARD_PATTERN;
+ ctx[n][0].guard[2] = GUARD_PATTERN;
+
+ ctx[n][1].guard[0] = GUARD_PATTERN;
+ ctx[n][1].guard[1] = GUARD_PATTERN;
+ ctx[n][1].guard[2] = GUARD_PATTERN;
+
+ if (getcontext (&ctx[n][1].uctx) != 0)
+ {
+ printf ("%d: cannot get context: %m\n", n);
+ exit (1);
+ }
+
+ printf ("%d: %s: before makecontext\n", n, __FUNCTION__);
+
+ ctx[n][1].uctx.uc_stack.ss_sp = stacks[n];
+ ctx[n][1].uctx.uc_stack.ss_size = sizeof (stacks[n]);
+ ctx[n][1].uctx.uc_link = &ctx[n][0].uctx;
+ makecontext (&ctx[n][1].uctx, (void (*) (void)) fct, 1, (long int) n);
+
+ printf ("%d: %s: before swapcontext\n", n, __FUNCTION__);
+
+ if (swapcontext (&ctx[n][0].uctx, &ctx[n][1].uctx) != 0)
+ {
+ ++failures;
+ printf ("%d: %s: swapcontext failed\n", n, __FUNCTION__);
+ }
+ else
+ printf ("%d: back in %s\n", n, __FUNCTION__);
+
+ return NULL;
+}
+
+
+static volatile int global;
+
+
+static int
+do_test (void)
+{
+ int n;
+ pthread_t th[N];
+ ucontext_t mctx;
+
+ puts ("making contexts");
+ if (getcontext (&mctx) != 0)
+ {
+ if (errno == ENOSYS)
+ {
+ puts ("context handling not supported");
+ exit (0);
+ }
+
+ printf ("%s: getcontext: %m\n", __FUNCTION__);
+ exit (1);
+ }
+
+ /* Play some tricks with this context. */
+ if (++global == 1)
+ if (setcontext (&mctx) != 0)
+ {
+ puts ("setcontext failed");
+ exit (1);
+ }
+ if (global != 2)
+ {
+ puts ("global not incremented twice");
+ exit (1);
+ }
+ puts ("global OK");
+
+ pthread_attr_t at;
+
+ if (pthread_attr_init (&at) != 0)
+ {
+ puts ("attr_init failed");
+ return 1;
+ }
+
+ if (pthread_attr_setstacksize (&at, 1 * 1024 * 1024) != 0)
+ {
+ puts ("attr_setstacksize failed");
+ return 1;
+ }
+
+ for (n = 0; n < N; ++n)
+ if (pthread_create (&th[n], &at, tf, (void *) (long int) n) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ if (pthread_attr_destroy (&at) != 0)
+ {
+ puts ("attr_destroy failed");
+ return 1;
+ }
+
+ for (n = 0; n < N; ++n)
+ if (pthread_join (th[n], NULL) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ return failures;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-detach1.c b/libc/nptl/tst-detach1.c
new file mode 100644
index 000000000..7b27f6ead
--- /dev/null
+++ b/libc/nptl/tst-detach1.c
@@ -0,0 +1,56 @@
+/* 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>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static void *
+tf (void *arg)
+{
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, (void *) pthread_self ()) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ /* Give the child a chance to finish. */
+ sleep (1);
+
+ if (pthread_detach (th) != 0)
+ {
+ puts ("detach failed");
+ exit (1);
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-dlsym1.c b/libc/nptl/tst-dlsym1.c
new file mode 100644
index 000000000..3744570c7
--- /dev/null
+++ b/libc/nptl/tst-dlsym1.c
@@ -0,0 +1,66 @@
+/* Test case by Hui Huang <hui.huang@sun.com>. */
+#include <dlfcn.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+static void *
+start_routine (void *args)
+{
+ int i;
+ void **addrs = (void **) args;
+ for (i = 0; i < 10000; ++i)
+ addrs[i % 1024] = dlsym (NULL, "does_not_exist");
+
+ return addrs;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t tid1, tid2, tid3;
+
+ void *addrs1[1024];
+ void *addrs2[1024];
+ void *addrs3[1024];
+
+ if (pthread_create (&tid1, NULL, start_routine, addrs1) != 0)
+ {
+ puts ("1st create failed");
+ exit (1);
+ }
+ if (pthread_create (&tid2, NULL, start_routine, addrs2) != 0)
+ {
+ puts ("2nd create failed");
+ exit (1);
+ }
+ if (pthread_create (&tid3, NULL, start_routine, addrs3) != 0)
+ {
+ puts ("3rd create failed");
+ exit (1);
+ }
+
+ if (pthread_join (tid1, NULL) != 0)
+ {
+ puts ("1st join failed");
+ exit (1);
+ }
+ if (pthread_join (tid2, NULL) != 0)
+ {
+ puts ("2nd join failed");
+ exit (1);
+ }
+ if (pthread_join (tid3, NULL) != 0)
+ {
+ puts ("2rd join failed");
+ exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-eintr1.c b/libc/nptl/tst-eintr1.c
new file mode 100644
index 000000000..43a5df5b9
--- /dev/null
+++ b/libc/nptl/tst-eintr1.c
@@ -0,0 +1,105 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "eintr.c"
+
+
+static void *
+tf2 (void *arg)
+{
+ return arg;
+}
+
+
+static void *
+tf1 (void *arg)
+{
+ while (1)
+ {
+ pthread_t th;
+
+ int e = pthread_create (&th, NULL, tf2, NULL);
+ if (e != 0)
+ {
+ if (e == EINTR)
+ {
+ puts ("pthread_create returned EINTR");
+ exit (1);
+ }
+
+ char buf[100];
+ printf ("tf1: pthread_create failed: %s\n",
+ strerror_r (e, buf, sizeof (buf)));
+ exit (1);
+ }
+
+ e = pthread_join (th, NULL);
+ if (e != 0)
+ {
+ if (e == EINTR)
+ {
+ puts ("pthread_join returned EINTR");
+ exit (1);
+ }
+
+ char buf[100];
+ printf ("tf1: pthread_join failed: %s\n",
+ strerror_r (e, buf, sizeof (buf)));
+ exit (1);
+ }
+ }
+}
+
+
+static int
+do_test (void)
+{
+ setup_eintr (SIGUSR1, NULL);
+
+ int i;
+ for (i = 0; i < 10; ++i)
+ {
+ pthread_t th;
+ int e = pthread_create (&th, NULL, tf1, NULL);
+ if (e != 0)
+ {
+ char buf[100];
+ printf ("main: pthread_create failed: %s\n",
+ strerror_r (e, buf, sizeof (buf)));
+ exit (1);
+ }
+ }
+
+ (void) tf1 (NULL);
+ /* NOTREACHED */
+
+ return 0;
+}
+
+#define EXPECTED_SIGNAL SIGALRM
+#define TIMEOUT 3
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-eintr2.c b/libc/nptl/tst-eintr2.c
new file mode 100644
index 000000000..8cbbc5a02
--- /dev/null
+++ b/libc/nptl/tst-eintr2.c
@@ -0,0 +1,118 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+
+#include "eintr.c"
+
+
+static pthread_mutex_t m1 = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t m2 = PTHREAD_MUTEX_INITIALIZER;
+
+
+static void *
+tf1 (void *arg)
+{
+ struct timespec ts;
+ struct timeval tv;
+
+ gettimeofday (&tv, NULL);
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+ ts.tv_sec += 10000;
+
+ /* This call must never return. */
+ int e = pthread_mutex_timedlock (&m1, &ts);
+ char buf[100];
+ printf ("tf1: mutex_timedlock returned: %s\n",
+ strerror_r (e, buf, sizeof (buf)));
+
+ exit (1);
+}
+
+
+static void *
+tf2 (void *arg)
+{
+ while (1)
+ {
+ int e = pthread_mutex_lock (&m2);
+ if (e != 0)
+ {
+ puts ("tf2: mutex_lock failed");
+ exit (1);
+ }
+ e = pthread_mutex_unlock (&m2);
+ if (e != 0)
+ {
+ puts ("tf2: mutex_unlock failed");
+ exit (1);
+ }
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 10000000 };
+ nanosleep (&ts, NULL);
+ }
+}
+
+
+static int
+do_test (void)
+{
+ if (pthread_mutex_lock (&m1) != 0)
+ {
+ puts ("mutex_lock failed");
+ exit (1);
+ }
+
+ setup_eintr (SIGUSR1, NULL);
+
+ pthread_t th;
+ char buf[100];
+ int e = pthread_create (&th, NULL, tf1, NULL);
+ if (e != 0)
+ {
+ printf ("main: 1st pthread_create failed: %s\n",
+ strerror_r (e, buf, sizeof (buf)));
+ exit (1);
+ }
+
+ e = pthread_create (&th, NULL, tf2, NULL);
+ if (e != 0)
+ {
+ printf ("main: 2nd pthread_create failed: %s\n",
+ strerror_r (e, buf, sizeof (buf)));
+ exit (1);
+ }
+
+ /* This call must never return. */
+ e = pthread_mutex_lock (&m1);
+ printf ("main: mutex_lock returned: %s\n",
+ strerror_r (e, buf, sizeof (buf)));
+
+ return 0;
+}
+
+#define EXPECTED_SIGNAL SIGALRM
+#define TIMEOUT 3
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-eintr3.c b/libc/nptl/tst-eintr3.c
new file mode 100644
index 000000000..eecab48b1
--- /dev/null
+++ b/libc/nptl/tst-eintr3.c
@@ -0,0 +1,72 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "eintr.c"
+
+
+static void *
+tf (void *arg)
+{
+ pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
+ pthread_mutex_lock (&m);
+ /* This call must not return. */
+ pthread_mutex_lock (&m);
+
+ puts ("tf: mutex_lock returned");
+ exit (1);
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t self = pthread_self ();
+
+ setup_eintr (SIGUSR1, &self);
+
+ pthread_t th;
+ char buf[100];
+ int e = pthread_create (&th, NULL, tf, NULL);
+ if (e != 0)
+ {
+ printf ("main: pthread_create failed: %s\n",
+ strerror_r (e, buf, sizeof (buf)));
+ exit (1);
+ }
+
+ /* This call must never return. */
+ e = pthread_join (th, NULL);
+
+ if (e == EINTR)
+ puts ("pthread_join returned with EINTR");
+
+ return 0;
+}
+
+#define EXPECTED_SIGNAL SIGALRM
+#define TIMEOUT 1
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-eintr4.c b/libc/nptl/tst-eintr4.c
new file mode 100644
index 000000000..dffbdd605
--- /dev/null
+++ b/libc/nptl/tst-eintr4.c
@@ -0,0 +1,56 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "eintr.c"
+
+
+static int
+do_test (void)
+{
+ pthread_t self = pthread_self ();
+
+ setup_eintr (SIGUSR1, &self);
+
+ pthread_barrier_t b;
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ /* This call must never return. */
+ int e = pthread_barrier_wait (&b);
+
+ if (e == EINTR)
+ puts ("pthread_join returned with EINTR");
+
+ return 0;
+}
+
+#define EXPECTED_SIGNAL SIGALRM
+#define TIMEOUT 1
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-eintr5.c b/libc/nptl/tst-eintr5.c
new file mode 100644
index 000000000..91473ec4c
--- /dev/null
+++ b/libc/nptl/tst-eintr5.c
@@ -0,0 +1,81 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+
+#include "eintr.c"
+
+
+static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t c = PTHREAD_COND_INITIALIZER;
+
+
+static void *
+tf (void *arg)
+{
+ struct timespec ts;
+ struct timeval tv;
+
+ gettimeofday (&tv, NULL);
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+ ts.tv_sec += 10000;
+
+ /* This call must never return. */
+ int e = pthread_cond_timedwait (&c, &m, &ts);
+ char buf[100];
+ printf ("tf: cond_timedwait returned: %s\n",
+ strerror_r (e, buf, sizeof (buf)));
+
+ exit (1);
+}
+
+
+static int
+do_test (void)
+{
+ setup_eintr (SIGUSR1, NULL);
+
+ pthread_t th;
+ char buf[100];
+ int e = pthread_create (&th, NULL, tf, NULL);
+ if (e != 0)
+ {
+ printf ("main: pthread_create failed: %s\n",
+ strerror_r (e, buf, sizeof (buf)));
+ exit (1);
+ }
+
+ /* This call must never return. */
+ e = pthread_cond_wait (&c, &m);
+ printf ("main: cond_wait returned: %s\n",
+ strerror_r (e, buf, sizeof (buf)));
+
+ return 0;
+}
+
+#define EXPECTED_SIGNAL SIGALRM
+#define TIMEOUT 3
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-exec1.c b/libc/nptl/tst-exec1.c
new file mode 100644
index 000000000..0448a059d
--- /dev/null
+++ b/libc/nptl/tst-exec1.c
@@ -0,0 +1,160 @@
+/* Simple exec test, only a thread in the parent.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <paths.h>
+#include <pthread.h>
+#include <signal.h>
+#include <spawn.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+
+static void *
+tf (void *arg)
+{
+ pthread_t th = (pthread_t) arg;
+
+ if (pthread_join (th, NULL) == 0)
+ {
+ puts ("thread in parent joined!?");
+ exit (1);
+ }
+
+ puts ("join in thread in parent returned!?");
+ exit (1);
+}
+
+
+static int
+do_test (void)
+{
+ int fd[2];
+ if (pipe (fd) != 0)
+ {
+ puts ("pipe failed");
+ exit (1);
+ }
+
+ /* Not interested in knowing when the pipe is closed. */
+ if (sigignore (SIGPIPE) != 0)
+ {
+ puts ("sigignore failed");
+ exit (1);
+ }
+
+ posix_spawn_file_actions_t a;
+ if (posix_spawn_file_actions_init (&a) != 0)
+ {
+ puts ("spawn_file_actions_init failed");
+ exit (1);
+ }
+
+ if (posix_spawn_file_actions_adddup2 (&a, fd[1], STDOUT_FILENO) != 0)
+ {
+ puts ("spawn_file_actions_adddup2 failed");
+ exit (1);
+ }
+
+ if (posix_spawn_file_actions_addclose (&a, fd[0]) != 0)
+ {
+ puts ("spawn_file_actions_addclose");
+ exit (1);
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, (void *) pthread_self ()) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ pid_t pid;
+ char *argv[] = { (char *) _PATH_BSHELL, (char *) "-c", (char *) "echo $$",
+ NULL };
+ if (posix_spawn (&pid, _PATH_BSHELL, &a, NULL, argv, NULL) != 0)
+ {
+ puts ("spawn failed");
+ exit (1);
+ }
+
+ close (fd[1]);
+
+ char buf[200];
+ ssize_t n;
+ bool seen_pid = false;
+ while (TEMP_FAILURE_RETRY ((n = read (fd[0], buf, sizeof (buf)))) > 0)
+ {
+ /* We only expect to read the PID. */
+ char *endp;
+ long int rpid = strtol (buf, &endp, 10);
+
+ if (*endp != '\n')
+ {
+ printf ("didn't parse whole line: \"%s\"\n", buf);
+ exit (1);
+ }
+ if (endp == buf)
+ {
+ puts ("read empty line");
+ exit (1);
+ }
+
+ if (rpid != pid)
+ {
+ printf ("found \"%s\", expected PID %ld\n", buf, (long int) pid);
+ exit (1);
+ }
+
+ if (seen_pid)
+ {
+ puts ("found more than one PID line");
+ exit (1);
+ }
+
+ seen_pid = true;
+ }
+
+ close (fd[0]);
+
+ int status;
+ int err = waitpid (pid, &status, 0);
+ if (err != pid)
+ {
+ puts ("waitpid failed");
+ exit (1);
+ }
+
+ if (!seen_pid)
+ {
+ puts ("didn't get PID");
+ exit (1);
+ }
+
+ puts ("read correct PID");
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-exec2.c b/libc/nptl/tst-exec2.c
new file mode 100644
index 000000000..0fa80eff5
--- /dev/null
+++ b/libc/nptl/tst-exec2.c
@@ -0,0 +1,155 @@
+/* Thread with running thread calls exec.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <paths.h>
+#include <pthread.h>
+#include <signal.h>
+#include <spawn.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+
+static void *
+tf (void *arg)
+{
+ pthread_t th = (pthread_t) arg;
+
+ if (pthread_join (th, NULL) == 0)
+ {
+ puts ("thread in parent joined!?");
+ exit (1);
+ }
+
+ puts ("join in thread in parent returned!?");
+ exit (1);
+}
+
+
+static int
+do_test (void)
+{
+ int fd[2];
+ if (pipe (fd) != 0)
+ {
+ puts ("pipe failed");
+ exit (1);
+ }
+
+ /* Not interested in knowing when the pipe is closed. */
+ if (sigignore (SIGPIPE) != 0)
+ {
+ puts ("sigignore failed");
+ exit (1);
+ }
+
+ pid_t pid = fork ();
+ if (pid == -1)
+ {
+ puts ("fork failed");
+ exit (1);
+ }
+
+ if (pid == 0)
+ {
+ /* Use the fd for stdout. This is kind of ugly because it
+ substitutes the fd of stdout but we know what we are doing
+ here... */
+ if (dup2 (fd[1], STDOUT_FILENO) != STDOUT_FILENO)
+ {
+ puts ("dup2 failed");
+ exit (1);
+ }
+
+ close (fd[0]);
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, (void *) pthread_self ()) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ execl (_PATH_BSHELL, _PATH_BSHELL, "-c", "echo $$", NULL);
+
+ puts ("execl failed");
+ exit (1);
+ }
+
+ close (fd[1]);
+
+ char buf[200];
+ ssize_t n;
+ bool seen_pid = false;
+ while (TEMP_FAILURE_RETRY ((n = read (fd[0], buf, sizeof (buf)))) > 0)
+ {
+ /* We only expect to read the PID. */
+ char *endp;
+ long int rpid = strtol (buf, &endp, 10);
+
+ if (*endp != '\n')
+ {
+ printf ("didn't parse whole line: \"%s\"\n", buf);
+ exit (1);
+ }
+ if (endp == buf)
+ {
+ puts ("read empty line");
+ exit (1);
+ }
+
+ if (rpid != pid)
+ {
+ printf ("found \"%s\", expected PID %ld\n", buf, (long int) pid);
+ exit (1);
+ }
+
+ if (seen_pid)
+ {
+ puts ("found more than one PID line");
+ exit (1);
+ }
+ seen_pid = true;
+ }
+
+ close (fd[0]);
+
+ int status;
+ int err = waitpid (pid, &status, 0);
+ if (err != pid)
+ {
+ puts ("waitpid failed");
+ exit (1);
+ }
+
+ if (!seen_pid)
+ {
+ puts ("didn't get PID");
+ exit (1);
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-exec3.c b/libc/nptl/tst-exec3.c
new file mode 100644
index 000000000..eb9c72124
--- /dev/null
+++ b/libc/nptl/tst-exec3.c
@@ -0,0 +1,153 @@
+/* Thread calls exec.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <paths.h>
+#include <pthread.h>
+#include <signal.h>
+#include <spawn.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+
+static void *
+tf (void *arg)
+{
+ execl (_PATH_BSHELL, _PATH_BSHELL, "-c", "echo $$", NULL);
+
+ puts ("execl failed");
+ exit (1);
+}
+
+
+static int
+do_test (void)
+{
+ int fd[2];
+ if (pipe (fd) != 0)
+ {
+ puts ("pipe failed");
+ exit (1);
+ }
+
+ /* Not interested in knowing when the pipe is closed. */
+ if (sigignore (SIGPIPE) != 0)
+ {
+ puts ("sigignore failed");
+ exit (1);
+ }
+
+ pid_t pid = fork ();
+ if (pid == -1)
+ {
+ puts ("fork failed");
+ exit (1);
+ }
+
+ if (pid == 0)
+ {
+ /* Use the fd for stdout. This is kind of ugly because it
+ substitutes the fd of stdout but we know what we are doing
+ here... */
+ if (dup2 (fd[1], STDOUT_FILENO) != STDOUT_FILENO)
+ {
+ puts ("dup2 failed");
+ exit (1);
+ }
+
+ close (fd[0]);
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ if (pthread_join (th, NULL) == 0)
+ {
+ puts ("join succeeded!?");
+ exit (1);
+ }
+
+ puts ("join returned!?");
+ exit (1);
+ }
+
+ close (fd[1]);
+
+ char buf[200];
+ ssize_t n;
+ bool seen_pid = false;
+ while (TEMP_FAILURE_RETRY ((n = read (fd[0], buf, sizeof (buf)))) > 0)
+ {
+ /* We only expect to read the PID. */
+ char *endp;
+ long int rpid = strtol (buf, &endp, 10);
+
+ if (*endp != '\n')
+ {
+ printf ("didn't parse whole line: \"%s\"\n", buf);
+ exit (1);
+ }
+ if (endp == buf)
+ {
+ puts ("read empty line");
+ exit (1);
+ }
+
+ if (rpid != pid)
+ {
+ printf ("found \"%s\", expected PID %ld\n", buf, (long int) pid);
+ exit (1);
+ }
+
+ if (seen_pid)
+ {
+ puts ("found more than one PID line");
+ exit (1);
+ }
+ seen_pid = true;
+ }
+
+ close (fd[0]);
+
+ int status;
+ int err = waitpid (pid, &status, 0);
+ if (err != pid)
+ {
+ puts ("waitpid failed");
+ exit (1);
+ }
+
+ if (!seen_pid)
+ {
+ puts ("didn't get PID");
+ exit (1);
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-exec4.c b/libc/nptl/tst-exec4.c
new file mode 100644
index 000000000..b3920a030
--- /dev/null
+++ b/libc/nptl/tst-exec4.c
@@ -0,0 +1,116 @@
+/* Signal handler and mask set in thread which calls exec.
+ 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>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static void *
+tf (void *arg)
+{
+ /* Ignore SIGUSR1 and block SIGUSR2. */
+ if (sigignore (SIGUSR1) != 0)
+ {
+ puts ("sigignore failed");
+ exit (1);
+ }
+
+ sigset_t ss;
+ sigemptyset (&ss);
+ sigaddset (&ss, SIGUSR2);
+ if (pthread_sigmask (SIG_BLOCK, &ss, NULL) != 0)
+ {
+ puts ("1st run: sigmask failed");
+ exit (1);
+ }
+
+ char **oldargv = (char **) arg;
+ size_t n = 1;
+ while (oldargv[n] != NULL)
+ ++n;
+
+ char **argv = (char **) alloca ((n + 1) * sizeof (char *));
+ for (n = 0; oldargv[n + 1] != NULL; ++n)
+ argv[n] = oldargv[n + 1];
+ argv[n++] = (char *) "--direct";
+ argv[n] = NULL;
+
+ execv (argv[0], argv);
+
+ puts ("execv failed");
+
+ exit (1);
+}
+
+
+static int
+do_test (int argc, char *argv[])
+{
+ if (argc == 1)
+ {
+ /* This is the second call. Perform the test. */
+ struct sigaction sa;
+
+ if (sigaction (SIGUSR1, NULL, &sa) != 0)
+ {
+ puts ("2nd run: sigaction failed");
+ return 1;
+ }
+ if (sa.sa_handler != SIG_IGN)
+ {
+ puts ("SIGUSR1 not ignored");
+ return 1;
+ }
+
+ sigset_t ss;
+ if (pthread_sigmask (SIG_SETMASK, NULL, &ss) != 0)
+ {
+ puts ("2nd run: sigmask failed");
+ return 1;
+ }
+ if (! sigismember (&ss, SIGUSR2))
+ {
+ puts ("SIGUSR2 not blocked");
+ return 1;
+ }
+
+ return 0;
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, argv) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ /* This call should never return. */
+ pthread_join (th, NULL);
+
+ puts ("join returned");
+
+ return 1;
+}
+
+#define TEST_FUNCTION do_test (argc, argv)
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-execstack-mod.c b/libc/nptl/tst-execstack-mod.c
new file mode 100644
index 000000000..5b9812c25
--- /dev/null
+++ b/libc/nptl/tst-execstack-mod.c
@@ -0,0 +1 @@
+#include "../elf/tst-execstack-mod.c"
diff --git a/libc/nptl/tst-execstack.c b/libc/nptl/tst-execstack.c
new file mode 100644
index 000000000..6e45c1a5e
--- /dev/null
+++ b/libc/nptl/tst-execstack.c
@@ -0,0 +1,2 @@
+#define USE_PTHREADS 1
+#include "../elf/tst-execstack.c"
diff --git a/libc/nptl/tst-exit1.c b/libc/nptl/tst-exit1.c
new file mode 100644
index 000000000..44175f76c
--- /dev/null
+++ b/libc/nptl/tst-exit1.c
@@ -0,0 +1,79 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+/* NOTE: this tests functionality beyond POSIX. POSIX does not allow
+ exit to be called more than once. */
+
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static pthread_barrier_t b;
+
+
+static void *
+tf (void *arg)
+{
+ int r = pthread_barrier_wait (&b);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ exit (0);
+}
+
+
+static int
+do_test (void)
+{
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ int r = pthread_barrier_wait (&b);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ /* Do nothing. */
+ if (pthread_join (th, NULL) == 0)
+ {
+ puts ("join succeeded!?");
+ exit (1);
+ }
+
+ puts ("join returned!?");
+ exit (1);
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-exit2.c b/libc/nptl/tst-exit2.c
new file mode 100644
index 000000000..3f5ff27b0
--- /dev/null
+++ b/libc/nptl/tst-exit2.c
@@ -0,0 +1,40 @@
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+
+static void *
+tf (void *arg)
+{
+ while (1)
+ sleep (100);
+
+ /* NOTREACHED */
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t th;
+
+ int e = pthread_create (&th, NULL, tf, NULL);
+ if (e != 0)
+ {
+ printf ("create failed: %s\n", strerror (e));
+ return 1;
+ }
+
+ /* Terminate only this thread. */
+ pthread_exit (NULL);
+
+ /* NOTREACHED */
+ return 1;
+}
+
+#define EXPECTED_SIGNAL SIGALRM
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-exit3.c b/libc/nptl/tst-exit3.c
new file mode 100644
index 000000000..da92c82c0
--- /dev/null
+++ b/libc/nptl/tst-exit3.c
@@ -0,0 +1,81 @@
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+
+static pthread_barrier_t b;
+
+
+static void *
+tf2 (void *arg)
+{
+ while (1)
+ sleep (100);
+
+ /* NOTREACHED */
+ return NULL;
+}
+
+
+static void *
+tf (void *arg)
+{
+ pthread_t th;
+
+ int e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ e = pthread_create (&th, NULL, tf2, NULL);
+ if (e != 0)
+ {
+ printf ("create failed: %s\n", strerror (e));
+ exit (1);
+ }
+
+ /* Terminate only this thread. */
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t th;
+
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ int e = pthread_create (&th, NULL, tf, NULL);
+ if (e != 0)
+ {
+ printf ("create failed: %s\n", strerror (e));
+ exit (1);
+ }
+
+ e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ /* Terminate only this thread. */
+ pthread_exit (NULL);
+
+ /* NOTREACHED */
+ return 1;
+}
+
+#define EXPECTED_SIGNAL SIGALRM
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-fini1.c b/libc/nptl/tst-fini1.c
new file mode 100644
index 000000000..bec4be1d3
--- /dev/null
+++ b/libc/nptl/tst-fini1.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
+
+ 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 <unistd.h>
+
+extern void m (void);
+
+int
+main (void)
+{
+ alarm (5);
+
+ m ();
+
+ /* The destructor is supposed to run now. Make sure that if it is
+ not we will notice it by using 42 as the exit code. In case the
+ destructor is run it will terminate with status zero. */
+ return 42;
+}
diff --git a/libc/nptl/tst-fini1mod.c b/libc/nptl/tst-fini1mod.c
new file mode 100644
index 000000000..492d9ffb8
--- /dev/null
+++ b/libc/nptl/tst-fini1mod.c
@@ -0,0 +1,72 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
+
+ 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>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static void *
+tf (void *arg)
+{
+ int fds[2];
+ if (pipe (fds) != 0)
+ {
+ puts ("pipe failed");
+ exit (1);
+ }
+
+ char buf[10];
+ read (fds[0], buf, sizeof (buf));
+
+ puts ("read returned");
+ exit (1);
+}
+
+static pthread_t th;
+
+static void
+__attribute ((destructor))
+dest (void)
+{
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("cancel failed");
+ _exit (1);
+ }
+ void *r;
+ if (pthread_join (th, &r) != 0)
+ {
+ puts ("join failed");
+ _exit (1);
+ }
+ /* Exit successfully. */
+ _exit (0);
+}
+
+void
+m (void)
+{
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ _exit (1);
+ }
+}
diff --git a/libc/nptl/tst-flock1.c b/libc/nptl/tst-flock1.c
new file mode 100644
index 000000000..ed2472d3a
--- /dev/null
+++ b/libc/nptl/tst-flock1.c
@@ -0,0 +1,93 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/file.h>
+
+
+static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+
+static int fd;
+
+
+static void *
+tf (void *arg)
+{
+ if (flock (fd, LOCK_SH | LOCK_NB) != 0)
+ {
+ puts ("second flock failed");
+ exit (1);
+ }
+
+ pthread_mutex_unlock (&lock);
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ char tmp[] = "/tmp/tst-flock1-XXXXXX";
+
+ fd = mkstemp (tmp);
+ if (fd == -1)
+ {
+ puts ("mkstemp failed");
+ exit (1);
+ }
+
+ unlink (tmp);
+
+ write (fd, "foobar xyzzy", 12);
+
+ if (flock (fd, LOCK_EX | LOCK_NB) != 0)
+ {
+ puts ("first flock failed");
+ exit (1);
+ }
+
+ pthread_mutex_lock (&lock);
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("pthread_create failed");
+ exit (1);
+ }
+
+ pthread_mutex_lock (&lock);
+
+ void *result;
+ if (pthread_join (th, &result) != 0)
+ {
+ puts ("pthread_join failed");
+ exit (1);
+ }
+
+ close (fd);
+
+ return result != NULL;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-flock2.c b/libc/nptl/tst-flock2.c
new file mode 100644
index 000000000..8ef3206cc
--- /dev/null
+++ b/libc/nptl/tst-flock2.c
@@ -0,0 +1,260 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/file.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+
+
+static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t lock2 = PTHREAD_MUTEX_INITIALIZER;
+static int fd;
+
+
+static void *
+tf (void *arg)
+{
+ struct flock fl =
+ {
+ .l_type = F_WRLCK,
+ .l_start = 0,
+ .l_whence = SEEK_SET,
+ .l_len = 10
+ };
+ if (TEMP_FAILURE_RETRY (fcntl (fd, F_SETLKW, &fl)) != 0)
+ {
+ puts ("fourth fcntl failed");
+ exit (1);
+ }
+
+ pthread_mutex_unlock (&lock);
+
+ pthread_mutex_lock (&lock2);
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ char tmp[] = "/tmp/tst-flock2-XXXXXX";
+
+ fd = mkstemp (tmp);
+ if (fd == -1)
+ {
+ puts ("mkstemp failed");
+ return 1;
+ }
+
+ unlink (tmp);
+
+ int i;
+ for (i = 0; i < 20; ++i)
+ write (fd, "foobar xyzzy", 12);
+
+ pthread_barrier_t *b;
+ b = mmap (NULL, sizeof (pthread_barrier_t), PROT_READ | PROT_WRITE,
+ MAP_SHARED, fd, 0);
+ if (b == MAP_FAILED)
+ {
+ puts ("mmap failed");
+ return 1;
+ }
+
+ pthread_barrierattr_t ba;
+ if (pthread_barrierattr_init (&ba) != 0)
+ {
+ puts ("barrierattr_init failed");
+ return 1;
+ }
+
+ if (pthread_barrierattr_setpshared (&ba, PTHREAD_PROCESS_SHARED) != 0)
+ {
+ puts ("barrierattr_setpshared failed");
+ return 1;
+ }
+
+ if (pthread_barrier_init (b, &ba, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ return 1;
+ }
+
+ if (pthread_barrierattr_destroy (&ba) != 0)
+ {
+ puts ("barrierattr_destroy failed");
+ return 1;
+ }
+
+ struct flock fl =
+ {
+ .l_type = F_WRLCK,
+ .l_start = 0,
+ .l_whence = SEEK_SET,
+ .l_len = 10
+ };
+ if (TEMP_FAILURE_RETRY (fcntl (fd, F_SETLKW, &fl)) != 0)
+ {
+ puts ("first fcntl failed");
+ return 1;
+ }
+
+ pid_t pid = fork ();
+ if (pid == -1)
+ {
+ puts ("fork failed");
+ return 1;
+ }
+
+ if (pid == 0)
+ {
+ /* Make sure the child does not stay around indefinitely. */
+ alarm (10);
+
+ /* Try to get the lock. */
+ if (TEMP_FAILURE_RETRY (fcntl (fd, F_SETLK, &fl)) == 0)
+ {
+ puts ("child: second flock succeeded");
+ return 1;
+ }
+ }
+
+ pthread_barrier_wait (b);
+
+ if (pid != 0)
+ {
+ fl.l_type = F_UNLCK;
+ if (TEMP_FAILURE_RETRY (fcntl (fd, F_SETLKW, &fl)) != 0)
+ {
+ puts ("third fcntl failed");
+ return 1;
+ }
+ }
+
+ pthread_barrier_wait (b);
+
+ pthread_t th;
+ if (pid == 0)
+ {
+ if (pthread_mutex_lock (&lock) != 0)
+ {
+ puts ("1st locking of lock failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (&lock2) != 0)
+ {
+ puts ("1st locking of lock2 failed");
+ return 1;
+ }
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("pthread_create failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (&lock) != 0)
+ {
+ puts ("2nd locking of lock failed");
+ return 1;
+ }
+
+ puts ("child locked file");
+ }
+
+ pthread_barrier_wait (b);
+
+ if (pid != 0)
+ {
+ fl.l_type = F_WRLCK;
+ if (TEMP_FAILURE_RETRY (fcntl (fd, F_SETLK, &fl)) == 0)
+ {
+ puts ("fifth fcntl succeeded");
+ return 1;
+ }
+
+ puts ("file locked by child");
+ }
+
+ pthread_barrier_wait (b);
+
+ if (pid == 0)
+ {
+ if (pthread_mutex_unlock (&lock2) != 0)
+ {
+ puts ("unlock of lock2 failed");
+ return 1;
+ }
+
+ if (pthread_join (th, NULL) != 0)
+ {
+ puts ("join failed");
+ return 1;
+ }
+
+ puts ("child's thread terminated");
+ }
+
+ pthread_barrier_wait (b);
+
+ if (pid != 0)
+ {
+ fl.l_type = F_WRLCK;
+ if (TEMP_FAILURE_RETRY (fcntl (fd, F_SETLK, &fl)) == 0)
+ {
+ puts ("fifth fcntl succeeded");
+ return 1;
+ }
+
+ puts ("file still locked");
+ }
+
+ pthread_barrier_wait (b);
+
+ if (pid == 0)
+ {
+ _exit (0);
+ }
+
+ int status;
+ if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid)
+ {
+ puts ("waitpid failed");
+ return 1;
+ }
+ puts ("child terminated");
+
+ if (TEMP_FAILURE_RETRY (fcntl (fd, F_SETLKW, &fl)) != 0)
+ {
+ puts ("sixth fcntl failed");
+ return 1;
+ }
+
+ return status;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-fork1.c b/libc/nptl/tst-fork1.c
new file mode 100644
index 000000000..33c4ed84f
--- /dev/null
+++ b/libc/nptl/tst-fork1.c
@@ -0,0 +1,120 @@
+/* Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Roland McGrath <roland@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+static void *
+thread_function (void * arg)
+{
+ int i = (intptr_t) arg;
+ int status;
+ pid_t pid;
+ pid_t pid2;
+
+ pid = fork ();
+ switch (pid)
+ {
+ case 0:
+ printf ("%ld for %d\n", (long int) getpid (), i);
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 * i };
+ nanosleep (&ts, NULL);
+ _exit (i);
+ break;
+ case -1:
+ printf ("fork: %m\n");
+ return (void *) 1l;
+ break;
+ }
+
+ pid2 = TEMP_FAILURE_RETRY (waitpid (pid, &status, 0));
+ if (pid2 != pid)
+ {
+ printf ("waitpid returned %ld, expected %ld\n",
+ (long int) pid2, (long int) pid);
+ return (void *) 1l;
+ }
+
+ printf ("%ld with %d, expected %d\n",
+ (long int) pid, WEXITSTATUS (status), i);
+
+ return WEXITSTATUS (status) == i ? NULL : (void *) 1l;
+}
+
+#define N 5
+static const int t[N] = { 7, 6, 5, 4, 3 };
+
+int
+main (void)
+{
+ pthread_t th[N];
+ int i;
+ int result = 0;
+ pthread_attr_t at;
+
+ if (pthread_attr_init (&at) != 0)
+ {
+ puts ("attr_init failed");
+ return 1;
+ }
+
+ if (pthread_attr_setstacksize (&at, 1 * 1024 * 1024) != 0)
+ {
+ puts ("attr_setstacksize failed");
+ return 1;
+ }
+
+ for (i = 0; i < N; ++i)
+ if (pthread_create (&th[i], NULL, thread_function,
+ (void *) (intptr_t) t[i]) != 0)
+ {
+ printf ("creation of thread %d failed\n", i);
+ exit (1);
+ }
+
+ if (pthread_attr_destroy (&at) != 0)
+ {
+ puts ("attr_destroy failed");
+ return 1;
+ }
+
+ for (i = 0; i < N; ++i)
+ {
+ void *v;
+ if (pthread_join (th[i], &v) != 0)
+ {
+ printf ("join of thread %d failed\n", i);
+ result = 1;
+ }
+ else if (v != NULL)
+ {
+ printf ("join %d successful, but child failed\n", i);
+ result = 1;
+ }
+ else
+ printf ("join %d successful\n", i);
+ }
+
+ return result;
+}
diff --git a/libc/nptl/tst-fork2.c b/libc/nptl/tst-fork2.c
new file mode 100644
index 000000000..07d6c2266
--- /dev/null
+++ b/libc/nptl/tst-fork2.c
@@ -0,0 +1,90 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Roland McGrath <roland@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+
+static pid_t initial_pid;
+
+
+static void *
+tf (void *arg)
+{
+ if (getppid () != initial_pid)
+ {
+ printf ("getppid in thread returned %ld, expected %ld\n",
+ (long int) getppid (), (long int) initial_pid);
+ return (void *) -1;
+ }
+
+ return NULL;
+}
+
+
+int
+main (void)
+{
+ initial_pid = getpid ();
+
+ pid_t child = fork ();
+ if (child == 0)
+ {
+ if (getppid () != initial_pid)
+ {
+ printf ("first getppid returned %ld, expected %ld\n",
+ (long int) getppid (), (long int) initial_pid);
+ exit (1);
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("pthread_create failed");
+ exit (1);
+ }
+
+ void *result;
+ if (pthread_join (th, &result) != 0)
+ {
+ puts ("pthread_join failed");
+ exit (1);
+ }
+
+ exit (result == NULL ? 0 : 1);
+ }
+ else if (child == -1)
+ {
+ puts ("initial fork failed");
+ return 1;
+ }
+
+ int status;
+ if (TEMP_FAILURE_RETRY (waitpid (child, &status, 0)) != child)
+ {
+ printf ("waitpid failed: %m\n");
+ return 1;
+ }
+
+ return status;
+}
diff --git a/libc/nptl/tst-fork3.c b/libc/nptl/tst-fork3.c
new file mode 100644
index 000000000..bc73853a5
--- /dev/null
+++ b/libc/nptl/tst-fork3.c
@@ -0,0 +1,107 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Roland McGrath <roland@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+
+static pid_t initial_pid;
+
+
+static void *
+tf2 (void *arg)
+{
+ if (getppid () != initial_pid)
+ {
+ printf ("getppid in thread returned %ld, expected %ld\n",
+ (long int) getppid (), (long int) initial_pid);
+ return (void *) -1;
+ }
+
+ return NULL;
+}
+
+
+static void *
+tf1 (void *arg)
+{
+ pid_t child = fork ();
+ if (child == 0)
+ {
+ if (getppid () != initial_pid)
+ {
+ printf ("first getppid returned %ld, expected %ld\n",
+ (long int) getppid (), (long int) initial_pid);
+ exit (1);
+ }
+
+ pthread_t th2;
+ if (pthread_create (&th2, NULL, tf2, NULL) != 0)
+ {
+ puts ("child: pthread_create failed");
+ exit (1);
+ }
+
+ void *result;
+ if (pthread_join (th2, &result) != 0)
+ {
+ puts ("pthread_join failed");
+ exit (1);
+ }
+
+ exit (result == NULL ? 0 : 1);
+ }
+ else if (child == -1)
+ {
+ puts ("initial fork failed");
+ exit (1);
+ }
+
+ int status;
+ if (TEMP_FAILURE_RETRY (waitpid (child, &status, 0)) != child)
+ {
+ printf ("waitpid failed: %m\n");
+ exit (1);
+ }
+
+ exit (status);
+}
+
+
+int
+main (void)
+{
+ initial_pid = getpid ();
+
+ pthread_t th1;
+ if (pthread_create (&th1, NULL, tf1, NULL) != 0)
+ {
+ puts ("parent: pthread_create failed");
+ exit (1);
+ }
+
+ /* This call should never return. */
+ pthread_join (th1, NULL);
+
+ return 1;
+}
diff --git a/libc/nptl/tst-fork4.c b/libc/nptl/tst-fork4.c
new file mode 100644
index 000000000..cca19f406
--- /dev/null
+++ b/libc/nptl/tst-fork4.c
@@ -0,0 +1,65 @@
+/* Test of fork updating child universe's pthread structures.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <string.h>
+
+
+static int
+do_test (void)
+{
+ pthread_t me = pthread_self ();
+
+ pid_t pid = fork ();
+
+ if (pid < 0)
+ {
+ printf ("fork: %m\n");
+ return 1;
+ }
+
+ if (pid == 0)
+ {
+ int err = pthread_kill (me, SIGTERM);
+ printf ("pthread_kill returned: %s\n", strerror (err));
+ return 3;
+ }
+
+ int status;
+ errno = 0;
+ if (wait (&status) != pid)
+ printf ("wait failed: %m\n");
+ else if (WIFSIGNALED (status) && WTERMSIG (status) == SIGTERM)
+ {
+ printf ("child correctly died with SIGTERM\n");
+ return 0;
+ }
+ else
+ printf ("child died with bad status %#x\n", status);
+
+ return 1;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-getpid1.c b/libc/nptl/tst-getpid1.c
new file mode 100644
index 000000000..f9fd4fc0c
--- /dev/null
+++ b/libc/nptl/tst-getpid1.c
@@ -0,0 +1,115 @@
+#include <sched.h>
+#include <signal.h>
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#ifndef TEST_CLONE_FLAGS
+#define TEST_CLONE_FLAGS 0
+#endif
+
+static int sig;
+
+static int
+f (void *a)
+{
+ puts ("in f");
+ union sigval sival;
+ sival.sival_int = getpid ();
+ printf ("pid = %d\n", sival.sival_int);
+ if (sigqueue (getppid (), sig, sival) != 0)
+ return 1;
+ return 0;
+}
+
+
+static int
+do_test (void)
+{
+ int mypid = getpid ();
+
+ sig = SIGRTMIN;
+ sigset_t ss;
+ sigemptyset (&ss);
+ sigaddset (&ss, sig);
+ if (sigprocmask (SIG_BLOCK, &ss, NULL) != 0)
+ {
+ printf ("sigprocmask failed: %m\n");
+ return 1;
+ }
+
+#ifdef __ia64__
+ extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base,
+ size_t __child_stack_size, int __flags,
+ void *__arg, ...);
+ char st[256 * 1024] __attribute__ ((aligned));
+ pid_t p = __clone2 (f, st, sizeof (st), TEST_CLONE_FLAGS, 0);
+#else
+ char st[128 * 1024] __attribute__ ((aligned));
+ pid_t p = clone (f, st + sizeof (st), TEST_CLONE_FLAGS, 0);
+#endif
+ if (p == -1)
+ {
+ printf("clone failed: %m\n");
+ return 1;
+ }
+ printf ("new thread: %d\n", (int) p);
+
+ siginfo_t si;
+ do
+ if (sigwaitinfo (&ss, &si) < 0)
+ {
+ printf("sigwaitinfo failed: %m\n");
+ kill (p, SIGKILL);
+ return 1;
+ }
+ while (si.si_signo != sig || si.si_code != SI_QUEUE);
+
+ int e;
+ if (waitpid (p, &e, __WCLONE) != p)
+ {
+ puts ("waitpid failed");
+ kill (p, SIGKILL);
+ return 1;
+ }
+ if (!WIFEXITED (e))
+ {
+ if (WIFSIGNALED (e))
+ printf ("died from signal %s\n", strsignal (WTERMSIG (e)));
+ else
+ puts ("did not terminate correctly");
+ return 1;
+ }
+ if (WEXITSTATUS (e) != 0)
+ {
+ printf ("exit code %d\n", WEXITSTATUS (e));
+ return 1;
+ }
+
+ if (si.si_int != (int) p)
+ {
+ printf ("expected PID %d, got si_int %d\n", (int) p, si.si_int);
+ kill (p, SIGKILL);
+ return 1;
+ }
+
+ if (si.si_pid != p)
+ {
+ printf ("expected PID %d, got si_pid %d\n", (int) p, (int) si.si_pid);
+ kill (p, SIGKILL);
+ return 1;
+ }
+
+ if (getpid () != mypid)
+ {
+ puts ("my PID changed");
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-getpid2.c b/libc/nptl/tst-getpid2.c
new file mode 100644
index 000000000..fc98cb60d
--- /dev/null
+++ b/libc/nptl/tst-getpid2.c
@@ -0,0 +1,2 @@
+#define TEST_CLONE_FLAGS CLONE_VM
+#include "tst-getpid1.c"
diff --git a/libc/nptl/tst-getpid3.c b/libc/nptl/tst-getpid3.c
new file mode 100644
index 000000000..f1e77f6b1
--- /dev/null
+++ b/libc/nptl/tst-getpid3.c
@@ -0,0 +1,114 @@
+#include <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+
+static pid_t pid;
+
+static void *
+pid_thread (void *arg)
+{
+ if (pid != getpid ())
+ {
+ printf ("pid wrong in thread: should be %d, is %d\n",
+ (int) pid, (int) getpid ());
+ return (void *) 1L;
+ }
+
+ return NULL;
+}
+
+static int
+do_test (void)
+{
+ pid = getpid ();
+
+ pthread_t thr;
+ int ret = pthread_create (&thr, NULL, pid_thread, NULL);
+ if (ret)
+ {
+ printf ("pthread_create failed: %d\n", ret);
+ return 1;
+ }
+
+ void *thr_ret;
+ ret = pthread_join (thr, &thr_ret);
+ if (ret)
+ {
+ printf ("pthread_create failed: %d\n", ret);
+ return 1;
+ }
+ else if (thr_ret)
+ {
+ printf ("thread getpid failed\n");
+ return 1;
+ }
+
+ pid_t child = fork ();
+ if (child == -1)
+ {
+ printf ("fork failed: %m\n");
+ return 1;
+ }
+ else if (child == 0)
+ {
+ if (pid == getpid ())
+ {
+ puts ("pid did not change after fork");
+ exit (1);
+ }
+
+ pid = getpid ();
+ ret = pthread_create (&thr, NULL, pid_thread, NULL);
+ if (ret)
+ {
+ printf ("pthread_create failed: %d\n", ret);
+ return 1;
+ }
+
+ ret = pthread_join (thr, &thr_ret);
+ if (ret)
+ {
+ printf ("pthread_create failed: %d\n", ret);
+ return 1;
+ }
+ else if (thr_ret)
+ {
+ printf ("thread getpid failed\n");
+ return 1;
+ }
+
+ return 0;
+ }
+
+ int status;
+ if (TEMP_FAILURE_RETRY (waitpid (child, &status, 0)) != child)
+ {
+ puts ("waitpid failed");
+ kill (child, SIGKILL);
+ return 1;
+ }
+
+ if (!WIFEXITED (status))
+ {
+ if (WIFSIGNALED (status))
+ printf ("died from signal %s\n", strsignal (WTERMSIG (status)));
+ else
+ puts ("did not terminate correctly");
+ return 1;
+ }
+ if (WEXITSTATUS (status) != 0)
+ {
+ printf ("exit code %d\n", WEXITSTATUS (status));
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-initializers1-c89.c b/libc/nptl/tst-initializers1-c89.c
new file mode 100644
index 000000000..7c27c1d54
--- /dev/null
+++ b/libc/nptl/tst-initializers1-c89.c
@@ -0,0 +1 @@
+#include "tst-initializers1.c"
diff --git a/libc/nptl/tst-initializers1-c99.c b/libc/nptl/tst-initializers1-c99.c
new file mode 100644
index 000000000..7c27c1d54
--- /dev/null
+++ b/libc/nptl/tst-initializers1-c99.c
@@ -0,0 +1 @@
+#include "tst-initializers1.c"
diff --git a/libc/nptl/tst-initializers1-gnu89.c b/libc/nptl/tst-initializers1-gnu89.c
new file mode 100644
index 000000000..7c27c1d54
--- /dev/null
+++ b/libc/nptl/tst-initializers1-gnu89.c
@@ -0,0 +1 @@
+#include "tst-initializers1.c"
diff --git a/libc/nptl/tst-initializers1-gnu99.c b/libc/nptl/tst-initializers1-gnu99.c
new file mode 100644
index 000000000..7c27c1d54
--- /dev/null
+++ b/libc/nptl/tst-initializers1-gnu99.c
@@ -0,0 +1 @@
+#include "tst-initializers1.c"
diff --git a/libc/nptl/tst-initializers1.c b/libc/nptl/tst-initializers1.c
new file mode 100644
index 000000000..ccd27286e
--- /dev/null
+++ b/libc/nptl/tst-initializers1.c
@@ -0,0 +1,48 @@
+/* Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2005.
+
+ 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>
+
+pthread_mutex_t mtx_normal = PTHREAD_MUTEX_INITIALIZER;
+pthread_mutex_t mtx_recursive = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+pthread_mutex_t mtx_errorchk = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
+pthread_mutex_t mtx_adaptive = PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP;
+pthread_rwlock_t rwl_normal = PTHREAD_RWLOCK_INITIALIZER;
+pthread_rwlock_t rwl_writer
+ = PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP;
+pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+
+int
+main (void)
+{
+ if (mtx_normal.__data.__kind != PTHREAD_MUTEX_TIMED_NP)
+ return 1;
+ if (mtx_recursive.__data.__kind != PTHREAD_MUTEX_RECURSIVE_NP)
+ return 1;
+ if (mtx_errorchk.__data.__kind != PTHREAD_MUTEX_ERRORCHECK_NP)
+ return 1;
+ if (mtx_adaptive.__data.__kind != PTHREAD_MUTEX_ADAPTIVE_NP)
+ return 1;
+ if (rwl_normal.__data.__flags != PTHREAD_RWLOCK_PREFER_READER_NP)
+ return 1;
+ if (rwl_writer.__data.__flags
+ != PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP)
+ return 1;
+ return 0;
+}
diff --git a/libc/nptl/tst-join1.c b/libc/nptl/tst-join1.c
new file mode 100644
index 000000000..95a78ba0b
--- /dev/null
+++ b/libc/nptl/tst-join1.c
@@ -0,0 +1,83 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+
+
+static void *
+tf (void *arg)
+{
+ pthread_t mh = (pthread_t) arg;
+ void *result;
+
+ if (pthread_mutex_unlock (&lock) != 0)
+ {
+ puts ("unlock failed");
+ exit (1);
+ }
+
+ if (pthread_join (mh, &result) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ if (result != (void *) 42l)
+ {
+ printf ("result wrong: expected %p, got %p\n", (void *) 42, result);
+ exit (1);
+ }
+
+ exit (0);
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t th;
+
+ if (pthread_mutex_lock (&lock) != 0)
+ {
+ puts ("1st lock failed");
+ exit (1);
+ }
+
+ if (pthread_create (&th, NULL, tf, (void *) pthread_self ()) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ if (pthread_mutex_lock (&lock) != 0)
+ {
+ puts ("2nd lock failed");
+ exit (1);
+ }
+
+ pthread_exit ((void *) 42);
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-join2.c b/libc/nptl/tst-join2.c
new file mode 100644
index 000000000..2cfab8b0e
--- /dev/null
+++ b/libc/nptl/tst-join2.c
@@ -0,0 +1,104 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+
+static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+
+
+static void *
+tf (void *arg)
+{
+ if (pthread_mutex_lock (&lock) != 0)
+ {
+ puts ("child: mutex_lock failed");
+ return NULL;
+ }
+
+ return (void *) 42l;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t th;
+
+ if (pthread_mutex_lock (&lock) != 0)
+ {
+ puts ("mutex_lock failed");
+ exit (1);
+ }
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("mutex_create failed");
+ exit (1);
+ }
+
+ void *status;
+ int val = pthread_tryjoin_np (th, &status);
+ if (val == 0)
+ {
+ puts ("1st tryjoin succeeded");
+ exit (1);
+ }
+ else if (val != EBUSY)
+ {
+ puts ("1st tryjoin didn't return EBUSY");
+ exit (1);
+ }
+
+ if (pthread_mutex_unlock (&lock) != 0)
+ {
+ puts ("mutex_unlock failed");
+ exit (1);
+ }
+
+ while ((val = pthread_tryjoin_np (th, &status)) != 0)
+ {
+ if (val != EBUSY)
+ {
+ printf ("tryjoin returned %s (%d), expected only 0 or EBUSY\n",
+ strerror (val), val);
+ exit (1);
+ }
+
+ /* Delay minimally. */
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 10000000 };
+ nanosleep (&ts, NULL);
+ }
+
+ if (status != (void *) 42l)
+ {
+ printf ("return value %p, expected %p\n", status, (void *) 42l);
+ exit (1);
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-join3.c b/libc/nptl/tst-join3.c
new file mode 100644
index 000000000..df1135fb5
--- /dev/null
+++ b/libc/nptl/tst-join3.c
@@ -0,0 +1,123 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+
+
+static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+
+
+static void *
+tf (void *arg)
+{
+ if (pthread_mutex_lock (&lock) != 0)
+ {
+ puts ("child: mutex_lock failed");
+ return NULL;
+ }
+
+ return (void *) 42l;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t th;
+
+ if (pthread_mutex_lock (&lock) != 0)
+ {
+ puts ("mutex_lock failed");
+ exit (1);
+ }
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("mutex_create failed");
+ exit (1);
+ }
+
+ void *status;
+ struct timespec ts;
+ struct timeval tv;
+ (void) gettimeofday (&tv, NULL);
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+ ts.tv_nsec += 200000000;
+ if (ts.tv_nsec >= 1000000000)
+ {
+ ts.tv_nsec -= 1000000000;
+ ++ts.tv_sec;
+ }
+ int val = pthread_timedjoin_np (th, &status, &ts);
+ if (val == 0)
+ {
+ puts ("1st timedjoin succeeded");
+ exit (1);
+ }
+ else if (val != ETIMEDOUT)
+ {
+ puts ("1st timedjoin didn't return ETIMEDOUT");
+ exit (1);
+ }
+
+ if (pthread_mutex_unlock (&lock) != 0)
+ {
+ puts ("mutex_unlock failed");
+ exit (1);
+ }
+
+ while (1)
+ {
+ (void) gettimeofday (&tv, NULL);
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+ ts.tv_nsec += 200000000;
+ if (ts.tv_nsec >= 1000000000)
+ {
+ ts.tv_nsec -= 1000000000;
+ ++ts.tv_sec;
+ }
+
+ val = pthread_timedjoin_np (th, &status, &ts);
+ if (val == 0)
+ break;
+
+ if (val != ETIMEDOUT)
+ {
+ printf ("timedjoin returned %s (%d), expected only 0 or ETIMEDOUT\n",
+ strerror (val), val);
+ exit (1);
+ }
+ }
+
+ if (status != (void *) 42l)
+ {
+ printf ("return value %p, expected %p\n", status, (void *) 42l);
+ exit (1);
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-join4.c b/libc/nptl/tst-join4.c
new file mode 100644
index 000000000..b13a51011
--- /dev/null
+++ b/libc/nptl/tst-join4.c
@@ -0,0 +1,125 @@
+/* Copyright (C) 2003, 2004 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+static pthread_barrier_t bar;
+
+
+static void *
+tf (void *arg)
+{
+ if (pthread_barrier_wait (&bar) != 0)
+ {
+ puts ("tf: barrier_wait failed");
+ exit (1);
+ }
+
+ return (void *) 1l;
+}
+
+
+static int
+do_test (void)
+{
+ if (pthread_barrier_init (&bar, NULL, 3) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ pthread_attr_t a;
+
+ if (pthread_attr_init (&a) != 0)
+ {
+ puts ("attr_init failed");
+ exit (1);
+ }
+
+ if (pthread_attr_setstacksize (&a, 1 * 1024 * 1024) != 0)
+ {
+ puts ("attr_setstacksize failed");
+ return 1;
+ }
+
+ pthread_t th[2];
+
+ if (pthread_create (&th[0], &a, tf, NULL) != 0)
+ {
+ puts ("1st create failed");
+ exit (1);
+ }
+
+ if (pthread_attr_setdetachstate (&a, PTHREAD_CREATE_DETACHED) != 0)
+ {
+ puts ("attr_setdetachstate failed");
+ exit (1);
+ }
+
+ if (pthread_create (&th[1], &a, tf, NULL) != 0)
+ {
+ puts ("1st create failed");
+ exit (1);
+ }
+
+ if (pthread_attr_destroy (&a) != 0)
+ {
+ puts ("attr_destroy failed");
+ exit (1);
+ }
+
+ if (pthread_detach (th[0]) != 0)
+ {
+ puts ("could not detach 1st thread");
+ exit (1);
+ }
+
+ int err = pthread_detach (th[0]);
+ if (err == 0)
+ {
+ puts ("second detach of 1st thread succeeded");
+ exit (1);
+ }
+ if (err != EINVAL)
+ {
+ printf ("second detach of 1st thread returned %d, not EINVAL\n", err);
+ exit (1);
+ }
+
+ err = pthread_detach (th[1]);
+ if (err == 0)
+ {
+ puts ("detach of 2nd thread succeeded");
+ exit (1);
+ }
+ if (err != EINVAL)
+ {
+ printf ("detach of 2nd thread returned %d, not EINVAL\n", err);
+ exit (1);
+ }
+
+ exit (0);
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-join5.c b/libc/nptl/tst-join5.c
new file mode 100644
index 000000000..db005f5b7
--- /dev/null
+++ b/libc/nptl/tst-join5.c
@@ -0,0 +1,208 @@
+/* Copyright (C) 2003, 2006 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+
+
+#define wait_code() \
+ do { \
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 200000000 }; \
+ while (syscall (__NR_nanosleep, &ts, &ts) < 0) \
+ /* nothing */; \
+ } while (0)
+
+
+#ifdef WAIT_IN_CHILD
+static pthread_barrier_t b;
+#endif
+
+
+static void *
+tf1 (void *arg)
+{
+#ifdef WAIT_IN_CHILD
+ int e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __func__);
+ exit (1);
+ }
+
+ wait_code ();
+#endif
+
+ pthread_join ((pthread_t) arg, NULL);
+
+ exit (42);
+}
+
+
+static void *
+tf2 (void *arg)
+{
+#ifdef WAIT_IN_CHILD
+ int e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __func__);
+ exit (1);
+ }
+
+ wait_code ();
+#endif
+ pthread_join ((pthread_t) arg, NULL);
+
+ exit (43);
+}
+
+
+static int
+do_test (void)
+{
+#ifdef WAIT_IN_CHILD
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ return 1;
+ }
+#endif
+
+ pthread_t th;
+
+ int err = pthread_join (pthread_self (), NULL);
+ if (err == 0)
+ {
+ puts ("1st circular join succeeded");
+ return 1;
+ }
+ if (err != EDEADLK)
+ {
+ printf ("1st circular join %d, not EDEADLK\n", err);
+ return 1;
+ }
+
+ if (pthread_create (&th, NULL, tf1, (void *) pthread_self ()) != 0)
+ {
+ puts ("1st create failed");
+ return 1;
+ }
+
+#ifndef WAIT_IN_CHILD
+ wait_code ();
+#endif
+
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("cannot cancel 1st thread");
+ return 1;
+ }
+
+#ifdef WAIT_IN_CHILD
+ int e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __func__);
+ return 1;
+ }
+#endif
+
+ void *r;
+ err = pthread_join (th, &r);
+ if (err != 0)
+ {
+ printf ("cannot join 1st thread: %d\n", err);
+ return 1;
+ }
+ if (r != PTHREAD_CANCELED)
+ {
+ puts ("1st thread not canceled");
+ return 1;
+ }
+
+ err = pthread_join (pthread_self (), NULL);
+ if (err == 0)
+ {
+ puts ("2nd circular join succeeded");
+ return 1;
+ }
+ if (err != EDEADLK)
+ {
+ printf ("2nd circular join %d, not EDEADLK\n", err);
+ return 1;
+ }
+
+ if (pthread_create (&th, NULL, tf2, (void *) pthread_self ()) != 0)
+ {
+ puts ("2nd create failed");
+ return 1;
+ }
+
+#ifndef WAIT_IN_CHILD
+ wait_code ();
+#endif
+
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("cannot cancel 2nd thread");
+ return 1;
+ }
+
+#ifdef WAIT_IN_CHILD
+ e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __func__);
+ return 1;
+ }
+#endif
+
+ if (pthread_join (th, &r) != 0)
+ {
+ puts ("cannot join 2nd thread");
+ return 1;
+ }
+ if (r != PTHREAD_CANCELED)
+ {
+ puts ("2nd thread not canceled");
+ return 1;
+ }
+
+ err = pthread_join (pthread_self (), NULL);
+ if (err == 0)
+ {
+ puts ("3rd circular join succeeded");
+ return 1;
+ }
+ if (err != EDEADLK)
+ {
+ printf ("3rd circular join %d, not EDEADLK\n", err);
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-join6.c b/libc/nptl/tst-join6.c
new file mode 100644
index 000000000..0c9e7c056
--- /dev/null
+++ b/libc/nptl/tst-join6.c
@@ -0,0 +1,2 @@
+#define WAIT_IN_CHILD 1
+#include "tst-join5.c"
diff --git a/libc/nptl/tst-key1.c b/libc/nptl/tst-key1.c
new file mode 100644
index 000000000..dfbe58417
--- /dev/null
+++ b/libc/nptl/tst-key1.c
@@ -0,0 +1,89 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <limits.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+int
+do_test (void)
+{
+ int max;
+#ifdef PTHREAD_KEYS_MAX
+ max = PTHREAD_KEYS_MAX;
+#else
+ max = _POSIX_THREAD_KEYS_MAX;
+#endif
+ pthread_key_t *keys = alloca (max * sizeof (pthread_key_t));
+
+ int i;
+ for (i = 0; i < max; ++i)
+ if (pthread_key_create (&keys[i], NULL) != 0)
+ {
+ write (2, "key_create failed\n", 18);
+ _exit (1);
+ }
+ else
+ {
+ printf ("created key %d\n", i);
+
+ if (pthread_setspecific (keys[i], (const void *) (i + 100l)) != 0)
+ {
+ write (2, "setspecific failed\n", 19);
+ _exit (1);
+ }
+ }
+
+ for (i = 0; i < max; ++i)
+ {
+ if (pthread_getspecific (keys[i]) != (void *) (i + 100l))
+ {
+ write (2, "getspecific failed\n", 19);
+ _exit (1);
+ }
+
+ if (pthread_key_delete (keys[i]) != 0)
+ {
+ write (2, "key_delete failed\n", 18);
+ _exit (1);
+ }
+ }
+
+ /* Now it must be once again possible to allocate keys. */
+ if (pthread_key_create (&keys[0], NULL) != 0)
+ {
+ write (2, "2nd key_create failed\n", 22);
+ _exit (1);
+ }
+
+ if (pthread_key_delete (keys[0]) != 0)
+ {
+ write (2, "2nd key_delete failed\n", 22);
+ _exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-key2.c b/libc/nptl/tst-key2.c
new file mode 100644
index 000000000..c5493322c
--- /dev/null
+++ b/libc/nptl/tst-key2.c
@@ -0,0 +1,115 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+#include <unistd.h>
+
+#define N 2
+
+
+static int cnt0;
+static void
+f0 (void *p)
+{
+ ++cnt0;
+}
+
+
+static int cnt1;
+static void
+f1 (void *p)
+{
+ ++cnt1;
+}
+
+
+static void (*fcts[N]) (void *) =
+{
+ f0,
+ f1
+};
+
+
+static void *
+tf (void *arg)
+{
+ pthread_key_t *key = (pthread_key_t *) arg;
+
+ if (pthread_setspecific (*key, (void *) -1l) != 0)
+ {
+ write (2, "setspecific failed\n", 19);
+ _exit (1);
+ }
+
+ return NULL;
+}
+
+
+int
+do_test (void)
+{
+ pthread_key_t keys[N];
+
+ int i;
+ for (i = 0; i < N; ++i)
+ if (pthread_key_create (&keys[i], fcts[i]) != 0)
+ {
+ write (2, "key_create failed\n", 18);
+ _exit (1);
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, &keys[1]) != 0)
+ {
+ write (2, "create failed\n", 14);
+ _exit (1);
+ }
+
+ if (pthread_join (th, NULL) != 0)
+ {
+ write (2, "join failed\n", 12);
+ _exit (1);
+ }
+
+ if (cnt0 != 0)
+ {
+ write (2, "cnt0 != 0\n", 10);
+ _exit (1);
+ }
+
+ if (cnt1 != 1)
+ {
+ write (2, "cnt1 != 1\n", 10);
+ _exit (1);
+ }
+
+ for (i = 0; i < N; ++i)
+ if (pthread_key_delete (keys[i]) != 0)
+ {
+ write (2, "key_delete failed\n", 18);
+ _exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-key3.c b/libc/nptl/tst-key3.c
new file mode 100644
index 000000000..73cb7417a
--- /dev/null
+++ b/libc/nptl/tst-key3.c
@@ -0,0 +1,156 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+#include <unistd.h>
+
+#define N 2
+
+
+static int cnt0;
+static void
+f0 (void *p)
+{
+ ++cnt0;
+}
+
+
+static int cnt1;
+static void
+f1 (void *p)
+{
+ ++cnt1;
+}
+
+
+static void (*fcts[N]) (void *) =
+{
+ f0,
+ f1
+};
+
+
+static pthread_barrier_t b;
+
+
+static void *
+tf (void *arg)
+{
+ pthread_key_t *key = (pthread_key_t *) arg;
+
+ if (pthread_setspecific (*key, (void *) -1l) != 0)
+ {
+ write (2, "setspecific failed\n", 19);
+ _exit (1);
+ }
+
+ pthread_barrier_wait (&b);
+
+ const struct timespec t = { .tv_sec = 1000, .tv_nsec = 0 };
+ while (1)
+ nanosleep (&t, NULL);
+
+ /* NOTREACHED */
+ return NULL;
+}
+
+
+int
+do_test (void)
+{
+ pthread_key_t keys[N];
+
+ int i;
+ for (i = 0; i < N; ++i)
+ if (pthread_key_create (&keys[i], fcts[i]) != 0)
+ {
+ write (2, "key_create failed\n", 18);
+ _exit (1);
+ }
+
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ write (2, "barrier_init failed\n", 20);
+ _exit (1);
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, &keys[1]) != 0)
+ {
+ write (2, "create failed\n", 14);
+ _exit (1);
+ }
+
+ pthread_barrier_wait (&b);
+
+ if (pthread_cancel (th) != 0)
+ {
+ write (2, "cancel failed\n", 14);
+ _exit (1);
+ }
+
+ void *status;
+ if (pthread_join (th, &status) != 0)
+ {
+ write (2, "join failed\n", 12);
+ _exit (1);
+ }
+
+ if (status != PTHREAD_CANCELED)
+ {
+ write (2, "thread not canceled\n", 20);
+ _exit (1);
+ }
+
+ /* Note that the TSD destructors not necessarily have to have
+ finished by the time pthread_join returns. At least according to
+ POSIX. We implement the stronger requirement that they indeed
+ have run and therefore these tests succeed. */
+ if (cnt0 != 0)
+ {
+ write (2, "cnt0 != 0\n", 10);
+ _exit (1);
+ }
+
+ if (cnt1 != 1)
+ {
+ write (2, "cnt1 != 1\n", 10);
+ _exit (1);
+ }
+
+ for (i = 0; i < N; ++i)
+ if (pthread_key_delete (keys[i]) != 0)
+ {
+ write (2, "key_delete failed\n", 18);
+ _exit (1);
+ }
+
+ if (pthread_barrier_destroy (&b) != 0)
+ {
+ write (2, "barrier_destroy failed\n", 23);
+ _exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-key4.c b/libc/nptl/tst-key4.c
new file mode 100644
index 000000000..0a5b448e5
--- /dev/null
+++ b/libc/nptl/tst-key4.c
@@ -0,0 +1,137 @@
+/* Copyright (C) 2003, 2004 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 <limits.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+#ifdef PTHREAD_KEYS_MAX
+const int max = PTHREAD_KEYS_MAX;
+#else
+const int max = _POSIX_THREAD_KEYS_MAX;
+#endif
+static pthread_key_t *keys;
+
+
+static void *
+tf1 (void *arg)
+{
+ int i;
+ for (i = 0; i < max; ++i)
+ if (pthread_setspecific (keys[i], (void *) (long int) (i + 1)) != 0)
+ {
+ puts ("setspecific failed");
+ exit (1);
+ }
+
+ return NULL;
+}
+
+
+static void *
+tf2 (void *arg)
+{
+ int i;
+ for (i = 0; i < max; ++i)
+ if (pthread_getspecific (keys[i]) != NULL)
+ {
+ printf ("getspecific for key %d not NULL\n", i);
+ exit (1);
+ }
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ keys = alloca (max * sizeof (pthread_key_t));
+
+ int i;
+ for (i = 0; i < max; ++i)
+ if (pthread_key_create (&keys[i], NULL) != 0)
+ {
+ puts ("key_create failed");
+ exit (1);
+ }
+
+ pthread_attr_t a;
+
+ if (pthread_attr_init (&a) != 0)
+ {
+ puts ("attr_init failed");
+ exit (1);
+ }
+
+ if (pthread_attr_setstacksize (&a, 1 * 1024 * 1024) != 0)
+ {
+ puts ("attr_setstacksize failed");
+ return 1;
+ }
+
+ for (i = 0; i < 10; ++i)
+ {
+ int j;
+#define N 2
+ pthread_t th[N];
+ for (j = 0; j < N; ++j)
+ if (pthread_create (&th[j], NULL, tf1, NULL) != 0)
+ {
+ puts ("1st create failed");
+ exit (1);
+ }
+
+ for (j = 0; j < N; ++j)
+ if (pthread_join (th[j], NULL) != 0)
+ {
+ puts ("1st join failed");
+ exit (1);
+ }
+
+ for (j = 0; j < N; ++j)
+ if (pthread_create (&th[j], NULL, tf2, NULL) != 0)
+ {
+ puts ("2nd create failed");
+ exit (1);
+ }
+
+ for (j = 0; j < N; ++j)
+ if (pthread_join (th[j], NULL) != 0)
+ {
+ puts ("2nd join failed");
+ exit (1);
+ }
+ }
+
+ if (pthread_attr_destroy (&a) != 0)
+ {
+ puts ("attr_destroy failed");
+ exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-kill1.c b/libc/nptl/tst-kill1.c
new file mode 100644
index 000000000..9eaf29be7
--- /dev/null
+++ b/libc/nptl/tst-kill1.c
@@ -0,0 +1,100 @@
+/* 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>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+static pthread_cond_t c = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
+static pthread_barrier_t b;
+
+static void *
+tf (void *a)
+{
+ if (pthread_mutex_lock (&m) != 0)
+ {
+ puts ("child: mutex_lock failed");
+ exit (1);
+ }
+
+ int e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("child: barrier_wait failed");
+ exit (1);
+ }
+
+ /* This call should never return. */
+ pthread_cond_wait (&c, &m);
+
+ return NULL;
+}
+
+
+int
+do_test (void)
+{
+ pthread_t th;
+
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ int e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ if (pthread_mutex_lock (&m) != 0)
+ {
+ puts ("mutex_lock failed");
+ exit (1);
+ }
+
+ /* Send the thread a signal which it doesn't catch and which will
+ cause the process to terminate. */
+ if (pthread_kill (th, SIGUSR1) != 0)
+ {
+ puts ("kill failed");
+ exit (1);
+ }
+
+ /* This call should never return. */
+ pthread_join (th, NULL);
+
+ return 0;
+}
+
+
+#define EXPECTED_SIGNAL SIGUSR1
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-kill2.c b/libc/nptl/tst-kill2.c
new file mode 100644
index 000000000..1e3dc4104
--- /dev/null
+++ b/libc/nptl/tst-kill2.c
@@ -0,0 +1,139 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/time.h>
+
+
+static pthread_cond_t c = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
+static pthread_barrier_t b;
+
+static void *
+tf (void *a)
+{
+ /* Block SIGUSR1. */
+ sigset_t ss;
+
+ sigemptyset (&ss);
+ sigaddset (&ss, SIGUSR1);
+ if (pthread_sigmask (SIG_BLOCK, &ss, NULL) != 0)
+ {
+ puts ("child: sigmask failed");
+ exit (1);
+ }
+
+ if (pthread_mutex_lock (&m) != 0)
+ {
+ puts ("child: mutex_lock failed");
+ exit (1);
+ }
+
+ int e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("child: barrier_wait failed");
+ exit (1);
+ }
+
+ /* Compute timeout. */
+ struct timeval tv;
+ (void) gettimeofday (&tv, NULL);
+ struct timespec ts;
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+ /* Timeout: 1sec. */
+ ts.tv_sec += 1;
+
+ /* This call should never return. */
+ if (pthread_cond_timedwait (&c, &m, &ts) != ETIMEDOUT)
+ {
+ puts ("cond_timedwait didn't time out");
+ exit (1);
+ }
+
+ return NULL;
+}
+
+
+int
+do_test (void)
+{
+ pthread_t th;
+
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ int e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ if (pthread_mutex_lock (&m) != 0)
+ {
+ puts ("mutex_lock failed");
+ exit (1);
+ }
+
+ /* Send the thread a signal which it has blocked. */
+ if (pthread_kill (th, SIGUSR1) != 0)
+ {
+ puts ("kill failed");
+ exit (1);
+ }
+
+ if (pthread_mutex_unlock (&m) != 0)
+ {
+ puts ("mutex_unlock failed");
+ exit (1);
+ }
+
+ void *r;
+ if (pthread_join (th, &r) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+ if (r != NULL)
+ {
+ puts ("return value wrong");
+ exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TIMEOUT 5
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-kill3.c b/libc/nptl/tst-kill3.c
new file mode 100644
index 000000000..9ea8d553b
--- /dev/null
+++ b/libc/nptl/tst-kill3.c
@@ -0,0 +1,159 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+
+static pthread_cond_t c = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
+static pthread_barrier_t b;
+
+
+static void
+handler (int sig)
+{
+ write (1, "handler called\n", 15);
+ _exit (1);
+}
+
+
+static void *
+tf (void *a)
+{
+ /* Block SIGUSR1. */
+ sigset_t ss;
+
+ sigemptyset (&ss);
+ sigaddset (&ss, SIGUSR1);
+ if (pthread_sigmask (SIG_BLOCK, &ss, NULL) != 0)
+ {
+ puts ("child: sigmask failed");
+ exit (1);
+ }
+
+ if (pthread_mutex_lock (&m) != 0)
+ {
+ puts ("child: mutex_lock failed");
+ exit (1);
+ }
+
+ int e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("child: barrier_wait failed");
+ exit (1);
+ }
+
+ /* Compute timeout. */
+ struct timeval tv;
+ (void) gettimeofday (&tv, NULL);
+ struct timespec ts;
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+ /* Timeout: 1sec. */
+ ts.tv_sec += 1;
+
+ /* This call should never return. */
+ if (pthread_cond_timedwait (&c, &m, &ts) != ETIMEDOUT)
+ {
+ puts ("cond_timedwait didn't time out");
+ exit (1);
+ }
+
+ return NULL;
+}
+
+
+int
+do_test (void)
+{
+ pthread_t th;
+
+ struct sigaction sa;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = handler;
+ if (sigaction (SIGUSR1, &sa, NULL) != 0)
+ {
+ puts ("sigaction failed");
+ exit (1);
+ }
+
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ int e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ if (pthread_mutex_lock (&m) != 0)
+ {
+ puts ("mutex_lock failed");
+ exit (1);
+ }
+
+ /* Send the thread a signal which it has blocked. */
+ if (pthread_kill (th, SIGUSR1) != 0)
+ {
+ puts ("kill failed");
+ exit (1);
+ }
+
+ if (pthread_mutex_unlock (&m) != 0)
+ {
+ puts ("mutex_unlock failed");
+ exit (1);
+ }
+
+ void *r;
+ if (pthread_join (th, &r) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+ if (r != NULL)
+ {
+ puts ("return value wrong");
+ exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TIMEOUT 5
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-kill4.c b/libc/nptl/tst-kill4.c
new file mode 100644
index 000000000..4e7ff5eaf
--- /dev/null
+++ b/libc/nptl/tst-kill4.c
@@ -0,0 +1,74 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static void *
+tf (void *a)
+{
+ return NULL;
+}
+
+
+int
+do_test (void)
+{
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ if (pthread_join (th, NULL) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ /* The following only works because we assume here something about
+ the implementation. Namely, that the memory allocated for the
+ thread descriptor is not going away, that the the TID field is
+ cleared and therefore the signal is sent to process 0, and that
+ we can savely assume there is no other process with this ID at
+ that time. */
+ int e = pthread_kill (th, 0);
+ if (e == 0)
+ {
+ puts ("pthread_kill succeeded");
+ exit (1);
+ }
+ if (e != ESRCH)
+ {
+ puts ("pthread_kill didn't return ESRCH");
+ exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-kill5.c b/libc/nptl/tst-kill5.c
new file mode 100644
index 000000000..12560943c
--- /dev/null
+++ b/libc/nptl/tst-kill5.c
@@ -0,0 +1,49 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+int
+do_test (void)
+{
+ /* XXX This test might require architecture and system specific changes.
+ There is no guarantee that this signal number is invalid. */
+ int e = pthread_kill (pthread_self (), SIGRTMAX + 10);
+ if (e == 0)
+ {
+ puts ("kill didn't failed");
+ exit (1);
+ }
+ if (e != EINVAL)
+ {
+ puts ("error not EINVAL");
+ exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-kill6.c b/libc/nptl/tst-kill6.c
new file mode 100644
index 000000000..26e82d98f
--- /dev/null
+++ b/libc/nptl/tst-kill6.c
@@ -0,0 +1,162 @@
+/* Copyright (C) 2003, 2004 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 <errno.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static pthread_t receiver;
+static sem_t sem;
+static pthread_barrier_t b;
+
+static void
+handler (int sig)
+{
+ if (sig != SIGUSR1)
+ {
+ write (STDOUT_FILENO, "wrong signal\n", 13);
+ _exit (1);
+ }
+
+ if (pthread_self () != receiver)
+ {
+ write (STDOUT_FILENO, "not the intended receiver\n", 26);
+ _exit (1);
+ }
+
+ if (sem_post (&sem) != 0)
+ {
+ write (STDOUT_FILENO, "sem_post failed\n", 16);
+ _exit (1);
+ }
+}
+
+
+static void *
+tf (void *a)
+{
+ int e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("child: barrier_wait failed");
+ exit (1);
+ }
+
+ return NULL;
+}
+
+
+int
+do_test (void)
+{
+ struct sigaction sa;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = handler;
+ if (sigaction (SIGUSR1, &sa, NULL) != 0)
+ {
+ puts ("sigaction failed");
+ exit (1);
+ }
+
+#define N 20
+
+ if (pthread_barrier_init (&b, NULL, N + 1) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ pthread_attr_t a;
+
+ if (pthread_attr_init (&a) != 0)
+ {
+ puts ("attr_init failed");
+ exit (1);
+ }
+
+ if (pthread_attr_setstacksize (&a, 1 * 1024 * 1024) != 0)
+ {
+ puts ("attr_setstacksize failed");
+ return 1;
+ }
+
+ pthread_t th[N];
+ int i;
+ for (i = 0; i < N; ++i)
+ if (pthread_create (&th[i], &a, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ if (pthread_attr_destroy (&a) != 0)
+ {
+ puts ("attr_destroy failed");
+ exit (1);
+ }
+
+ if (sem_init (&sem, 0, 0) != 0)
+ {
+ puts ("sem_init failed");
+ exit (1);
+ }
+
+ for (i = 0; i < N * 10; ++i)
+ {
+ receiver = th[i % N];
+
+ if (pthread_kill (receiver, SIGUSR1) != 0)
+ {
+ puts ("kill failed");
+ exit (1);
+ }
+
+ if (TEMP_FAILURE_RETRY (sem_wait (&sem)) != 0)
+ {
+ puts ("sem_wait failed");
+ exit (1);
+ }
+ }
+
+ int e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ for (i = 0; i < N; ++i)
+ if (pthread_join (th[i], NULL) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-locale1.c b/libc/nptl/tst-locale1.c
new file mode 100644
index 000000000..08b43704e
--- /dev/null
+++ b/libc/nptl/tst-locale1.c
@@ -0,0 +1,17 @@
+/* Test that the thread-local locale works right in the main thread
+ when statically linked. */
+
+#include "../locale/tst-C-locale.c"
+
+#include <pthread.h>
+#include <signal.h>
+
+/* This is never called, just here to get pthreads linked in. */
+int
+useless (void)
+{
+ pthread_create (0, 0, 0, 0);
+ /* This is to check __libc_current_sigrt* can be used in statically
+ linked apps. */
+ return SIGRTMIN;
+}
diff --git a/libc/nptl/tst-locale2.c b/libc/nptl/tst-locale2.c
new file mode 100644
index 000000000..2c803e3ef
--- /dev/null
+++ b/libc/nptl/tst-locale2.c
@@ -0,0 +1,13 @@
+/* Test that the thread-local locale works right in the main thread
+ when statically linked. */
+
+#include "../argp/tst-argp1.c"
+
+#include <pthread.h>
+
+/* This is never called, just here to get pthreads linked in. */
+void
+useless (void)
+{
+ pthread_create (0, 0, 0, 0);
+}
diff --git a/libc/nptl/tst-mutex1.c b/libc/nptl/tst-mutex1.c
new file mode 100644
index 000000000..9453f0491
--- /dev/null
+++ b/libc/nptl/tst-mutex1.c
@@ -0,0 +1,77 @@
+/* Copyright (C) 2002, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+#include <errno.h>
+
+
+#ifndef ATTR
+# define ATTR NULL
+#endif
+
+
+static int
+do_test (void)
+{
+ pthread_mutex_t m;
+
+ int e = pthread_mutex_init (&m, ATTR);
+ if (ATTR != NULL && e == ENOTSUP)
+ {
+ puts ("cannot support selected type of mutexes");
+ return 0;
+ }
+ else if (e != 0)
+ {
+ puts ("mutex_init failed");
+ return 1;
+ }
+
+ if (ATTR != NULL && pthread_mutexattr_destroy (ATTR) != 0)
+ {
+ puts ("mutexattr_destroy failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (&m) != 0)
+ {
+ puts ("mutex_lock failed");
+ return 1;
+ }
+
+ if (pthread_mutex_unlock (&m) != 0)
+ {
+ puts ("mutex_unlock failed");
+ return 1;
+ }
+
+ if (pthread_mutex_destroy (&m) != 0)
+ {
+ puts ("mutex_destroy failed");
+ return 1;
+ }
+
+ return 0;
+}
+
+#ifndef TEST_FUNCTION
+# define TEST_FUNCTION do_test ()
+#endif
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-mutex2.c b/libc/nptl/tst-mutex2.c
new file mode 100644
index 000000000..b09f569a5
--- /dev/null
+++ b/libc/nptl/tst-mutex2.c
@@ -0,0 +1,242 @@
+/* Copyright (C) 2002, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+static pthread_mutex_t m;
+static pthread_barrier_t b;
+
+
+static void *
+tf (void *arg)
+{
+ int e = pthread_mutex_unlock (&m);
+ if (e == 0)
+ {
+ puts ("child: 1st mutex_unlock succeeded");
+ exit (1);
+ }
+ else if (e != EPERM)
+ {
+ puts ("child: 1st mutex_unlock error != EPERM");
+ exit (1);
+ }
+
+ e = pthread_mutex_trylock (&m);
+ if (e == 0)
+ {
+ puts ("child: 1st trylock suceeded");
+ exit (1);
+ }
+ if (e != EBUSY)
+ {
+ puts ("child: 1st trylock didn't return EBUSY");
+ exit (1);
+ }
+
+ e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("child: 1st barrier_wait failed");
+ exit (1);
+ }
+
+ e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("child: 2nd barrier_wait failed");
+ exit (1);
+ }
+
+ e = pthread_mutex_unlock (&m);
+ if (e == 0)
+ {
+ puts ("child: 2nd mutex_unlock succeeded");
+ exit (1);
+ }
+ else if (e != EPERM)
+ {
+ puts ("child: 2nd mutex_unlock error != EPERM");
+ exit (1);
+ }
+
+ if (pthread_mutex_trylock (&m) != 0)
+ {
+ puts ("child: 2nd trylock failed");
+ exit (1);
+ }
+
+ if (pthread_mutex_unlock (&m) != 0)
+ {
+ puts ("child: 3rd mutex_unlock failed");
+ exit (1);
+ }
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_mutexattr_t a;
+ int e;
+
+ if (pthread_mutexattr_init (&a) != 0)
+ {
+ puts ("mutexattr_init failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_settype (&a, PTHREAD_MUTEX_ERRORCHECK) != 0)
+ {
+ puts ("mutexattr_settype failed");
+ return 1;
+ }
+
+#ifdef ENABLE_PI
+ if (pthread_mutexattr_setprotocol (&a, PTHREAD_PRIO_INHERIT) != 0)
+ {
+ puts ("pthread_mutexattr_setprotocol failed");
+ return 1;
+ }
+#endif
+
+ e = pthread_mutex_init (&m, &a);
+ if (e != 0)
+ {
+#ifdef ENABLE_PI
+ if (e == ENOTSUP)
+ {
+ puts ("PI mutexes unsupported");
+ return 0;
+ }
+#endif
+ puts ("mutex_init failed");
+ return 1;
+ }
+
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ return 1;
+ }
+
+ e = pthread_mutex_unlock (&m);
+ if (e == 0)
+ {
+ puts ("1st mutex_unlock succeeded");
+ return 1;
+ }
+ else if (e != EPERM)
+ {
+ puts ("1st mutex_unlock error != EPERM");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (&m) != 0)
+ {
+ puts ("mutex_lock failed");
+ return 1;
+ }
+
+ e = pthread_mutex_lock (&m);
+ if (e == 0)
+ {
+ puts ("2nd mutex_lock succeeded");
+ return 1;
+ }
+ else if (e != EDEADLK)
+ {
+ puts ("2nd mutex_lock error != EDEADLK");
+ return 1;
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ return 1;
+ }
+
+ e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("1st barrier_wait failed");
+ return 1;
+ }
+
+ if (pthread_mutex_unlock (&m) != 0)
+ {
+ puts ("2nd mutex_unlock failed");
+ return 1;
+ }
+
+ e = pthread_mutex_unlock (&m);
+ if (e == 0)
+ {
+ puts ("3rd mutex_unlock succeeded");
+ return 1;
+ }
+ else if (e != EPERM)
+ {
+ puts ("3rd mutex_unlock error != EPERM");
+ return 1;
+ }
+
+ e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("2nd barrier_wait failed");
+ return 1;
+ }
+
+ if (pthread_join (th, NULL) != 0)
+ {
+ puts ("join failed");
+ return 1;
+ }
+
+ if (pthread_mutex_destroy (&m) != 0)
+ {
+ puts ("mutex_destroy failed");
+ return 1;
+ }
+
+ if (pthread_barrier_destroy (&b) != 0)
+ {
+ puts ("barrier_destroy failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_destroy (&a) != 0)
+ {
+ puts ("mutexattr_destroy failed");
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-mutex3.c b/libc/nptl/tst-mutex3.c
new file mode 100644
index 000000000..284809653
--- /dev/null
+++ b/libc/nptl/tst-mutex3.c
@@ -0,0 +1,242 @@
+/* Copyright (C) 2002, 2003, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+static pthread_mutex_t m;
+static pthread_barrier_t b;
+
+
+static void *
+tf (void *arg)
+{
+ int e = pthread_mutex_unlock (&m);
+ if (e == 0)
+ {
+ puts ("1st mutex_unlock in child succeeded");
+ exit (1);
+ }
+ if (e != EPERM)
+ {
+ puts ("1st mutex_unlock in child didn't return EPERM");
+ exit (1);
+ }
+
+ e = pthread_mutex_trylock (&m);
+ if (e == 0)
+ {
+ puts ("mutex_trylock in second thread succeeded");
+ exit (1);
+ }
+ if (e != EBUSY)
+ {
+ puts ("mutex_trylock returned wrong value");
+ exit (1);
+ }
+
+ e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ e = pthread_mutex_unlock (&m);
+ if (e == 0)
+ {
+ puts ("2nd mutex_unlock in child succeeded");
+ exit (1);
+ }
+ if (e != EPERM)
+ {
+ puts ("2nd mutex_unlock in child didn't return EPERM");
+ exit (1);
+ }
+
+ if (pthread_mutex_trylock (&m) != 0)
+ {
+ puts ("2nd mutex_trylock in second thread failed");
+ exit (1);
+ }
+
+ if (pthread_mutex_unlock (&m) != 0)
+ {
+ puts ("3rd mutex_unlock in second thread failed");
+ exit (1);
+ }
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_mutexattr_t a;
+
+ if (pthread_mutexattr_init (&a) != 0)
+ {
+ puts ("mutexattr_init failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_settype (&a, PTHREAD_MUTEX_RECURSIVE) != 0)
+ {
+ puts ("mutexattr_settype failed");
+ return 1;
+ }
+
+#ifdef ENABLE_PI
+ if (pthread_mutexattr_setprotocol (&a, PTHREAD_PRIO_INHERIT) != 0)
+ {
+ puts ("pthread_mutexattr_setprotocol failed");
+ return 1;
+ }
+#endif
+
+ int e;
+ e = pthread_mutex_init (&m, &a);
+ if (e != 0)
+ {
+#ifdef ENABLE_PI
+ if (e == ENOTSUP)
+ {
+ puts ("PI mutexes unsupported");
+ return 0;
+ }
+#endif
+ puts ("mutex_init failed");
+ return 1;
+ }
+
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (&m) != 0)
+ {
+ puts ("mutex_lock failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (&m) != 0)
+ {
+ puts ("2nd mutex_lock failed");
+ return 1;
+ }
+
+ if (pthread_mutex_trylock (&m) != 0)
+ {
+ puts ("1st trylock failed");
+ return 1;
+ }
+
+ if (pthread_mutex_unlock (&m) != 0)
+ {
+ puts ("mutex_unlock failed");
+ return 1;
+ }
+
+ if (pthread_mutex_unlock (&m) != 0)
+ {
+ puts ("2nd mutex_unlock failed");
+ return 1;
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ return 1;
+ }
+
+ e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ return 1;
+ }
+
+ if (pthread_mutex_unlock (&m) != 0)
+ {
+ puts ("3rd mutex_unlock failed");
+ return 1;
+ }
+
+ e = pthread_mutex_unlock (&m);
+ if (e == 0)
+ {
+ puts ("4th mutex_unlock succeeded");
+ return 1;
+ }
+ if (e != EPERM)
+ {
+ puts ("4th mutex_unlock didn't return EPERM");
+ return 1;
+ }
+
+ e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ return 1;
+ }
+
+ if (pthread_join (th, NULL) != 0)
+ {
+ puts ("join failed");
+ return 1;
+ }
+
+ if (pthread_barrier_destroy (&b) != 0)
+ {
+ puts ("barrier_destroy failed");
+ return 1;
+ }
+
+ if (pthread_mutex_destroy (&m) != 0)
+ {
+ puts ("mutex_destroy failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_destroy (&a) != 0)
+ {
+ puts ("mutexattr_destroy failed");
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-mutex4.c b/libc/nptl/tst-mutex4.c
new file mode 100644
index 000000000..9699c2db4
--- /dev/null
+++ b/libc/nptl/tst-mutex4.c
@@ -0,0 +1,278 @@
+/* Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+
+
+static int
+do_test (void)
+{
+ size_t ps = sysconf (_SC_PAGESIZE);
+ char tmpfname[] = "/tmp/tst-mutex4.XXXXXX";
+ char data[ps];
+ void *mem;
+ int fd;
+ pthread_mutex_t *m;
+ pthread_mutexattr_t a;
+ pid_t pid;
+ char *p;
+ int err;
+ int s;
+ pthread_barrier_t *b;
+ pthread_barrierattr_t ba;
+
+ fd = mkstemp (tmpfname);
+ if (fd == -1)
+ {
+ printf ("cannot open temporary file: %m\n");
+ return 1;
+ }
+
+ /* Make sure it is always removed. */
+ unlink (tmpfname);
+
+ /* Create one page of data. */
+ memset (data, '\0', ps);
+
+ /* Write the data to the file. */
+ if (write (fd, data, ps) != (ssize_t) ps)
+ {
+ puts ("short write");
+ return 1;
+ }
+
+ mem = mmap (NULL, ps, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if (mem == MAP_FAILED)
+ {
+ printf ("mmap failed: %m\n");
+ return 1;
+ }
+
+ m = (pthread_mutex_t *) (((uintptr_t) mem + __alignof (pthread_mutex_t) - 1)
+ & ~(__alignof (pthread_mutex_t) - 1));
+ b = (pthread_barrier_t *) (((uintptr_t) (m + 1)
+ + __alignof (pthread_barrier_t) - 1)
+ & ~(__alignof (pthread_barrier_t) - 1));
+ p = (char *) (b + 1);
+
+ if (pthread_mutexattr_init (&a) != 0)
+ {
+ puts ("mutexattr_init failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_getpshared (&a, &s) != 0)
+ {
+ puts ("1st mutexattr_getpshared failed");
+ return 1;
+ }
+
+ if (s != PTHREAD_PROCESS_PRIVATE)
+ {
+ puts ("default pshared value wrong");
+ return 1;
+ }
+
+ if (pthread_mutexattr_setpshared (&a, PTHREAD_PROCESS_SHARED) != 0)
+ {
+ puts ("mutexattr_setpshared failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_getpshared (&a, &s) != 0)
+ {
+ puts ("2nd mutexattr_getpshared failed");
+ return 1;
+ }
+
+ if (s != PTHREAD_PROCESS_SHARED)
+ {
+ puts ("pshared value after setpshared call wrong");
+ return 1;
+ }
+
+#ifdef ENABLE_PI
+ if (pthread_mutexattr_setprotocol (&a, PTHREAD_PRIO_INHERIT) != 0)
+ {
+ puts ("pthread_mutexattr_setprotocol failed");
+ return 1;
+ }
+#endif
+
+ if ((err = pthread_mutex_init (m, &a)) != 0)
+ {
+#ifdef ENABLE_PI
+ if (err == ENOTSUP)
+ {
+ puts ("PI mutexes unsupported");
+ return 0;
+ }
+#endif
+ puts ("mutex_init failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (m) != 0)
+ {
+ puts ("mutex_lock failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_destroy (&a) != 0)
+ {
+ puts ("mutexattr_destroy failed");
+ return 1;
+ }
+
+ if (pthread_barrierattr_init (&ba) != 0)
+ {
+ puts ("barrierattr_init failed");
+ return 1;
+ }
+
+ if (pthread_barrierattr_setpshared (&ba, PTHREAD_PROCESS_SHARED) != 0)
+ {
+ puts ("barrierattr_setpshared failed");
+ return 1;
+ }
+
+ if (pthread_barrier_init (b, &ba, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ return 1;
+ }
+
+ if (pthread_barrierattr_destroy (&ba) != 0)
+ {
+ puts ("barrierattr_destroy failed");
+ return 1;
+ }
+
+ err = pthread_mutex_trylock (m);
+ if (err == 0)
+ {
+ puts ("mutex_trylock succeeded");
+ return 1;
+ }
+ else if (err != EBUSY)
+ {
+ puts ("mutex_trylock didn't return EBUSY");
+ return 1;
+ }
+
+ *p = 0;
+
+ if (pthread_mutex_unlock (m) != 0)
+ {
+ puts ("parent: 1st mutex_unlock failed");
+ return 1;
+ }
+
+ puts ("going to fork now");
+ pid = fork ();
+ if (pid == -1)
+ {
+ puts ("fork failed");
+ return 1;
+ }
+ else if (pid == 0)
+ {
+ if (pthread_mutex_lock (m) != 0)
+ {
+ puts ("child: mutex_lock failed");
+ return 1;
+ }
+
+ int e = pthread_barrier_wait (b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("child: barrier_wait failed");
+ return 1;
+ }
+
+ if ((*p)++ != 0)
+ {
+ puts ("child: *p != 0");
+ return 1;
+ }
+
+ if (pthread_mutex_unlock (m) != 0)
+ {
+ puts ("child: mutex_unlock failed");
+ return 1;
+ }
+
+ puts ("child done");
+ }
+ else
+ {
+ int e = pthread_barrier_wait (b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("parent: barrier_wait failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (m) != 0)
+ {
+ puts ("parent: 2nd mutex_lock failed");
+ return 1;
+ }
+
+ if (*p != 1)
+ {
+ puts ("*p != 1");
+ return 1;
+ }
+
+ if (pthread_mutex_unlock (m) != 0)
+ {
+ puts ("parent: 2nd mutex_unlock failed");
+ return 1;
+ }
+
+ if (pthread_mutex_destroy (m) != 0)
+ {
+ puts ("mutex_destroy failed");
+ return 1;
+ }
+
+ if (pthread_barrier_destroy (b) != 0)
+ {
+ puts ("barrier_destroy failed");
+ return 1;
+ }
+
+ puts ("parent done");
+ }
+
+ return 0;
+}
+
+#define TIMEOUT 4
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-mutex5.c b/libc/nptl/tst-mutex5.c
new file mode 100644
index 000000000..291274fee
--- /dev/null
+++ b/libc/nptl/tst-mutex5.c
@@ -0,0 +1,202 @@
+/* Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+
+#ifndef TYPE
+# define TYPE PTHREAD_MUTEX_NORMAL
+#endif
+
+
+static int
+do_test (void)
+{
+ pthread_mutex_t m;
+ struct timespec ts;
+ struct timeval tv;
+ struct timeval tv2;
+ int err;
+ pthread_mutexattr_t a;
+
+ if (pthread_mutexattr_init (&a) != 0)
+ {
+ puts ("mutexattr_init failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_settype (&a, TYPE) != 0)
+ {
+ puts ("mutexattr_settype failed");
+ return 1;
+ }
+
+#ifdef ENABLE_PI
+ if (pthread_mutexattr_setprotocol (&a, PTHREAD_PRIO_INHERIT) != 0)
+ {
+ puts ("pthread_mutexattr_setprotocol failed");
+ return 1;
+ }
+#endif
+
+ err = pthread_mutex_init (&m, &a);
+ if (err != 0)
+ {
+#ifdef ENABLE_PI
+ if (err == ENOTSUP)
+ {
+ puts ("PI mutexes unsupported");
+ return 0;
+ }
+#endif
+ puts ("mutex_init failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_destroy (&a) != 0)
+ {
+ puts ("mutexattr_destroy failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (&m) != 0)
+ {
+ puts ("mutex_lock failed");
+ return 1;
+ }
+
+ if (pthread_mutex_trylock (&m) == 0)
+ {
+ puts ("mutex_trylock succeeded");
+ return 1;
+ }
+
+ gettimeofday (&tv, NULL);
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+
+ ts.tv_sec += 2; /* Wait 2 seconds. */
+
+ err = pthread_mutex_timedlock (&m, &ts);
+ if (err == 0)
+ {
+ puts ("timedlock succeeded");
+ return 1;
+ }
+ else if (err != ETIMEDOUT)
+ {
+ printf ("timedlock error != ETIMEDOUT: %d\n", err);
+ return 1;
+ }
+ else
+ {
+ int clk_tck = sysconf (_SC_CLK_TCK);
+
+ gettimeofday (&tv2, NULL);
+
+ tv2.tv_sec -= tv.tv_sec;
+ tv2.tv_usec -= tv.tv_usec;
+ if (tv2.tv_usec < 0)
+ {
+ tv2.tv_usec += 1000000;
+ tv2.tv_sec -= 1;
+ }
+
+ /* Be a bit tolerant, add one CLK_TCK. */
+ tv2.tv_usec += 1000000 / clk_tck;
+ if (tv2.tv_usec >= 1000000)
+ {
+ tv2.tv_usec -= 1000000;
+ ++tv2.tv_sec;
+ }
+
+ if (tv2.tv_sec < 2)
+ {
+ printf ("premature timeout: %ld.%06ld difference\n",
+ tv2.tv_sec, tv2.tv_usec);
+ return 1;
+ }
+ }
+
+ (void) gettimeofday (&tv, NULL);
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+
+ ts.tv_sec += 2; /* Wait 2 seconds. */
+ /* The following makes the ts value invalid. */
+ ts.tv_nsec += 1000000000;
+
+ err = pthread_mutex_timedlock (&m, &ts);
+ if (err == 0)
+ {
+ puts ("2nd timedlock succeeded");
+ return 1;
+ }
+ else if (err != EINVAL)
+ {
+ printf ("2nd timedlock error != EINVAL: %d\n", err);
+ return 1;
+ }
+
+ if (pthread_mutex_unlock (&m) != 0)
+ {
+ puts ("mutex_unlock failed");
+ return 1;
+ }
+
+ (void) gettimeofday (&tv, NULL);
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+
+ ts.tv_sec += 2; /* Wait 2 seconds. */
+ if (pthread_mutex_timedlock (&m, &ts) != 0)
+ {
+ puts ("3rd timedlock failed");
+ }
+
+ (void) gettimeofday (&tv2, NULL);
+
+ /* Check that timedlock didn't delay. We use a limit of 0.1 secs. */
+ timersub (&tv2, &tv, &tv2);
+ if (tv2.tv_sec > 0 || tv2.tv_usec > 100000)
+ {
+ puts ("3rd timedlock didn't return right away");
+ return 1;
+ }
+
+ if (pthread_mutex_unlock (&m) != 0)
+ {
+ puts ("final mutex_unlock failed");
+ return 1;
+ }
+
+ if (pthread_mutex_destroy (&m) != 0)
+ {
+ puts ("mutex_destroy failed");
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TIMEOUT 4
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-mutex5a.c b/libc/nptl/tst-mutex5a.c
new file mode 100644
index 000000000..f91eec0d7
--- /dev/null
+++ b/libc/nptl/tst-mutex5a.c
@@ -0,0 +1,2 @@
+#define TYPE PTHREAD_MUTEX_ADAPTIVE_NP
+#include "tst-mutex5.c"
diff --git a/libc/nptl/tst-mutex6.c b/libc/nptl/tst-mutex6.c
new file mode 100644
index 000000000..de64bdb43
--- /dev/null
+++ b/libc/nptl/tst-mutex6.c
@@ -0,0 +1,75 @@
+/* Copyright (C) 2002, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+
+
+#ifndef ATTR
+# define ATTR NULL
+#endif
+
+
+static int
+do_test (void)
+{
+ pthread_mutex_t m;
+
+ int e = pthread_mutex_init (&m, ATTR);
+ if (ATTR != NULL && e == ENOTSUP)
+ {
+ puts ("cannot support selected type of mutexes");
+ e = pthread_mutex_init (&m, NULL);
+ }
+ if (e != 0)
+ {
+ puts ("mutex_init failed");
+ return 1;
+ }
+
+ if (ATTR != NULL && pthread_mutexattr_destroy (ATTR) != 0)
+ {
+ puts ("mutexattr_destroy failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (&m) != 0)
+ {
+ puts ("1st mutex_lock failed");
+ return 1;
+ }
+
+ /* Set an alarm for 1 second. The wrapper will expect this. */
+ alarm (1);
+
+ /* This call should never return. */
+ pthread_mutex_lock (&m);
+
+ puts ("2nd mutex_lock returned");
+ return 1;
+}
+
+#define EXPECTED_SIGNAL SIGALRM
+#ifndef TEST_FUNCTION
+# define TEST_FUNCTION do_test ()
+#endif
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-mutex7.c b/libc/nptl/tst-mutex7.c
new file mode 100644
index 000000000..27e5d8eb2
--- /dev/null
+++ b/libc/nptl/tst-mutex7.c
@@ -0,0 +1,165 @@
+/* Copyright (C) 2002, 2004, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+
+#ifndef TYPE
+# define TYPE PTHREAD_MUTEX_DEFAULT
+#endif
+
+
+static pthread_mutex_t lock;
+
+
+#define ROUNDS 1000
+#define N 100
+
+
+static void *
+tf (void *arg)
+{
+ int nr = (long int) arg;
+ int cnt;
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 11000 };
+
+ for (cnt = 0; cnt < ROUNDS; ++cnt)
+ {
+ if (pthread_mutex_lock (&lock) != 0)
+ {
+ printf ("thread %d: failed to get the lock\n", nr);
+ return (void *) 1l;
+ }
+
+ if (pthread_mutex_unlock (&lock) != 0)
+ {
+ printf ("thread %d: failed to release the lock\n", nr);
+ return (void *) 1l;
+ }
+
+ nanosleep (&ts, NULL);
+ }
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_mutexattr_t a;
+
+ if (pthread_mutexattr_init (&a) != 0)
+ {
+ puts ("mutexattr_init failed");
+ exit (1);
+ }
+
+ if (pthread_mutexattr_settype (&a, TYPE) != 0)
+ {
+ puts ("mutexattr_settype failed");
+ exit (1);
+ }
+
+#ifdef ENABLE_PI
+ if (pthread_mutexattr_setprotocol (&a, PTHREAD_PRIO_INHERIT) != 0)
+ {
+ puts ("pthread_mutexattr_setprotocol failed");
+ return 1;
+ }
+#endif
+
+ int e = pthread_mutex_init (&lock, &a);
+ if (e != 0)
+ {
+#ifdef ENABLE_PI
+ if (e == ENOTSUP)
+ {
+ puts ("PI mutexes unsupported");
+ return 0;
+ }
+#endif
+ puts ("mutex_init failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_destroy (&a) != 0)
+ {
+ puts ("mutexattr_destroy failed");
+ return 1;
+ }
+
+ pthread_attr_t at;
+ pthread_t th[N];
+ int cnt;
+
+ if (pthread_attr_init (&at) != 0)
+ {
+ puts ("attr_init failed");
+ return 1;
+ }
+
+ if (pthread_attr_setstacksize (&at, 1 * 1024 * 1024) != 0)
+ {
+ puts ("attr_setstacksize failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (&lock) != 0)
+ {
+ puts ("locking in parent failed");
+ return 1;
+ }
+
+ for (cnt = 0; cnt < N; ++cnt)
+ if (pthread_create (&th[cnt], &at, tf, (void *) (long int) cnt) != 0)
+ {
+ printf ("creating thread %d failed\n", cnt);
+ return 1;
+ }
+
+ if (pthread_attr_destroy (&at) != 0)
+ {
+ puts ("attr_destroy failed");
+ return 1;
+ }
+
+ if (pthread_mutex_unlock (&lock) != 0)
+ {
+ puts ("unlocking in parent failed");
+ return 1;
+ }
+
+ for (cnt = 0; cnt < N; ++cnt)
+ if (pthread_join (th[cnt], NULL) != 0)
+ {
+ printf ("joining thread %d failed\n", cnt);
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TIMEOUT 60
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-mutex7a.c b/libc/nptl/tst-mutex7a.c
new file mode 100644
index 000000000..30d46b81a
--- /dev/null
+++ b/libc/nptl/tst-mutex7a.c
@@ -0,0 +1,2 @@
+#define TYPE PTHREAD_MUTEX_ADAPTIVE_NP
+#include "tst-mutex7.c"
diff --git a/libc/nptl/tst-mutex8.c b/libc/nptl/tst-mutex8.c
new file mode 100644
index 000000000..80ebe71f0
--- /dev/null
+++ b/libc/nptl/tst-mutex8.c
@@ -0,0 +1,367 @@
+/* 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. */
+
+/* This test checks behavior not required by POSIX. */
+#include <errno.h>
+#include <pthread.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+static pthread_mutex_t *m;
+static pthread_barrier_t b;
+static pthread_cond_t c;
+static bool done;
+
+
+static void
+cl (void *arg)
+{
+ if (pthread_mutex_unlock (m) != 0)
+ {
+ puts ("cl: mutex_unlocked failed");
+ exit (1);
+ }
+}
+
+
+static void *
+tf (void *arg)
+{
+ if (pthread_mutex_lock (m) != 0)
+ {
+ puts ("tf: mutex_lock failed");
+ return (void *) 1l;
+ }
+
+ int e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ return (void *) 1l;
+ }
+
+ if (arg == NULL)
+ do
+ if (pthread_cond_wait (&c, m) != 0)
+ {
+ puts ("tf: cond_wait failed");
+ return (void *) 1l;
+ }
+ while (! done);
+ else
+ do
+ {
+ pthread_cleanup_push (cl, NULL);
+
+ if (pthread_cond_wait (&c, m) != 0)
+ {
+ puts ("tf: cond_wait failed");
+ return (void *) 1l;
+ }
+
+ pthread_cleanup_pop (0);
+ }
+ while (! done);
+
+ if (pthread_mutex_unlock (m) != 0)
+ {
+ puts ("tf: mutex_unlock failed");
+ return (void *) 1l;
+ }
+
+ return NULL;
+}
+
+
+static int
+check_type (const char *mas, pthread_mutexattr_t *ma)
+{
+ if (pthread_mutex_init (m, ma) != 0)
+ {
+ printf ("1st mutex_init failed for %s\n", mas);
+ return 1;
+ }
+
+ if (pthread_mutex_destroy (m) != 0)
+ {
+ printf ("immediate mutex_destroy failed for %s\n", mas);
+ return 1;
+ }
+
+ if (pthread_mutex_init (m, ma) != 0)
+ {
+ printf ("2nd mutex_init failed for %s\n", mas);
+ return 1;
+ }
+
+ if (pthread_mutex_lock (m) != 0)
+ {
+ printf ("1st mutex_lock failed for %s\n", mas);
+ return 1;
+ }
+
+ int e = pthread_mutex_destroy (m);
+ if (e == 0)
+ {
+ printf ("mutex_destroy of self-locked mutex succeeded for %s\n", mas);
+ return 1;
+ }
+ if (e != EBUSY)
+ {
+ printf ("mutex_destroy of self-locked mutex did not return EBUSY %s\n",
+ mas);
+ return 1;
+ }
+
+ if (pthread_mutex_unlock (m) != 0)
+ {
+ printf ("1st mutex_unlock failed for %s\n", mas);
+ return 1;
+ }
+
+ if (pthread_mutex_trylock (m) != 0)
+ {
+ printf ("mutex_trylock failed for %s\n", mas);
+ return 1;
+ }
+
+ e = pthread_mutex_destroy (m);
+ if (e == 0)
+ {
+ printf ("mutex_destroy of self-trylocked mutex succeeded for %s\n", mas);
+ return 1;
+ }
+ if (e != EBUSY)
+ {
+ printf ("\
+mutex_destroy of self-trylocked mutex did not return EBUSY %s\n",
+ mas);
+ return 1;
+ }
+
+ if (pthread_mutex_unlock (m) != 0)
+ {
+ printf ("2nd mutex_unlock failed for %s\n", mas);
+ return 1;
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("1st create failed");
+ return 1;
+ }
+ done = false;
+
+ e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("1st barrier_wait failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (m) != 0)
+ {
+ printf ("2nd mutex_lock failed for %s\n", mas);
+ return 1;
+ }
+
+ if (pthread_mutex_unlock (m) != 0)
+ {
+ printf ("3rd mutex_unlock failed for %s\n", mas);
+ return 1;
+ }
+
+ e = pthread_mutex_destroy (m);
+ if (e == 0)
+ {
+ printf ("mutex_destroy of condvar-used mutex succeeded for %s\n", mas);
+ return 1;
+ }
+ if (e != EBUSY)
+ {
+ printf ("\
+mutex_destroy of condvar-used mutex did not return EBUSY for %s\n", mas);
+ return 1;
+ }
+
+ done = true;
+ if (pthread_cond_signal (&c) != 0)
+ {
+ puts ("cond_signal failed");
+ return 1;
+ }
+
+ void *r;
+ if (pthread_join (th, &r) != 0)
+ {
+ puts ("join failed");
+ return 1;
+ }
+ if (r != NULL)
+ {
+ puts ("thread didn't return NULL");
+ return 1;
+ }
+
+ if (pthread_mutex_destroy (m) != 0)
+ {
+ printf ("mutex_destroy after condvar-use failed for %s\n", mas);
+ return 1;
+ }
+
+ if (pthread_mutex_init (m, ma) != 0)
+ {
+ printf ("3rd mutex_init failed for %s\n", mas);
+ return 1;
+ }
+
+ if (pthread_create (&th, NULL, tf, (void *) 1) != 0)
+ {
+ puts ("2nd create failed");
+ return 1;
+ }
+ done = false;
+
+ e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("2nd barrier_wait failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (m) != 0)
+ {
+ printf ("3rd mutex_lock failed for %s\n", mas);
+ return 1;
+ }
+
+ if (pthread_mutex_unlock (m) != 0)
+ {
+ printf ("4th mutex_unlock failed for %s\n", mas);
+ return 1;
+ }
+
+ e = pthread_mutex_destroy (m);
+ if (e == 0)
+ {
+ printf ("2nd mutex_destroy of condvar-used mutex succeeded for %s\n",
+ mas);
+ return 1;
+ }
+ if (e != EBUSY)
+ {
+ printf ("\
+2nd mutex_destroy of condvar-used mutex did not return EBUSY for %s\n",
+ mas);
+ return 1;
+ }
+
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("cond_cancel failed");
+ return 1;
+ }
+
+ if (pthread_join (th, &r) != 0)
+ {
+ puts ("join failed");
+ return 1;
+ }
+ if (r != PTHREAD_CANCELED)
+ {
+ puts ("thread not canceled");
+ return 1;
+ }
+
+ if (pthread_mutex_destroy (m) != 0)
+ {
+ printf ("mutex_destroy after condvar-canceled failed for %s\n", mas);
+ return 1;
+ }
+
+ return 0;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_mutex_t mm;
+ m = &mm;
+
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ return 1;
+ }
+
+ if (pthread_cond_init (&c, NULL) != 0)
+ {
+ puts ("cond_init failed");
+ return 1;
+ }
+
+ puts ("check normal mutex");
+ int res = check_type ("normal", NULL);
+
+ pthread_mutexattr_t ma;
+ if (pthread_mutexattr_init (&ma) != 0)
+ {
+ puts ("1st mutexattr_init failed");
+ return 1;
+ }
+ if (pthread_mutexattr_settype (&ma, PTHREAD_MUTEX_RECURSIVE) != 0)
+ {
+ puts ("1st mutexattr_settype failed");
+ return 1;
+ }
+ puts ("check recursive mutex");
+ res |= check_type ("recursive", &ma);
+ if (pthread_mutexattr_destroy (&ma) != 0)
+ {
+ puts ("1st mutexattr_destroy failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_init (&ma) != 0)
+ {
+ puts ("2nd mutexattr_init failed");
+ return 1;
+ }
+ if (pthread_mutexattr_settype (&ma, PTHREAD_MUTEX_ERRORCHECK) != 0)
+ {
+ puts ("2nd mutexattr_settype failed");
+ return 1;
+ }
+ puts ("check error-checking mutex");
+ res |= check_type ("error-checking", &ma);
+ if (pthread_mutexattr_destroy (&ma) != 0)
+ {
+ puts ("2nd mutexattr_destroy failed");
+ return 1;
+ }
+
+ return res;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-mutex9.c b/libc/nptl/tst-mutex9.c
new file mode 100644
index 000000000..f9d379343
--- /dev/null
+++ b/libc/nptl/tst-mutex9.c
@@ -0,0 +1,202 @@
+/* Copyright (C) 2003, 2004, 2006 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+
+
+static int
+do_test (void)
+{
+ size_t ps = sysconf (_SC_PAGESIZE);
+ char tmpfname[] = "/tmp/tst-mutex9.XXXXXX";
+ char data[ps];
+ void *mem;
+ int fd;
+ pthread_mutex_t *m;
+ pthread_mutexattr_t a;
+ pid_t pid;
+ char *p;
+
+ fd = mkstemp (tmpfname);
+ if (fd == -1)
+ {
+ printf ("cannot open temporary file: %m\n");
+ return 1;
+ }
+
+ /* Make sure it is always removed. */
+ unlink (tmpfname);
+
+ /* Create one page of data. */
+ memset (data, '\0', ps);
+
+ /* Write the data to the file. */
+ if (write (fd, data, ps) != (ssize_t) ps)
+ {
+ puts ("short write");
+ return 1;
+ }
+
+ mem = mmap (NULL, ps, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if (mem == MAP_FAILED)
+ {
+ printf ("mmap failed: %m\n");
+ return 1;
+ }
+
+ m = (pthread_mutex_t *) (((uintptr_t) mem + __alignof (pthread_mutex_t))
+ & ~(__alignof (pthread_mutex_t) - 1));
+ p = (char *) (m + 1);
+
+ if (pthread_mutexattr_init (&a) != 0)
+ {
+ puts ("mutexattr_init failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_setpshared (&a, PTHREAD_PROCESS_SHARED) != 0)
+ {
+ puts ("mutexattr_setpshared failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_settype (&a, PTHREAD_MUTEX_RECURSIVE) != 0)
+ {
+ puts ("mutexattr_settype failed");
+ return 1;
+ }
+
+#ifdef ENABLE_PI
+ if (pthread_mutexattr_setprotocol (&a, PTHREAD_PRIO_INHERIT) != 0)
+ {
+ puts ("pthread_mutexattr_setprotocol failed");
+ return 1;
+ }
+#endif
+
+ int e;
+ if ((e = pthread_mutex_init (m, &a)) != 0)
+ {
+#ifdef ENABLE_PI
+ if (e == ENOTSUP)
+ {
+ puts ("PI mutexes unsupported");
+ return 0;
+ }
+#endif
+ puts ("mutex_init failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (m) != 0)
+ {
+ puts ("mutex_lock failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_destroy (&a) != 0)
+ {
+ puts ("mutexattr_destroy failed");
+ return 1;
+ }
+
+ puts ("going to fork now");
+ pid = fork ();
+ if (pid == -1)
+ {
+ puts ("fork failed");
+ return 1;
+ }
+ else if (pid == 0)
+ {
+ if (pthread_mutex_trylock (m) == 0)
+ {
+ puts ("child: mutex_trylock succeeded");
+ exit (1);
+ }
+
+ if (pthread_mutex_unlock (m) == 0)
+ {
+ puts ("child: mutex_unlock succeeded");
+ exit (1);
+ }
+
+ struct timeval tv;
+ gettimeofday (&tv, NULL);
+ struct timespec ts;
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+ ts.tv_nsec += 500000000;
+ if (ts.tv_nsec >= 1000000000)
+ {
+ ++ts.tv_sec;
+ ts.tv_nsec -= 1000000000;
+ }
+
+ e = pthread_mutex_timedlock (m, &ts);
+ if (e == 0)
+ {
+ puts ("child: mutex_timedlock succeeded");
+ exit (1);
+ }
+ if (e != ETIMEDOUT)
+ {
+ puts ("child: mutex_timedlock didn't time out");
+ exit (1);
+ }
+
+ alarm (1);
+
+ pthread_mutex_lock (m);
+
+ puts ("child: mutex_lock returned");
+
+ exit (0);
+ }
+
+ sleep (2);
+
+ int status;
+ if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid)
+ {
+ puts ("waitpid failed");
+ return 1;
+ }
+ if (! WIFSIGNALED (status))
+ {
+ puts ("child not killed by signal");
+ return 1;
+ }
+ if (WTERMSIG (status) != SIGALRM)
+ {
+ puts ("child not killed by SIGALRM");
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TIMEOUT 3
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-mutexpi1.c b/libc/nptl/tst-mutexpi1.c
new file mode 100644
index 000000000..623ede9fa
--- /dev/null
+++ b/libc/nptl/tst-mutexpi1.c
@@ -0,0 +1,27 @@
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+static pthread_mutexattr_t a;
+
+static void
+prepare (void)
+{
+ if (pthread_mutexattr_init (&a) != 0)
+ {
+ puts ("mutexattr_init failed");
+ exit (1);
+ }
+
+ if (pthread_mutexattr_setprotocol (&a, PTHREAD_PRIO_INHERIT) != 0)
+ {
+ puts ("mutexattr_setprotocol failed");
+ exit (1);
+ }
+}
+#define PREPARE(argc, argv) prepare ()
+
+
+#define ATTR &a
+#include "tst-mutex1.c"
diff --git a/libc/nptl/tst-mutexpi2.c b/libc/nptl/tst-mutexpi2.c
new file mode 100644
index 000000000..fbe48716f
--- /dev/null
+++ b/libc/nptl/tst-mutexpi2.c
@@ -0,0 +1,2 @@
+#define ENABLE_PI 1
+#include "tst-mutex2.c"
diff --git a/libc/nptl/tst-mutexpi3.c b/libc/nptl/tst-mutexpi3.c
new file mode 100644
index 000000000..e338ebfff
--- /dev/null
+++ b/libc/nptl/tst-mutexpi3.c
@@ -0,0 +1,2 @@
+#define ENABLE_PI 1
+#include "tst-mutex3.c"
diff --git a/libc/nptl/tst-mutexpi4.c b/libc/nptl/tst-mutexpi4.c
new file mode 100644
index 000000000..177b17b47
--- /dev/null
+++ b/libc/nptl/tst-mutexpi4.c
@@ -0,0 +1,2 @@
+#define ENABLE_PI 1
+#include "tst-mutex4.c"
diff --git a/libc/nptl/tst-mutexpi5.c b/libc/nptl/tst-mutexpi5.c
new file mode 100644
index 000000000..287465c23
--- /dev/null
+++ b/libc/nptl/tst-mutexpi5.c
@@ -0,0 +1,2 @@
+#define ENABLE_PI 1
+#include "tst-mutex5.c"
diff --git a/libc/nptl/tst-mutexpi5a.c b/libc/nptl/tst-mutexpi5a.c
new file mode 100644
index 000000000..2f85c94ff
--- /dev/null
+++ b/libc/nptl/tst-mutexpi5a.c
@@ -0,0 +1,2 @@
+#define ENABLE_PI 1
+#include "tst-mutex5a.c"
diff --git a/libc/nptl/tst-mutexpi6.c b/libc/nptl/tst-mutexpi6.c
new file mode 100644
index 000000000..42cda377d
--- /dev/null
+++ b/libc/nptl/tst-mutexpi6.c
@@ -0,0 +1,27 @@
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+static pthread_mutexattr_t a;
+
+static void
+prepare (void)
+{
+ if (pthread_mutexattr_init (&a) != 0)
+ {
+ puts ("mutexattr_init failed");
+ exit (1);
+ }
+
+ if (pthread_mutexattr_setprotocol (&a, PTHREAD_PRIO_INHERIT) != 0)
+ {
+ puts ("mutexattr_setprotocol failed");
+ exit (1);
+ }
+}
+#define PREPARE(argc, argv) prepare ()
+
+
+#define ATTR &a
+#include "tst-mutex6.c"
diff --git a/libc/nptl/tst-mutexpi7.c b/libc/nptl/tst-mutexpi7.c
new file mode 100644
index 000000000..1e7e92938
--- /dev/null
+++ b/libc/nptl/tst-mutexpi7.c
@@ -0,0 +1,2 @@
+#define ENABLE_PI 1
+#include "tst-mutex7.c"
diff --git a/libc/nptl/tst-mutexpi7a.c b/libc/nptl/tst-mutexpi7a.c
new file mode 100644
index 000000000..c59083cf6
--- /dev/null
+++ b/libc/nptl/tst-mutexpi7a.c
@@ -0,0 +1,2 @@
+#define ENABLE_PI 1
+#include "tst-mutex7a.c"
diff --git a/libc/nptl/tst-mutexpi8.c b/libc/nptl/tst-mutexpi8.c
new file mode 100644
index 000000000..cea60309a
--- /dev/null
+++ b/libc/nptl/tst-mutexpi8.c
@@ -0,0 +1,2 @@
+#define ENABLE_PI 1
+#include "tst-mutex8.c"
diff --git a/libc/nptl/tst-mutexpi9.c b/libc/nptl/tst-mutexpi9.c
new file mode 100644
index 000000000..3710d9e08
--- /dev/null
+++ b/libc/nptl/tst-mutexpi9.c
@@ -0,0 +1,2 @@
+#define ENABLE_PI 1
+#include "tst-mutex9.c"
diff --git a/libc/nptl/tst-mutexpp1.c b/libc/nptl/tst-mutexpp1.c
new file mode 100644
index 000000000..9b7d7fe26
--- /dev/null
+++ b/libc/nptl/tst-mutexpp1.c
@@ -0,0 +1,45 @@
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "tst-tpp.h"
+
+static pthread_mutexattr_t a;
+
+static void
+prepare (void)
+{
+ init_tpp_test ();
+
+ if (pthread_mutexattr_init (&a) != 0)
+ {
+ puts ("mutexattr_init failed");
+ exit (1);
+ }
+
+ if (pthread_mutexattr_setprotocol (&a, PTHREAD_PRIO_PROTECT) != 0)
+ {
+ puts ("mutexattr_setprotocol failed");
+ exit (1);
+ }
+
+ if (pthread_mutexattr_setprioceiling (&a, 6) != 0)
+ {
+ puts ("mutexattr_setprioceiling failed");
+ exit (1);
+ }
+}
+#define PREPARE(argc, argv) prepare ()
+
+static int do_test (void);
+
+static int
+do_test_wrapper (void)
+{
+ init_tpp_test ();
+ return do_test ();
+}
+#define TEST_FUNCTION do_test_wrapper ()
+
+#define ATTR &a
+#include "tst-mutex1.c"
diff --git a/libc/nptl/tst-mutexpp10.c b/libc/nptl/tst-mutexpp10.c
new file mode 100644
index 000000000..78281a4d3
--- /dev/null
+++ b/libc/nptl/tst-mutexpp10.c
@@ -0,0 +1,334 @@
+/* Copyright (C) 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2006.
+
+ 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 <errno.h>
+#include <limits.h>
+#include <pthread.h>
+#include <sched.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "tst-tpp.h"
+
+static int
+do_test (void)
+{
+ int ret = 0;
+
+ init_tpp_test ();
+
+ pthread_mutexattr_t ma;
+ if (pthread_mutexattr_init (&ma))
+ {
+ puts ("mutexattr_init failed");
+ return 1;
+ }
+ if (pthread_mutexattr_setprotocol (&ma, PTHREAD_PRIO_PROTECT))
+ {
+ puts ("mutexattr_setprotocol failed");
+ return 1;
+ }
+
+ int prioceiling;
+ if (pthread_mutexattr_getprioceiling (&ma, &prioceiling))
+ {
+ puts ("mutexattr_getprioceiling failed");
+ return 1;
+ }
+
+ if (prioceiling < fifo_min || prioceiling > fifo_max)
+ {
+ printf ("prioceiling %d not in %d..%d range\n",
+ prioceiling, fifo_min, fifo_max);
+ return 1;
+ }
+
+ if (fifo_max < INT_MAX
+ && pthread_mutexattr_setprioceiling (&ma, fifo_max + 1) != EINVAL)
+ {
+ printf ("mutexattr_setprioceiling %d did not fail with EINVAL\n",
+ fifo_max + 1);
+ return 1;
+ }
+
+ if (fifo_min > 0
+ && pthread_mutexattr_setprioceiling (&ma, fifo_min - 1) != EINVAL)
+ {
+ printf ("mutexattr_setprioceiling %d did not fail with EINVAL\n",
+ fifo_min - 1);
+ return 1;
+ }
+
+ if (pthread_mutexattr_setprioceiling (&ma, fifo_min))
+ {
+ puts ("mutexattr_setprioceiling failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_setprioceiling (&ma, fifo_max))
+ {
+ puts ("mutexattr_setprioceiling failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_setprioceiling (&ma, 6))
+ {
+ puts ("mutexattr_setprioceiling failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_getprioceiling (&ma, &prioceiling))
+ {
+ puts ("mutexattr_getprioceiling failed");
+ return 1;
+ }
+
+ if (prioceiling != 6)
+ {
+ printf ("mutexattr_getprioceiling returned %d != 6\n",
+ prioceiling);
+ return 1;
+ }
+
+ pthread_mutex_t m1, m2, m3;
+ int e = pthread_mutex_init (&m1, &ma);
+ if (e == ENOTSUP)
+ {
+ puts ("cannot support selected type of mutexes");
+ return 0;
+ }
+ else if (e != 0)
+ {
+ puts ("mutex_init failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_setprioceiling (&ma, 8))
+ {
+ puts ("mutexattr_setprioceiling failed");
+ return 1;
+ }
+
+ if (pthread_mutex_init (&m2, &ma))
+ {
+ puts ("mutex_init failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_setprioceiling (&ma, 5))
+ {
+ puts ("mutexattr_setprioceiling failed");
+ return 1;
+ }
+
+ if (pthread_mutex_init (&m3, &ma))
+ {
+ puts ("mutex_init failed");
+ return 1;
+ }
+
+ CHECK_TPP_PRIORITY (4, 4);
+
+ if (pthread_mutex_lock (&m1) != 0)
+ {
+ puts ("mutex_lock failed");
+ return 1;
+ }
+
+ CHECK_TPP_PRIORITY (4, 6);
+
+ if (pthread_mutex_trylock (&m2) != 0)
+ {
+ puts ("mutex_lock failed");
+ return 1;
+ }
+
+ CHECK_TPP_PRIORITY (4, 8);
+
+ if (pthread_mutex_lock (&m3) != 0)
+ {
+ puts ("mutex_lock failed");
+ return 1;
+ }
+
+ CHECK_TPP_PRIORITY (4, 8);
+
+ if (pthread_mutex_unlock (&m2) != 0)
+ {
+ puts ("mutex_unlock failed");
+ return 1;
+ }
+
+ CHECK_TPP_PRIORITY (4, 6);
+
+ if (pthread_mutex_unlock (&m1) != 0)
+ {
+ puts ("mutex_unlock failed");
+ return 1;
+ }
+
+ CHECK_TPP_PRIORITY (4, 5);
+
+ if (pthread_mutex_lock (&m2) != 0)
+ {
+ puts ("mutex_lock failed");
+ return 1;
+ }
+
+ CHECK_TPP_PRIORITY (4, 8);
+
+ if (pthread_mutex_unlock (&m2) != 0)
+ {
+ puts ("mutex_unlock failed");
+ return 1;
+ }
+
+ CHECK_TPP_PRIORITY (4, 5);
+
+ if (pthread_mutex_getprioceiling (&m1, &prioceiling))
+ {
+ puts ("mutex_getprioceiling m1 failed");
+ return 1;
+ }
+ else if (prioceiling != 6)
+ {
+ printf ("unexpected m1 prioceiling %d != 6\n", prioceiling);
+ return 1;
+ }
+
+ if (pthread_mutex_getprioceiling (&m2, &prioceiling))
+ {
+ puts ("mutex_getprioceiling m2 failed");
+ return 1;
+ }
+ else if (prioceiling != 8)
+ {
+ printf ("unexpected m2 prioceiling %d != 8\n", prioceiling);
+ return 1;
+ }
+
+ if (pthread_mutex_getprioceiling (&m3, &prioceiling))
+ {
+ puts ("mutex_getprioceiling m3 failed");
+ return 1;
+ }
+ else if (prioceiling != 5)
+ {
+ printf ("unexpected m3 prioceiling %d != 5\n", prioceiling);
+ return 1;
+ }
+
+ if (pthread_mutex_setprioceiling (&m1, 7, &prioceiling))
+ {
+ printf ("mutex_setprioceiling failed");
+ return 1;
+ }
+ else if (prioceiling != 6)
+ {
+ printf ("unexpected m1 old prioceiling %d != 6\n", prioceiling);
+ return 1;
+ }
+
+ if (pthread_mutex_getprioceiling (&m1, &prioceiling))
+ {
+ puts ("mutex_getprioceiling m1 failed");
+ return 1;
+ }
+ else if (prioceiling != 7)
+ {
+ printf ("unexpected m1 prioceiling %d != 7\n", prioceiling);
+ return 1;
+ }
+
+ CHECK_TPP_PRIORITY (4, 5);
+
+ if (pthread_mutex_unlock (&m3) != 0)
+ {
+ puts ("mutex_unlock failed");
+ return 1;
+ }
+
+ CHECK_TPP_PRIORITY (4, 4);
+
+ if (pthread_mutex_trylock (&m1) != 0)
+ {
+ puts ("mutex_lock failed");
+ return 1;
+ }
+
+ CHECK_TPP_PRIORITY (4, 7);
+
+ struct sched_param sp;
+ memset (&sp, 0, sizeof (sp));
+ sp.sched_priority = 8;
+ if (pthread_setschedparam (pthread_self (), SCHED_FIFO, &sp))
+ {
+ puts ("cannot set scheduling params");
+ return 1;
+ }
+
+ CHECK_TPP_PRIORITY (8, 8);
+
+ if (pthread_mutex_unlock (&m1) != 0)
+ {
+ puts ("mutex_unlock failed");
+ return 1;
+ }
+
+ CHECK_TPP_PRIORITY (8, 8);
+
+ if (pthread_mutex_lock (&m3) != EINVAL)
+ {
+ puts ("pthread_mutex_lock didn't fail with EINVAL");
+ return 1;
+ }
+
+ CHECK_TPP_PRIORITY (8, 8);
+
+ if (pthread_mutex_destroy (&m1) != 0)
+ {
+ puts ("mutex_destroy failed");
+ return 1;
+ }
+
+ if (pthread_mutex_destroy (&m2) != 0)
+ {
+ puts ("mutex_destroy failed");
+ return 1;
+ }
+
+ if (pthread_mutex_destroy (&m3) != 0)
+ {
+ puts ("mutex_destroy failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_destroy (&ma) != 0)
+ {
+ puts ("mutexattr_destroy failed");
+ return 1;
+ }
+
+ return ret;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-mutexpp6.c b/libc/nptl/tst-mutexpp6.c
new file mode 100644
index 000000000..2ddf6b45c
--- /dev/null
+++ b/libc/nptl/tst-mutexpp6.c
@@ -0,0 +1,45 @@
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "tst-tpp.h"
+
+static pthread_mutexattr_t a;
+
+static void
+prepare (void)
+{
+ init_tpp_test ();
+
+ if (pthread_mutexattr_init (&a) != 0)
+ {
+ puts ("mutexattr_init failed");
+ exit (1);
+ }
+
+ if (pthread_mutexattr_setprotocol (&a, PTHREAD_PRIO_PROTECT) != 0)
+ {
+ puts ("mutexattr_setprotocol failed");
+ exit (1);
+ }
+
+ if (pthread_mutexattr_setprioceiling (&a, 6) != 0)
+ {
+ puts ("mutexattr_setprioceiling failed");
+ exit (1);
+ }
+}
+#define PREPARE(argc, argv) prepare ()
+
+static int do_test (void);
+
+static int
+do_test_wrapper (void)
+{
+ init_tpp_test ();
+ return do_test ();
+}
+#define TEST_FUNCTION do_test_wrapper ()
+
+#define ATTR &a
+#include "tst-mutex6.c"
diff --git a/libc/nptl/tst-oddstacklimit.c b/libc/nptl/tst-oddstacklimit.c
new file mode 100644
index 000000000..9fbef1889
--- /dev/null
+++ b/libc/nptl/tst-oddstacklimit.c
@@ -0,0 +1 @@
+#include "tst-basic1.c"
diff --git a/libc/nptl/tst-once1.c b/libc/nptl/tst-once1.c
new file mode 100644
index 000000000..87ed51c82
--- /dev/null
+++ b/libc/nptl/tst-once1.c
@@ -0,0 +1,51 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+
+
+static pthread_once_t once = PTHREAD_ONCE_INIT;
+
+static int global;
+
+static void
+once_handler (void)
+{
+ ++global;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_once (&once, once_handler);
+ pthread_once (&once, once_handler);
+
+ if (global != 1)
+ {
+ printf ("global = %d, expected 1\n", global);
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-once2.c b/libc/nptl/tst-once2.c
new file mode 100644
index 000000000..c60634538
--- /dev/null
+++ b/libc/nptl/tst-once2.c
@@ -0,0 +1,104 @@
+/* Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+
+#define N 100
+
+static pthread_once_t once = PTHREAD_ONCE_INIT;
+
+static int global;
+
+static void
+once_handler (void)
+{
+ struct timespec ts;
+
+ ++global;
+
+ ts.tv_sec = 2;
+ ts.tv_nsec = 0;
+ nanosleep (&ts, NULL);
+}
+
+
+static void *
+tf (void *arg)
+{
+ pthread_once (&once, once_handler);
+
+ if (global != 1)
+ {
+ printf ("thread %ld: global == %d\n", (long int) arg, global);
+ exit (1);
+ }
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_attr_t at;
+ pthread_t th[N];
+ int cnt;
+
+ if (pthread_attr_init (&at) != 0)
+ {
+ puts ("attr_init failed");
+ return 1;
+ }
+
+ if (pthread_attr_setstacksize (&at, 1 * 1024 * 1024) != 0)
+ {
+ puts ("attr_setstacksize failed");
+ return 1;
+ }
+
+ for (cnt = 0; cnt < N; ++cnt)
+ if (pthread_create (&th[cnt], &at, tf, (void *) (long int) cnt) != 0)
+ {
+ printf ("creation of thread %d failed\n", cnt);
+ return 1;
+ }
+
+ if (pthread_attr_destroy (&at) != 0)
+ {
+ puts ("attr_destroy failed");
+ return 1;
+ }
+
+ for (cnt = 0; cnt < N; ++cnt)
+ if (pthread_join (th[cnt], NULL) != 0)
+ {
+ printf ("join of thread %d failed\n", cnt);
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#define TIMEOUT 4
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-once3.c b/libc/nptl/tst-once3.c
new file mode 100644
index 000000000..1a74abb53
--- /dev/null
+++ b/libc/nptl/tst-once3.c
@@ -0,0 +1,167 @@
+/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+
+#define N 100
+
+static pthread_once_t once = PTHREAD_ONCE_INIT;
+
+static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+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)
+{
+ if (pthread_mutex_lock (&mut) != 0)
+ {
+ 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)
+ {
+ puts ("once_handler1: barrier_wait failed");
+ exit (1);
+ }
+
+ puts ("once_handler1: going to wait on cond");
+
+ pthread_cond_wait (&cond, &mut);
+
+ /* We should never get here. */
+ exit (42);
+}
+
+static void
+once_handler2 (void)
+{
+ global = 1;
+}
+
+
+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);
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t th;
+
+ if (pthread_barrier_init (&bar, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ return 1;
+ }
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("first create failed");
+ return 1;
+ }
+
+ int r = pthread_barrier_wait (&bar);
+ if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (&mut) != 0)
+ {
+ puts ("mutex_lock failed");
+ 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");
+ return 1;
+ }
+
+ /* Cancel the thread. */
+ puts ("going to cancel");
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("cancel failed");
+ return 1;
+ }
+
+ void *result;
+ pthread_join (th, &result);
+ if (result != PTHREAD_CANCELED)
+ {
+ puts ("join didn't return PTHREAD_CANCELED");
+ return 1;
+ }
+ puts ("joined successfully");
+
+ printf ("once = %d\n", *(int *) &once);
+
+ if (cl_called != 1)
+ {
+ puts ("cleanup handler not called");
+ return 1;
+ }
+
+ pthread_once (&once, once_handler2);
+
+ if (global != 1)
+ {
+ puts ("global still 0");
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#define TIMEOUT 4
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-once4.c b/libc/nptl/tst-once4.c
new file mode 100644
index 000000000..35bae3c0e
--- /dev/null
+++ b/libc/nptl/tst-once4.c
@@ -0,0 +1,202 @@
+/* Copyright (C) 2003, 2004 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>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+
+
+static pthread_once_t once = PTHREAD_ONCE_INIT;
+
+static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+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)
+{
+ if (pthread_mutex_lock (&mut) != 0)
+ {
+ puts ("once_handler1: mutex_lock failed");
+ exit (1);
+ }
+
+ int r = pthread_barrier_wait (&bar);
+ if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("once_handler1: barrier_wait failed");
+ exit (1);
+ }
+
+ pthread_cond_wait (&cond, &mut);
+
+ /* We should never get here. */
+}
+
+
+static void
+once_handler2 (void)
+{
+ global = 1;
+}
+
+
+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);
+}
+
+
+static void *
+tf2 (void *arg)
+{
+ pthread_cleanup_push (cl, NULL);
+
+ int r = pthread_barrier_wait (&bar);
+ if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("once_handler2: barrier_wait failed");
+ exit (1);
+ }
+
+ pthread_cleanup_pop (0);
+
+ pthread_once (&once, once_handler2);
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t th[2];
+
+ if (pthread_barrier_init (&bar, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ return 1;
+ }
+
+ if (pthread_create (&th[0], NULL, tf1, NULL) != 0)
+ {
+ puts ("first create failed");
+ return 1;
+ }
+
+ int r = pthread_barrier_wait (&bar);
+ if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("first barrier_wait failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (&mut) != 0)
+ {
+ puts ("mutex_lock failed");
+ 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");
+ return 1;
+ }
+
+ if (pthread_create (&th[1], NULL, tf2, NULL) != 0)
+ {
+ puts ("second create failed");
+ return 1;
+ }
+
+ r = pthread_barrier_wait (&bar);
+ if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("second barrier_wait failed");
+ return 1;
+ }
+
+ /* Give the second thread a chance to reach the pthread_once call. */
+ sleep (2);
+
+ /* Cancel the thread. */
+ if (pthread_cancel (th[0]) != 0)
+ {
+ puts ("cancel failed");
+ return 1;
+ }
+
+ void *result;
+ pthread_join (th[0], &result);
+ if (result != PTHREAD_CANCELED)
+ {
+ puts ("first join didn't return PTHREAD_CANCELED");
+ return 1;
+ }
+
+ puts ("joined first thread");
+
+ pthread_join (th[1], &result);
+ if (result != NULL)
+ {
+ puts ("second join didn't return PTHREAD_CANCELED");
+ return 1;
+ }
+
+ if (global != 1)
+ {
+ puts ("global still 0");
+ return 1;
+ }
+
+ if (cl_called != 1)
+ {
+ printf ("cl_called = %d\n", cl_called);
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#define TIMEOUT 4
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-oncex3.c b/libc/nptl/tst-oncex3.c
new file mode 100644
index 000000000..08225b88d
--- /dev/null
+++ b/libc/nptl/tst-oncex3.c
@@ -0,0 +1 @@
+#include "tst-once3.c"
diff --git a/libc/nptl/tst-oncex4.c b/libc/nptl/tst-oncex4.c
new file mode 100644
index 000000000..9b4d98f3f
--- /dev/null
+++ b/libc/nptl/tst-oncex4.c
@@ -0,0 +1 @@
+#include "tst-once4.c"
diff --git a/libc/nptl/tst-popen1.c b/libc/nptl/tst-popen1.c
new file mode 100644
index 000000000..a9d077371
--- /dev/null
+++ b/libc/nptl/tst-popen1.c
@@ -0,0 +1,60 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 <errno.h>
+#include <error.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static void *
+dummy (void *x)
+{
+ return NULL;
+}
+
+static char buf[sizeof "something\n"];
+
+static int
+do_test (void)
+{
+ FILE *f;
+ pthread_t p;
+ int err;
+
+ f = popen ("echo something", "r");
+ if (f == NULL)
+ error (EXIT_FAILURE, errno, "popen failed");
+ if (fgets (buf, sizeof (buf), f) == NULL)
+ error (EXIT_FAILURE, 0, "fgets failed");
+ if (strcmp (buf, "something\n"))
+ error (EXIT_FAILURE, 0, "read wrong data");
+ if (pclose (f))
+ error (EXIT_FAILURE, errno, "pclose returned non-zero");
+ if ((err = pthread_create (&p, NULL, dummy, NULL)))
+ error (EXIT_FAILURE, err, "pthread_create failed");
+ if ((err = pthread_join (p, NULL)))
+ error (EXIT_FAILURE, err, "pthread_join failed");
+ exit (0);
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-raise1.c b/libc/nptl/tst-raise1.c
new file mode 100644
index 000000000..5ea9886a4
--- /dev/null
+++ b/libc/nptl/tst-raise1.c
@@ -0,0 +1,62 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 <errno.h>
+#include <error.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+volatile int count;
+
+void
+sh (int sig)
+{
+ ++count;
+}
+
+int
+main (void)
+{
+ struct sigaction sa;
+ sa.sa_handler = sh;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = 0;
+ if (sigaction (SIGUSR1, &sa, NULL) < 0)
+ {
+ printf ("sigaction failed: %m\n");
+ exit (1);
+ }
+ if (raise (SIGUSR1) < 0)
+ {
+ printf ("first raise failed: %m\n");
+ exit (1);
+ }
+ if (raise (SIGUSR1) < 0)
+ {
+ printf ("second raise failed: %m\n");
+ exit (1);
+ }
+ if (count != 2)
+ {
+ printf ("signal handler not called 2 times\n");
+ exit (1);
+ }
+ exit (0);
+}
diff --git a/libc/nptl/tst-robust1.c b/libc/nptl/tst-robust1.c
new file mode 100644
index 000000000..bc48700e4
--- /dev/null
+++ b/libc/nptl/tst-robust1.c
@@ -0,0 +1,339 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2005.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+static pthread_mutex_t m1;
+static pthread_mutex_t m2;
+static pthread_barrier_t b;
+
+
+#ifndef LOCK
+# define LOCK(m) pthread_mutex_lock (m)
+#endif
+
+
+static void *
+tf (void *arg)
+{
+ long int round = (long int) arg;
+
+ if (pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL) != 0)
+ {
+ printf ("%ld: setcancelstate failed\n", round);
+ exit (1);
+ }
+
+ int e = LOCK (&m1);
+ if (e != 0)
+ {
+ printf ("%ld: child: mutex_lock m1 failed with error %d\n", round, e);
+ exit (1);
+ }
+
+ e = LOCK (&m2);
+ if (e != 0)
+ {
+ printf ("%ld: child: mutex_lock m2 failed with error %d\n", round, e);
+ exit (1);
+ }
+
+ e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%ld: child: 1st barrier_wait failed\n", round);
+ exit (1);
+ }
+
+ e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%ld: child: 2nd barrier_wait failed\n", round);
+ exit (1);
+ }
+
+ pthread_testcancel ();
+
+ printf ("%ld: testcancel returned\n", round);
+ exit (1);
+}
+
+
+static int
+do_test (void)
+{
+#ifdef PREPARE_TMO
+ PREPARE_TMO;
+#endif
+
+ pthread_mutexattr_t a;
+ if (pthread_mutexattr_init (&a) != 0)
+ {
+ puts ("mutexattr_init failed");
+ return 1;
+ }
+ if (pthread_mutexattr_setrobust_np (&a, PTHREAD_MUTEX_ROBUST_NP) != 0)
+ {
+ puts ("mutexattr_setrobust failed");
+ return 1;
+ }
+
+#ifdef ENABLE_PI
+ if (pthread_mutexattr_setprotocol (&a, PTHREAD_PRIO_INHERIT) != 0)
+ {
+ puts ("pthread_mutexattr_setprotocol failed");
+ return 1;
+ }
+ else
+ {
+ int e = pthread_mutex_init (&m1, &a);
+ if (e == ENOTSUP)
+ {
+ puts ("PI robust mutexes not supported");
+ return 0;
+ }
+ else if (e != 0)
+ {
+ puts ("mutex_init m1 failed");
+ return 1;
+ }
+ pthread_mutex_destroy (&m1);
+ }
+#endif
+
+#ifndef NOT_CONSISTENT
+ if (pthread_mutex_init (&m1, &a) != 0)
+ {
+ puts ("mutex_init m1 failed");
+ return 1;
+ }
+
+ if (pthread_mutex_init (&m2, &a) != 0)
+ {
+ puts ("mutex_init m2 failed");
+ return 1;
+ }
+#endif
+
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ return 1;
+ }
+
+ for (long int round = 1; round < 5; ++round)
+ {
+#ifdef NOT_CONSISTENT
+ if (pthread_mutex_init (&m1 , &a) != 0)
+ {
+ puts ("mutex_init m1 failed");
+ return 1;
+ }
+ if (pthread_mutex_init (&m2 , &a) != 0)
+ {
+ puts ("mutex_init m2 failed");
+ return 1;
+ }
+#endif
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, (void *) round) != 0)
+ {
+ printf ("%ld: create failed\n", round);
+ return 1;
+ }
+
+ int e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%ld: parent: 1st barrier_wait failed\n", round);
+ return 1;
+ }
+
+ if (pthread_cancel (th) != 0)
+ {
+ printf ("%ld: cancel failed\n", round);
+ return 1;
+ }
+
+ e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%ld: parent: 2nd barrier_wait failed\n", round);
+ return 1;
+ }
+
+#ifndef AFTER_JOIN
+ if (round & 1)
+#endif
+ {
+ void *res;
+ if (pthread_join (th, &res) != 0)
+ {
+ printf ("%ld: join failed\n", round);
+ return 1;
+ }
+ if (res != PTHREAD_CANCELED)
+ {
+ printf ("%ld: thread not canceled\n", round);
+ return 1;
+ }
+ }
+
+ e = LOCK (&m1);
+ if (e == 0)
+ {
+ printf ("%ld: parent: mutex_lock m1 succeeded\n", round);
+ return 1;
+ }
+ if (e != EOWNERDEAD)
+ {
+ printf ("%ld: parent: mutex_lock m1 returned wrong code\n", round);
+ return 1;
+ }
+
+ e = LOCK (&m2);
+ if (e == 0)
+ {
+ printf ("%ld: parent: mutex_lock m2 succeeded\n", round);
+ return 1;
+ }
+ if (e != EOWNERDEAD)
+ {
+ printf ("%ld: parent: mutex_lock m2 returned wrong code\n", round);
+ return 1;
+ }
+
+#ifndef AFTER_JOIN
+ if ((round & 1) == 0)
+ {
+ void *res;
+ if (pthread_join (th, &res) != 0)
+ {
+ printf ("%ld: join failed\n", round);
+ return 1;
+ }
+ if (res != PTHREAD_CANCELED)
+ {
+ printf ("%ld: thread not canceled\n", round);
+ return 1;
+ }
+ }
+#endif
+
+#ifndef NOT_CONSISTENT
+ e = pthread_mutex_consistent_np (&m1);
+ if (e != 0)
+ {
+ printf ("%ld: mutex_consistent m1 failed with error %d\n", round, e);
+ return 1;
+ }
+
+ e = pthread_mutex_consistent_np (&m2);
+ if (e != 0)
+ {
+ printf ("%ld: mutex_consistent m2 failed with error %d\n", round, e);
+ return 1;
+ }
+#endif
+
+ e = pthread_mutex_unlock (&m1);
+ if (e != 0)
+ {
+ printf ("%ld: mutex_unlock m1 failed with %d\n", round, e);
+ return 1;
+ }
+
+ e = pthread_mutex_unlock (&m2);
+ if (e != 0)
+ {
+ printf ("%ld: mutex_unlock m2 failed with %d\n", round, e);
+ return 1;
+ }
+
+#ifdef NOT_CONSISTENT
+ e = LOCK (&m1);
+ if (e == 0)
+ {
+ printf ("%ld: locking inconsistent mutex m1 succeeded\n", round);
+ return 1;
+ }
+ if (e != ENOTRECOVERABLE)
+ {
+ printf ("%ld: locking inconsistent mutex m1 failed with error %d\n",
+ round, e);
+ return 1;
+ }
+
+ if (pthread_mutex_destroy (&m1) != 0)
+ {
+ puts ("mutex_destroy m1 failed");
+ return 1;
+ }
+
+ e = LOCK (&m2);
+ if (e == 0)
+ {
+ printf ("%ld: locking inconsistent mutex m2 succeeded\n", round);
+ return 1;
+ }
+ if (e != ENOTRECOVERABLE)
+ {
+ printf ("%ld: locking inconsistent mutex m2 failed with error %d\n",
+ round, e);
+ return 1;
+ }
+
+ if (pthread_mutex_destroy (&m2) != 0)
+ {
+ puts ("mutex_destroy m2 failed");
+ return 1;
+ }
+#endif
+ }
+
+#ifndef NOT_CONSISTENT
+ if (pthread_mutex_destroy (&m1) != 0)
+ {
+ puts ("mutex_destroy m1 failed");
+ return 1;
+ }
+
+ if (pthread_mutex_destroy (&m2) != 0)
+ {
+ puts ("mutex_destroy m2 failed");
+ return 1;
+ }
+#endif
+
+ if (pthread_mutexattr_destroy (&a) != 0)
+ {
+ puts ("mutexattr_destroy failed");
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-robust2.c b/libc/nptl/tst-robust2.c
new file mode 100644
index 000000000..cf603feb4
--- /dev/null
+++ b/libc/nptl/tst-robust2.c
@@ -0,0 +1,3 @@
+#define AFTER_JOIN 1
+#define LOCK(m) pthread_mutex_trylock (m)
+#include "tst-robust1.c"
diff --git a/libc/nptl/tst-robust3.c b/libc/nptl/tst-robust3.c
new file mode 100644
index 000000000..e56f2762c
--- /dev/null
+++ b/libc/nptl/tst-robust3.c
@@ -0,0 +1,20 @@
+#include <time.h>
+#include <sys/time.h>
+
+
+static struct timespec tmo;
+
+
+#define PREPARE_TMO \
+ do { \
+ struct timeval tv; \
+ gettimeofday (&tv, NULL); \
+ \
+ /* Define the timeout as one hour in the future. */ \
+ tmo.tv_sec = tv.tv_sec + 3600; \
+ tmo.tv_nsec = 0; \
+ } while (0)
+
+
+#define LOCK(m) pthread_mutex_timedlock (m, &tmo)
+#include "tst-robust1.c"
diff --git a/libc/nptl/tst-robust4.c b/libc/nptl/tst-robust4.c
new file mode 100644
index 000000000..b9c42b85b
--- /dev/null
+++ b/libc/nptl/tst-robust4.c
@@ -0,0 +1,2 @@
+#define NOT_CONSISTENT 1
+#include "tst-robust1.c"
diff --git a/libc/nptl/tst-robust5.c b/libc/nptl/tst-robust5.c
new file mode 100644
index 000000000..b83d3d66c
--- /dev/null
+++ b/libc/nptl/tst-robust5.c
@@ -0,0 +1,2 @@
+#define NOT_CONSISTENT 1
+#include "tst-robust2.c"
diff --git a/libc/nptl/tst-robust6.c b/libc/nptl/tst-robust6.c
new file mode 100644
index 000000000..6713396de
--- /dev/null
+++ b/libc/nptl/tst-robust6.c
@@ -0,0 +1,2 @@
+#define NOT_CONSISTENT 1
+#include "tst-robust3.c"
diff --git a/libc/nptl/tst-robust7.c b/libc/nptl/tst-robust7.c
new file mode 100644
index 000000000..d0bc91cc8
--- /dev/null
+++ b/libc/nptl/tst-robust7.c
@@ -0,0 +1,212 @@
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2005.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdbool.h>
+#include <stdio.h>
+
+
+static pthread_barrier_t b;
+static pthread_cond_t c = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t m;
+static bool first = true;
+
+
+static void *
+tf (void *arg)
+{
+ long int n = (long int) arg;
+
+ if (pthread_mutex_lock (&m) != 0)
+ {
+ printf ("thread %ld: mutex_lock failed\n", n + 1);
+ exit (1);
+ }
+
+ int e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("thread %ld: barrier_wait failed\n", n + 1);
+ exit (1);
+ }
+
+ e = pthread_cond_wait (&c, &m);
+ if (first)
+ {
+ if (e != 0)
+ {
+ printf ("thread %ld: cond_wait failed\n", n + 1);
+ exit (1);
+ }
+ first = false;
+ }
+ else
+ {
+ if (e != EOWNERDEAD)
+ {
+ printf ("thread %ld: cond_wait did not return EOWNERDEAD\n", n + 1);
+ exit (1);
+ }
+ }
+
+ if (pthread_cancel (pthread_self ()) != 0)
+ {
+ printf ("thread %ld: cancel failed\n", n + 1);
+ exit (1);
+ }
+
+ pthread_testcancel ();
+
+ printf ("thread %ld: testcancel returned\n", n + 1);
+ exit (1);
+}
+
+
+static int
+do_test (void)
+{
+ pthread_mutexattr_t a;
+ if (pthread_mutexattr_init (&a) != 0)
+ {
+ puts ("mutexattr_init failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_setrobust_np (&a, PTHREAD_MUTEX_ROBUST_NP) != 0)
+ {
+ puts ("mutexattr_setrobust failed");
+ return 1;
+ }
+
+#ifdef ENABLE_PI
+ if (pthread_mutexattr_setprotocol (&a, PTHREAD_PRIO_INHERIT) != 0)
+ {
+ puts ("pthread_mutexattr_setprotocol failed");
+ return 1;
+ }
+#endif
+
+ int e;
+ e = pthread_mutex_init (&m, &a);
+ if (e != 0)
+ {
+#ifdef ENABLE_PI
+ if (e == ENOTSUP)
+ {
+ puts ("PI robust mutexes not supported");
+ return 0;
+ }
+#endif
+ puts ("mutex_init failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_destroy (&a) != 0)
+ {
+ puts ("mutexattr_destroy failed");
+ return 1;
+ }
+
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ return 1;
+ }
+
+#define N 5
+ pthread_t th[N];
+ for (long int n = 0; n < N; ++n)
+ {
+ if (pthread_create (&th[n], NULL, tf, (void *) n) != 0)
+ {
+ printf ("pthread_create loop %ld failed\n", n + 1);
+ return 1;
+ }
+
+ e = pthread_barrier_wait (&b);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("parent: barrier_wait failed in round %ld\n", n + 1);
+ return 1;
+ }
+ }
+
+ if (pthread_mutex_lock (&m) != 0)
+ {
+ puts ("parent: mutex_lock failed");
+ return 1;
+ }
+
+ if (pthread_mutex_unlock (&m) != 0)
+ {
+ puts ("parent: mutex_unlock failed");
+ return 1;
+ }
+
+ if (pthread_cond_broadcast (&c) != 0)
+ {
+ puts ("cond_broadcast failed");
+ return 1;
+ }
+
+ for (int n = 0; n < N; ++n)
+ {
+ void *res;
+ if (pthread_join (th[n], &res) != 0)
+ {
+ printf ("join round %d failed\n", n + 1);
+ return 1;
+ }
+ if (res != PTHREAD_CANCELED)
+ {
+ printf ("thread %d not canceled\n", n + 1);
+ return 1;
+ }
+ }
+
+ e = pthread_mutex_lock (&m);
+ if (e == 0)
+ {
+ puts ("parent: 2nd mutex_lock succeeded");
+ return 1;
+ }
+ if (e != EOWNERDEAD)
+ {
+ puts ("parent: mutex_lock did not return EOWNERDEAD");
+ return 1;
+ }
+
+ if (pthread_mutex_unlock (&m) != 0)
+ {
+ puts ("parent: 2nd mutex_unlock failed");
+ return 1;
+ }
+
+ if (pthread_mutex_destroy (&m) != 0)
+ {
+ puts ("mutex_destroy failed");
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-robust8.c b/libc/nptl/tst-robust8.c
new file mode 100644
index 000000000..9c636250d
--- /dev/null
+++ b/libc/nptl/tst-robust8.c
@@ -0,0 +1,275 @@
+#include <pthread.h>
+#include <signal.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+
+
+
+
+static void prepare (void);
+#define PREPARE(argc, argv) prepare ()
+static int do_test (void);
+#define TEST_FUNCTION do_test ()
+#define TIMEOUT 5
+#include "../test-skeleton.c"
+
+
+static int fd;
+#define N 100
+
+static void
+prepare (void)
+{
+ fd = create_temp_file ("tst-robust8", NULL);
+ if (fd == -1)
+ exit (1);
+}
+
+
+#define THESIGNAL SIGKILL
+#define ROUNDS 5
+#define THREADS 9
+
+
+static const struct timespec before = { 0, 0 };
+
+
+static pthread_mutex_t *map;
+
+
+static void *
+tf (void *arg)
+{
+ long int nr = (long int) arg;
+ int fct = nr % 3;
+
+ uint8_t state[N];
+ memset (state, '\0', sizeof (state));
+
+ while (1)
+ {
+ int r = random () % N;
+ if (state[r] == 0)
+ {
+ int e;
+
+ switch (fct)
+ {
+ case 0:
+ e = pthread_mutex_lock (&map[r]);
+ if (e != 0)
+ {
+ printf ("mutex_lock of %d in thread %ld failed with %d\n",
+ r, nr, e);
+ exit (1);
+ }
+ state[r] = 1;
+ break;
+ case 1:
+ e = pthread_mutex_timedlock (&map[r], &before);
+ if (e != 0 && e != ETIMEDOUT)
+ {
+ printf ("\
+mutex_timedlock of %d in thread %ld failed with %d\n",
+ r, nr, e);
+ exit (1);
+ }
+ break;
+ default:
+ e = pthread_mutex_trylock (&map[r]);
+ if (e != 0 && e != EBUSY)
+ {
+ printf ("mutex_trylock of %d in thread %ld failed with %d\n",
+ r, nr, e);
+ exit (1);
+ }
+ break;
+ }
+
+ if (e == EOWNERDEAD)
+ pthread_mutex_consistent_np (&map[r]);
+
+ if (e == 0 || e == EOWNERDEAD)
+ state[r] = 1;
+ }
+ else
+ {
+ int e = pthread_mutex_unlock (&map[r]);
+ if (e != 0)
+ {
+ printf ("mutex_unlock of %d in thread %ld failed with %d\n",
+ r, nr, e);
+ exit (1);
+ }
+
+ state[r] = 0;
+ }
+ }
+}
+
+
+static void
+child (int round)
+{
+ for (int thread = 1; thread <= THREADS; ++thread)
+ {
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, (void *) (long int) thread) != 0)
+ {
+ printf ("cannot create thread %d in round %d\n", thread, round);
+ exit (1);
+ }
+ }
+
+ struct timespec ts;
+ ts.tv_sec = 0;
+ ts.tv_nsec = 1000000000 / ROUNDS;
+ while (nanosleep (&ts, &ts) != 0)
+ /* nothing */;
+
+ /* Time to die. */
+ kill (getpid (), THESIGNAL);
+
+ /* We better never get here. */
+ abort ();
+}
+
+
+static int
+do_test (void)
+{
+ if (ftruncate (fd, N * sizeof (pthread_mutex_t)) != 0)
+ {
+ puts ("cannot size new file");
+ return 1;
+ }
+
+ map = mmap (NULL, N * sizeof (pthread_mutex_t), PROT_READ | PROT_WRITE,
+ MAP_SHARED, fd, 0);
+ if (map == MAP_FAILED)
+ {
+ puts ("mapping failed");
+ return 1;
+ }
+
+ pthread_mutexattr_t ma;
+ if (pthread_mutexattr_init (&ma) != 0)
+ {
+ puts ("mutexattr_init failed");
+ return 0;
+ }
+ if (pthread_mutexattr_setrobust_np (&ma, PTHREAD_MUTEX_ROBUST_NP) != 0)
+ {
+ puts ("mutexattr_setrobust failed");
+ return 1;
+ }
+ if (pthread_mutexattr_setpshared (&ma, PTHREAD_PROCESS_SHARED) != 0)
+ {
+ puts ("mutexattr_setpshared failed");
+ return 1;
+ }
+#ifdef ENABLE_PI
+ if (pthread_mutexattr_setprotocol (&ma, PTHREAD_PRIO_INHERIT) != 0)
+ {
+ puts ("pthread_mutexattr_setprotocol failed");
+ return 1;
+ }
+#endif
+
+ for (int round = 1; round <= ROUNDS; ++round)
+ {
+ for (int n = 0; n < N; ++n)
+ {
+ int e = pthread_mutex_init (&map[n], &ma);
+ if (e == ENOTSUP)
+ {
+#ifdef ENABLE_PI
+ puts ("cannot support pshared robust PI mutexes");
+#else
+ puts ("cannot support pshared robust mutexes");
+#endif
+ return 0;
+ }
+ if (e != 0)
+ {
+ printf ("mutex_init %d in round %d failed\n", n + 1, round);
+ return 1;
+ }
+ }
+
+ pid_t p = fork ();
+ if (p == -1)
+ {
+ printf ("fork in round %d failed\n", round);
+ return 1;
+ }
+ if (p == 0)
+ child (round);
+
+ int status;
+ if (TEMP_FAILURE_RETRY (waitpid (p, &status, 0)) != p)
+ {
+ printf ("waitpid in round %d failed\n", round);
+ return 1;
+ }
+ if (!WIFSIGNALED (status))
+ {
+ printf ("child did not die of a signal in round %d\n", round);
+ return 1;
+ }
+ if (WTERMSIG (status) != THESIGNAL)
+ {
+ printf ("child did not die of signal %d in round %d\n",
+ THESIGNAL, round);
+ return 1;
+ }
+
+ for (int n = 0; n < N; ++n)
+ {
+ int e = pthread_mutex_lock (&map[n]);
+ if (e != 0 && e != EOWNERDEAD)
+ {
+ printf ("mutex_lock %d failed in round %d\n", n + 1, round);
+ return 1;
+ }
+ }
+
+ for (int n = 0; n < N; ++n)
+ if (pthread_mutex_unlock (&map[n]) != 0)
+ {
+ printf ("mutex_unlock %d failed in round %d\n", n + 1, round);
+ return 1;
+ }
+
+ for (int n = 0; n < N; ++n)
+ {
+ int e = pthread_mutex_destroy (&map[n]);
+ if (e != 0)
+ {
+ printf ("mutex_destroy %d in round %d failed with %d\n",
+ n + 1, round, e);
+ printf("nusers = %d\n", (int) map[n].__data.__nusers);
+ return 1;
+ }
+ }
+ }
+
+ if (pthread_mutexattr_destroy (&ma) != 0)
+ {
+ puts ("mutexattr_destroy failed");
+ return 1;
+ }
+
+ if (munmap (map, N * sizeof (pthread_mutex_t)) != 0)
+ {
+ puts ("munmap failed");
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/libc/nptl/tst-robustpi1.c b/libc/nptl/tst-robustpi1.c
new file mode 100644
index 000000000..031291b29
--- /dev/null
+++ b/libc/nptl/tst-robustpi1.c
@@ -0,0 +1,2 @@
+#define ENABLE_PI 1
+#include "tst-robust1.c"
diff --git a/libc/nptl/tst-robustpi2.c b/libc/nptl/tst-robustpi2.c
new file mode 100644
index 000000000..ac411c773
--- /dev/null
+++ b/libc/nptl/tst-robustpi2.c
@@ -0,0 +1,2 @@
+#define ENABLE_PI 1
+#include "tst-robust2.c"
diff --git a/libc/nptl/tst-robustpi3.c b/libc/nptl/tst-robustpi3.c
new file mode 100644
index 000000000..7dcf691e8
--- /dev/null
+++ b/libc/nptl/tst-robustpi3.c
@@ -0,0 +1,2 @@
+#define ENABLE_PI 1
+#include "tst-robust3.c"
diff --git a/libc/nptl/tst-robustpi4.c b/libc/nptl/tst-robustpi4.c
new file mode 100644
index 000000000..6c7b0aa7b
--- /dev/null
+++ b/libc/nptl/tst-robustpi4.c
@@ -0,0 +1,2 @@
+#define ENABLE_PI 1
+#include "tst-robust4.c"
diff --git a/libc/nptl/tst-robustpi5.c b/libc/nptl/tst-robustpi5.c
new file mode 100644
index 000000000..a494c332f
--- /dev/null
+++ b/libc/nptl/tst-robustpi5.c
@@ -0,0 +1,2 @@
+#define ENABLE_PI 1
+#include "tst-robust5.c"
diff --git a/libc/nptl/tst-robustpi6.c b/libc/nptl/tst-robustpi6.c
new file mode 100644
index 000000000..3b1482fc2
--- /dev/null
+++ b/libc/nptl/tst-robustpi6.c
@@ -0,0 +1,2 @@
+#define ENABLE_PI 1
+#include "tst-robust6.c"
diff --git a/libc/nptl/tst-robustpi7.c b/libc/nptl/tst-robustpi7.c
new file mode 100644
index 000000000..f8892f352
--- /dev/null
+++ b/libc/nptl/tst-robustpi7.c
@@ -0,0 +1,2 @@
+#define ENABLE_PI 1
+#include "tst-robust7.c"
diff --git a/libc/nptl/tst-robustpi8.c b/libc/nptl/tst-robustpi8.c
new file mode 100644
index 000000000..cbea3d6d7
--- /dev/null
+++ b/libc/nptl/tst-robustpi8.c
@@ -0,0 +1,2 @@
+#define ENABLE_PI 1
+#include "tst-robust8.c"
diff --git a/libc/nptl/tst-rwlock1.c b/libc/nptl/tst-rwlock1.c
new file mode 100644
index 000000000..c97e0e60f
--- /dev/null
+++ b/libc/nptl/tst-rwlock1.c
@@ -0,0 +1,117 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+
+
+static int
+do_test (void)
+{
+ pthread_rwlock_t r;
+
+ if (pthread_rwlock_init (&r, NULL) != 0)
+ {
+ puts ("rwlock_init failed");
+ return 1;
+ }
+ puts ("rwlock_init succeeded");
+
+ if (pthread_rwlock_rdlock (&r) != 0)
+ {
+ puts ("1st rwlock_rdlock failed");
+ return 1;
+ }
+ puts ("1st rwlock_rdlock succeeded");
+
+ if (pthread_rwlock_rdlock (&r) != 0)
+ {
+ puts ("2nd rwlock_rdlock failed");
+ return 1;
+ }
+ puts ("2nd rwlock_rdlock succeeded");
+
+ if (pthread_rwlock_unlock (&r) != 0)
+ {
+ puts ("1st rwlock_unlock failed");
+ return 1;
+ }
+ puts ("1st rwlock_unlock succeeded");
+
+ if (pthread_rwlock_unlock (&r) != 0)
+ {
+ puts ("2nd rwlock_unlock failed");
+ return 1;
+ }
+ puts ("2nd rwlock_unlock succeeded");
+
+ if (pthread_rwlock_wrlock (&r) != 0)
+ {
+ puts ("1st rwlock_wrlock failed");
+ return 1;
+ }
+ puts ("1st rwlock_wrlock succeeded");
+
+ if (pthread_rwlock_unlock (&r) != 0)
+ {
+ puts ("3rd rwlock_unlock failed");
+ return 1;
+ }
+ puts ("3rd rwlock_unlock succeeded");
+
+ if (pthread_rwlock_wrlock (&r) != 0)
+ {
+ puts ("2nd rwlock_wrlock failed");
+ return 1;
+ }
+ puts ("2nd rwlock_wrlock succeeded");
+
+ if (pthread_rwlock_unlock (&r) != 0)
+ {
+ puts ("4th rwlock_unlock failed");
+ return 1;
+ }
+ puts ("4th rwlock_unlock succeeded");
+
+ if (pthread_rwlock_rdlock (&r) != 0)
+ {
+ puts ("3rd rwlock_rdlock failed");
+ return 1;
+ }
+ puts ("3rd rwlock_rdlock succeeded");
+
+ if (pthread_rwlock_unlock (&r) != 0)
+ {
+ puts ("5th rwlock_unlock failed");
+ return 1;
+ }
+ puts ("5th rwlock_unlock succeeded");
+
+ if (pthread_rwlock_destroy (&r) != 0)
+ {
+ puts ("rwlock_destroy failed");
+ return 1;
+ }
+ puts ("rwlock_destroy succeeded");
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-rwlock10.c b/libc/nptl/tst-rwlock10.c
new file mode 100644
index 000000000..43156eae6
--- /dev/null
+++ b/libc/nptl/tst-rwlock10.c
@@ -0,0 +1,21 @@
+/* Test program for timedout read/write lock functions.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#define INIT PTHREAD_RWLOCK_INITIALIZER
+#include "tst-rwlock8.c"
diff --git a/libc/nptl/tst-rwlock11.c b/libc/nptl/tst-rwlock11.c
new file mode 100644
index 000000000..ed9af7edc
--- /dev/null
+++ b/libc/nptl/tst-rwlock11.c
@@ -0,0 +1,21 @@
+/* Test program for timedout read/write lock functions.
+ Copyright (C) 2003 Free Software Foundation, Inc.
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#define INIT PTHREAD_RWLOCK_INITIALIZER
+#include "tst-rwlock9.c"
diff --git a/libc/nptl/tst-rwlock12.c b/libc/nptl/tst-rwlock12.c
new file mode 100644
index 000000000..91f25d3b1
--- /dev/null
+++ b/libc/nptl/tst-rwlock12.c
@@ -0,0 +1,208 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+
+
+static int
+do_test (void)
+{
+ size_t ps = sysconf (_SC_PAGESIZE);
+ char tmpfname[] = "/tmp/tst-rwlock12.XXXXXX";
+ char data[ps];
+ void *mem;
+ int fd;
+ pthread_mutex_t *m;
+ pthread_mutexattr_t ma;
+ pthread_rwlock_t *r;
+ pthread_rwlockattr_t ra;
+ pid_t pid;
+ int status = 0;
+
+ fd = mkstemp (tmpfname);
+ if (fd == -1)
+ {
+ printf ("cannot open temporary file: %m\n");
+ return 1;
+ }
+
+ /* Make sure it is always removed. */
+ unlink (tmpfname);
+
+ /* Create one page of data. */
+ memset (data, '\0', ps);
+
+ /* Write the data to the file. */
+ if (write (fd, data, ps) != (ssize_t) ps)
+ {
+ puts ("short write");
+ return 1;
+ }
+
+ mem = mmap (NULL, ps, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if (mem == MAP_FAILED)
+ {
+ printf ("mmap failed: %m\n");
+ return 1;
+ }
+
+ r = (pthread_rwlock_t *) (((uintptr_t) mem + __alignof (pthread_rwlock_t))
+ & ~(__alignof (pthread_rwlock_t) - 1));
+ /* The following assumes alignment for a mutex is at least as high
+ as that for a rwlock. Which is true in our case. */
+ m = (pthread_mutex_t *) (r + 1);
+
+ if (pthread_rwlockattr_init (&ra) != 0)
+ {
+ puts ("rwlockattr_init failed");
+ return 1;
+ }
+
+ if (pthread_rwlockattr_setpshared (&ra, PTHREAD_PROCESS_SHARED) != 0)
+ {
+ puts ("rwlockattr_setpshared failed");
+ return 1;
+ }
+
+ if (pthread_rwlock_init (r, &ra) != 0)
+ {
+ puts ("rwlock_init failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_init (&ma) != 0)
+ {
+ puts ("rwlockattr_init failed");
+ return 1;
+ }
+
+ if (pthread_mutexattr_setpshared (&ma, PTHREAD_PROCESS_SHARED) != 0)
+ {
+ puts ("mutexattr_setpshared failed");
+ return 1;
+ }
+
+ if (pthread_mutex_init (m, &ma) != 0)
+ {
+ puts ("mutex_init failed");
+ return 1;
+ }
+
+ /* Lock the mutex. */
+ if (pthread_mutex_lock (m) != 0)
+ {
+ puts ("mutex_lock failed");
+ return 1;
+ }
+
+ puts ("going to fork now");
+ pid = fork ();
+ if (pid == -1)
+ {
+ puts ("fork failed");
+ return 1;
+ }
+ else if (pid == 0)
+ {
+ /* Lock the mutex. */
+ if (pthread_mutex_lock (m) != 0)
+ {
+ puts ("child: mutex_lock failed");
+ return 1;
+ }
+
+ /* Try to get the rwlock. */
+ if (pthread_rwlock_trywrlock (r) == 0)
+ {
+ puts ("rwlock_trywrlock succeeded");
+ return 1;
+ }
+
+ /* Try again. */
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 500000000 };
+ int e = pthread_rwlock_timedwrlock (r, &ts);
+ if (e == 0)
+ {
+ puts ("rwlock_timedwrlock succeeded");
+ return 1;
+ }
+ if (e != ETIMEDOUT)
+ {
+ puts ("rwlock_timedwrlock didn't return ETIMEDOUT");
+ status = 1;
+ }
+
+ if (pthread_rwlock_tryrdlock (r) == 0)
+ {
+ puts ("rwlock_tryrdlock succeeded");
+ return 1;
+ }
+
+ e = pthread_rwlock_timedrdlock (r, &ts);
+ if (e == 0)
+ {
+ puts ("rwlock_timedrdlock succeeded");
+ return 1;
+ }
+ if (e != ETIMEDOUT)
+ {
+ puts ("rwlock_timedrdlock didn't return ETIMEDOUT");
+ status = 1;
+ }
+ }
+ else
+ {
+ /* Lock the rwlock for writing. */
+ if (pthread_rwlock_wrlock (r) != 0)
+ {
+ puts ("rwlock_wrlock failed");
+ kill (pid, SIGTERM);
+ return 1;
+ }
+
+ /* Allow the child to run. */
+ if (pthread_mutex_unlock (m) != 0)
+ {
+ puts ("mutex_unlock failed");
+ kill (pid, SIGTERM);
+ return 1;
+ }
+
+ /* Just wait for the child. */
+ if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid)
+ {
+ puts ("waitpid failed");
+ kill (pid, SIGTERM);
+ return 1;
+ }
+ }
+
+ return status;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-rwlock13.c b/libc/nptl/tst-rwlock13.c
new file mode 100644
index 000000000..61d5b83e1
--- /dev/null
+++ b/libc/nptl/tst-rwlock13.c
@@ -0,0 +1,71 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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>
+#include <stdio.h>
+#include <string.h>
+
+
+static int
+do_test (void)
+{
+ pthread_rwlock_t r;
+ int ret;
+
+ memset (&r, 0xaa, sizeof (r));
+ if ((ret = pthread_rwlock_init (&r, NULL)) != 0)
+ {
+ printf ("rwlock_init failed: %d\n", ret);
+ return 1;
+ }
+
+ if ((ret = pthread_rwlock_rdlock (&r)) != 0)
+ {
+ printf ("rwlock_rdlock failed: %d\n", ret);
+ return 1;
+ }
+
+ if ((ret = pthread_rwlock_unlock (&r)) != 0)
+ {
+ printf ("rwlock_unlock failed: %d\n", ret);
+ return 1;
+ }
+
+ if ((ret = pthread_rwlock_wrlock (&r)) != 0)
+ {
+ printf ("rwlock_wrlock failed: %d\n", ret);
+ return 1;
+ }
+
+ if ((ret = pthread_rwlock_unlock (&r)) != 0)
+ {
+ printf ("second rwlock_unlock failed: %d\n", ret);
+ return 1;
+ }
+
+ if ((ret = pthread_rwlock_destroy (&r)) != 0)
+ {
+ printf ("second rwlock_destroy failed: %d\n", ret);
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-rwlock14.c b/libc/nptl/tst-rwlock14.c
new file mode 100644
index 000000000..fc0d3d219
--- /dev/null
+++ b/libc/nptl/tst-rwlock14.c
@@ -0,0 +1,169 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+
+static pthread_barrier_t b;
+static pthread_rwlock_t r = PTHREAD_RWLOCK_INITIALIZER;
+
+
+static void *
+tf (void *arg)
+{
+ /* Lock the read-write lock. */
+ if (pthread_rwlock_wrlock (&r) != 0)
+ {
+ puts ("tf: cannot lock rwlock");
+ exit (EXIT_FAILURE);
+ }
+
+ pthread_t mt = *(pthread_t *) arg;
+
+ pthread_barrier_wait (&b);
+
+ /* This call will never return. */
+ pthread_join (mt, NULL);
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ int result = 0;
+ struct timespec ts;
+
+ if (clock_gettime (CLOCK_REALTIME, &ts) != 0)
+ {
+ puts ("clock_gettime failed");
+ return 1;
+ }
+
+ if (pthread_barrier_init (&b, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ return 1;
+ }
+
+ pthread_t me = pthread_self ();
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, &me) != 0)
+ {
+ puts ("create failed");
+ return 1;
+ }
+
+ /* Wait until the rwlock is locked. */
+ pthread_barrier_wait (&b);
+
+ ts.tv_nsec = -1;
+
+ int e = pthread_rwlock_timedrdlock (&r, &ts);
+ if (e == 0)
+ {
+ puts ("first rwlock_timedrdlock did not fail");
+ result = 1;
+ }
+ else if (e != EINVAL)
+ {
+ puts ("first rwlock_timedrdlock did not return EINVAL");
+ result = 1;
+ }
+
+ e = pthread_rwlock_timedwrlock (&r, &ts);
+ if (e == 0)
+ {
+ puts ("first rwlock_timedwrlock did not fail");
+ result = 1;
+ }
+ else if (e != EINVAL)
+ {
+ puts ("first rwlock_timedwrlock did not return EINVAL");
+ result = 1;
+ }
+
+ ts.tv_nsec = 1000000000;
+
+ e = pthread_rwlock_timedrdlock (&r, &ts);
+ if (e == 0)
+ {
+ puts ("second rwlock_timedrdlock did not fail");
+ result = 1;
+ }
+ else if (e != EINVAL)
+ {
+ puts ("second rwlock_timedrdlock did not return EINVAL");
+ result = 1;
+ }
+
+ e = pthread_rwlock_timedrdlock (&r, &ts);
+ if (e == 0)
+ {
+ puts ("second rwlock_timedrdlock did not fail");
+ result = 1;
+ }
+ else if (e != EINVAL)
+ {
+ puts ("second rwlock_timedrdlock did not return EINVAL");
+ result = 1;
+ }
+
+ ts.tv_nsec = 0x100001000LL;
+ if (ts.tv_nsec != 0x100001000LL)
+ ts.tv_nsec = 2000000000;
+
+ e = pthread_rwlock_timedrdlock (&r, &ts);
+ if (e == 0)
+ {
+ puts ("third rwlock_timedrdlock did not fail");
+ result = 1;
+ }
+ else if (e != EINVAL)
+ {
+ puts ("third rwlock_timedrdlock did not return EINVAL");
+ result = 1;
+ }
+
+ e = pthread_rwlock_timedrdlock (&r, &ts);
+ if (e == 0)
+ {
+ puts ("third rwlock_timedrdlock did not fail");
+ result = 1;
+ }
+ else if (e != EINVAL)
+ {
+ puts ("third rwlock_timedrdlock did not return EINVAL");
+ result = 1;
+ }
+
+ if (result == 0)
+ puts ("no bugs");
+
+ return result;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-rwlock2.c b/libc/nptl/tst-rwlock2.c
new file mode 100644
index 000000000..6f38682b8
--- /dev/null
+++ b/libc/nptl/tst-rwlock2.c
@@ -0,0 +1,143 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+
+
+static int
+do_test (void)
+{
+ pthread_rwlock_t r;
+ int e;
+
+ if (pthread_rwlock_init (&r, NULL) != 0)
+ {
+ puts ("rwlock_init failed");
+ return 1;
+ }
+ puts ("rwlock_init succeeded");
+
+ if (pthread_rwlock_wrlock (&r) != 0)
+ {
+ puts ("1st rwlock_wrlock failed");
+ return 1;
+ }
+ puts ("1st rwlock_wrlock succeeded");
+
+ e = pthread_rwlock_tryrdlock (&r);
+ if (e == 0)
+ {
+ puts ("rwlock_tryrdlock on rwlock with writer succeeded");
+ return 1;
+ }
+ if (e != EBUSY)
+ {
+ puts ("rwlock_tryrdlock on rwlock with writer return value != EBUSY");
+ return 1;
+ }
+ puts ("rwlock_tryrdlock on rwlock with writer failed with EBUSY");
+
+ e = pthread_rwlock_trywrlock (&r);
+ if (e == 0)
+ {
+ puts ("rwlock_trywrlock on rwlock with writer succeeded");
+ return 1;
+ }
+ if (e != EBUSY)
+ {
+ puts ("rwlock_trywrlock on rwlock with writer return value != EBUSY");
+ return 1;
+ }
+ puts ("rwlock_trywrlock on rwlock with writer failed with EBUSY");
+
+ if (pthread_rwlock_unlock (&r) != 0)
+ {
+ puts ("1st rwlock_unlock failed");
+ return 1;
+ }
+ puts ("1st rwlock_unlock succeeded");
+
+ if (pthread_rwlock_tryrdlock (&r) != 0)
+ {
+ puts ("rwlock_tryrdlock on unlocked rwlock failed");
+ return 1;
+ }
+ puts ("rwlock_tryrdlock on unlocked rwlock succeeded");
+
+ e = pthread_rwlock_trywrlock (&r);
+ if (e == 0)
+ {
+ puts ("rwlock_trywrlock on rwlock with reader succeeded");
+ return 1;
+ }
+ if (e != EBUSY)
+ {
+ puts ("rwlock_trywrlock on rwlock with reader return value != EBUSY");
+ return 1;
+ }
+ puts ("rwlock_trywrlock on rwlock with reader failed with EBUSY");
+
+ if (pthread_rwlock_unlock (&r) != 0)
+ {
+ puts ("2nd rwlock_unlock failed");
+ return 1;
+ }
+ puts ("2nd rwlock_unlock succeeded");
+
+ if (pthread_rwlock_trywrlock (&r) != 0)
+ {
+ puts ("rwlock_trywrlock on unlocked rwlock failed");
+ return 1;
+ }
+ puts ("rwlock_trywrlock on unlocked rwlock succeeded");
+
+ e = pthread_rwlock_tryrdlock (&r);
+ if (e == 0)
+ {
+ puts ("rwlock_tryrdlock on rwlock with writer succeeded");
+ return 1;
+ }
+ if (e != EBUSY)
+ {
+ puts ("rwlock_tryrdlock on rwlock with writer return value != EBUSY");
+ return 1;
+ }
+ puts ("rwlock_tryrdlock on rwlock with writer failed with EBUSY");
+
+ if (pthread_rwlock_unlock (&r) != 0)
+ {
+ puts ("3rd rwlock_unlock failed");
+ return 1;
+ }
+ puts ("3rd rwlock_unlock succeeded");
+
+ if (pthread_rwlock_destroy (&r) != 0)
+ {
+ puts ("rwlock_destroy failed");
+ return 1;
+ }
+ puts ("rwlock_destroy succeeded");
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-rwlock3.c b/libc/nptl/tst-rwlock3.c
new file mode 100644
index 000000000..c1cac876d
--- /dev/null
+++ b/libc/nptl/tst-rwlock3.c
@@ -0,0 +1,93 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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. */
+
+/* This test case checks more than standard compliance. An
+ implementation may provide this service but it is not required to
+ do so. */
+
+#include <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+
+
+static int
+do_test (void)
+{
+ pthread_rwlock_t r;
+ int e;
+
+ if (pthread_rwlock_init (&r, NULL) != 0)
+ {
+ puts ("rwlock_init failed");
+ return 1;
+ }
+ puts ("rwlock_init succeeded");
+
+ if (pthread_rwlock_trywrlock (&r) != 0)
+ {
+ puts ("rwlock_trywrlock on unlocked rwlock failed");
+ return 1;
+ }
+ puts ("rwlock_trywrlock on unlocked rwlock succeeded");
+
+ e = pthread_rwlock_rdlock (&r);
+ if (e == 0)
+ {
+ puts ("rwlock_rdlock on rwlock with writer succeeded");
+ return 1;
+ }
+ if (e != EDEADLK)
+ {
+ puts ("rwlock_rdlock on rwlock with writer failed != EDEADLK");
+ return 1;
+ }
+ puts ("rwlock_rdlock on rwlock with writer failed with EDEADLK");
+
+ e = pthread_rwlock_wrlock (&r);
+ if (e == 0)
+ {
+ puts ("rwlock_wrlock on rwlock with writer succeeded");
+ return 1;
+ }
+ if (e != EDEADLK)
+ {
+ puts ("rwlock_wrlock on rwlock with writer failed != EDEADLK");
+ return 1;
+ }
+ puts ("rwlock_wrlock on rwlock with writer failed with EDEADLK");
+
+ if (pthread_rwlock_unlock (&r) != 0)
+ {
+ puts ("rwlock_unlock failed");
+ return 1;
+ }
+ puts ("rwlock_unlock succeeded");
+
+ if (pthread_rwlock_destroy (&r) != 0)
+ {
+ puts ("rwlock_destroy failed");
+ return 1;
+ }
+ puts ("rwlock_destroy succeeded");
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-rwlock4.c b/libc/nptl/tst-rwlock4.c
new file mode 100644
index 000000000..8de0121b3
--- /dev/null
+++ b/libc/nptl/tst-rwlock4.c
@@ -0,0 +1,190 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+
+
+static int
+do_test (void)
+{
+ size_t ps = sysconf (_SC_PAGESIZE);
+ char tmpfname[] = "/tmp/tst-rwlock4.XXXXXX";
+ char data[ps];
+ void *mem;
+ int fd;
+ pthread_rwlock_t *r;
+ pthread_rwlockattr_t a;
+ pid_t pid;
+ char *p;
+ int err;
+ int s;
+
+ fd = mkstemp (tmpfname);
+ if (fd == -1)
+ {
+ printf ("cannot open temporary file: %m\n");
+ return 1;
+ }
+
+ /* Make sure it is always removed. */
+ unlink (tmpfname);
+
+ /* Create one page of data. */
+ memset (data, '\0', ps);
+
+ /* Write the data to the file. */
+ if (write (fd, data, ps) != (ssize_t) ps)
+ {
+ puts ("short write");
+ return 1;
+ }
+
+ mem = mmap (NULL, ps, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if (mem == MAP_FAILED)
+ {
+ printf ("mmap failed: %m\n");
+ return 1;
+ }
+
+ r = (pthread_rwlock_t *) (((uintptr_t) mem + __alignof (pthread_rwlock_t))
+ & ~(__alignof (pthread_rwlock_t) - 1));
+ p = (char *) (r + 1);
+
+ if (pthread_rwlockattr_init (&a) != 0)
+ {
+ puts ("rwlockattr_init failed");
+ return 1;
+ }
+
+ if (pthread_rwlockattr_getpshared (&a, &s) != 0)
+ {
+ puts ("1st rwlockattr_getpshared failed");
+ return 1;
+ }
+
+ if (s != PTHREAD_PROCESS_PRIVATE)
+ {
+ puts ("default pshared value wrong");
+ return 1;
+ }
+
+ if (pthread_rwlockattr_setpshared (&a, PTHREAD_PROCESS_SHARED) != 0)
+ {
+ puts ("rwlockattr_setpshared failed");
+ return 1;
+ }
+
+ if (pthread_rwlockattr_getpshared (&a, &s) != 0)
+ {
+ puts ("2nd rwlockattr_getpshared failed");
+ return 1;
+ }
+
+ if (s != PTHREAD_PROCESS_SHARED)
+ {
+ puts ("pshared value after setpshared call wrong");
+ return 1;
+ }
+
+ if (pthread_rwlock_init (r, &a) != 0)
+ {
+ puts ("rwlock_init failed");
+ return 1;
+ }
+
+ if (pthread_rwlock_rdlock (r) != 0)
+ {
+ puts ("rwlock_rdlock failed");
+ return 1;
+ }
+
+ if (pthread_rwlockattr_destroy (&a) != 0)
+ {
+ puts ("rwlockattr_destroy failed");
+ return 1;
+ }
+
+ err = pthread_rwlock_trywrlock (r);
+ if (err == 0)
+ {
+ puts ("rwlock_trywrlock succeeded");
+ return 1;
+ }
+ else if (err != EBUSY)
+ {
+ puts ("rwlock_trywrlock didn't return EBUSY");
+ return 1;
+ }
+
+ *p = 0;
+
+ puts ("going to fork now");
+ pid = fork ();
+ if (pid == -1)
+ {
+ puts ("fork failed");
+ return 1;
+ }
+ else if (pid == 0)
+ {
+ /* Play some lock ping-pong. It's our turn to unlock first. */
+ if ((*p)++ != 0)
+ {
+ puts ("child: *p != 0");
+ return 1;
+ }
+
+ if (pthread_rwlock_unlock (r) != 0)
+ {
+ puts ("child: 1st rwlock_unlock failed");
+ return 1;
+ }
+
+ puts ("child done");
+ }
+ else
+ {
+ if (pthread_rwlock_wrlock (r) != 0)
+ {
+ puts ("parent: rwlock_wrlock failed");
+ return 1;
+ }
+
+ if (*p != 1)
+ {
+ puts ("*p != 1");
+ return 1;
+ }
+
+ puts ("parent done");
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-rwlock5.c b/libc/nptl/tst-rwlock5.c
new file mode 100644
index 000000000..a04eb2670
--- /dev/null
+++ b/libc/nptl/tst-rwlock5.c
@@ -0,0 +1,87 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
+static pthread_rwlock_t r;
+
+
+static void *
+tf (void *arg)
+{
+ if (pthread_rwlock_wrlock (&r) == 0)
+ {
+ puts ("child: rwlock_wrlock succeeded");
+ exit (1);
+ }
+
+ puts ("child: rwlock_wrlock returned");
+
+ exit (1);
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t th;
+
+ if (pthread_rwlock_init (&r, NULL) != 0)
+ {
+ puts ("rwlock_init failed");
+ return 1;
+ }
+
+ if (pthread_rwlock_wrlock (&r) != 0)
+ {
+ puts ("rwlock_wrlock failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (&m) != 0)
+ {
+ puts ("mutex_lock failed");
+ return 1;
+ }
+
+ /* Set an alarm for 1 second. The wrapper will expect this. */
+ alarm (1);
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ return 1;
+ }
+
+ /* This call should never return. */
+ pthread_mutex_lock (&m);
+
+ puts ("2nd mutex_lock returned");
+ return 1;
+}
+
+#define EXPECTED_SIGNAL SIGALRM
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-rwlock6.c b/libc/nptl/tst-rwlock6.c
new file mode 100644
index 000000000..3b525b9d5
--- /dev/null
+++ b/libc/nptl/tst-rwlock6.c
@@ -0,0 +1,226 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/time.h>
+
+
+static int kind[] =
+ {
+ PTHREAD_RWLOCK_PREFER_READER_NP,
+ PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,
+ PTHREAD_RWLOCK_PREFER_WRITER_NP,
+ };
+
+
+static void *
+tf (void *arg)
+{
+ pthread_rwlock_t *r = arg;
+
+ /* Timeout: 0.3 secs. */
+ struct timeval tv;
+ (void) gettimeofday (&tv, NULL);
+
+ struct timespec ts;
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+ ts.tv_nsec += 300000000;
+ if (ts.tv_nsec >= 1000000000)
+ {
+ ts.tv_nsec -= 1000000000;
+ ++ts.tv_sec;
+ }
+
+ puts ("child calling timedrdlock");
+
+ int err = pthread_rwlock_timedrdlock (r, &ts);
+ if (err == 0)
+ {
+ puts ("rwlock_timedrdlock returned");
+ pthread_exit ((void *) 1l);
+ }
+
+ if (err != ETIMEDOUT)
+ {
+ printf ("err = %s (%d), expected %s (%d)\n",
+ strerror (err), err, strerror (ETIMEDOUT), ETIMEDOUT);
+ pthread_exit ((void *) 1l);
+ }
+
+ puts ("1st child timedrdlock done");
+
+ struct timeval tv2;
+ (void) gettimeofday (&tv2, NULL);
+
+ timersub (&tv2, &tv, &tv);
+
+ if (tv.tv_usec < 200000)
+ {
+ puts ("timeout too short");
+ pthread_exit ((void *) 1l);
+ }
+
+ (void) gettimeofday (&tv, NULL);
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+ ts.tv_sec += 10;
+ /* Note that the following operation makes ts invalid. */
+ ts.tv_nsec += 1000000000;
+
+ err = pthread_rwlock_timedrdlock (r, &ts);
+ if (err == 0)
+ {
+ puts ("2nd timedrdlock succeeded");
+ pthread_exit ((void *) 1l);
+ }
+ if (err != EINVAL)
+ {
+ puts ("2nd timedrdlock did not return EINVAL");
+ pthread_exit ((void *) 1l);
+ }
+
+ puts ("2nd child timedrdlock done");
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ size_t cnt;
+ for (cnt = 0; cnt < sizeof (kind) / sizeof (kind[0]); ++cnt)
+ {
+ pthread_rwlock_t r;
+ pthread_rwlockattr_t a;
+
+ if (pthread_rwlockattr_init (&a) != 0)
+ {
+ printf ("round %Zu: rwlockattr_t failed\n", cnt);
+ exit (1);
+ }
+
+ if (pthread_rwlockattr_setkind_np (&a, kind[cnt]) != 0)
+ {
+ printf ("round %Zu: rwlockattr_setkind failed\n", cnt);
+ exit (1);
+ }
+
+ if (pthread_rwlock_init (&r, &a) != 0)
+ {
+ printf ("round %Zu: rwlock_init failed\n", cnt);
+ exit (1);
+ }
+
+ if (pthread_rwlockattr_destroy (&a) != 0)
+ {
+ printf ("round %Zu: rwlockattr_destroy failed\n", cnt);
+ exit (1);
+ }
+
+ struct timeval tv;
+ (void) gettimeofday (&tv, NULL);
+
+ struct timespec ts;
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+
+ ++ts.tv_sec;
+
+ /* Get a write lock. */
+ int e = pthread_rwlock_timedwrlock (&r, &ts);
+ if (e != 0)
+ {
+ printf ("round %Zu: rwlock_timedwrlock failed (%d)\n", cnt, e);
+ exit (1);
+ }
+
+ puts ("1st timedwrlock done");
+
+ (void) gettimeofday (&tv, NULL);
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+ ++ts.tv_sec;
+ e = pthread_rwlock_timedrdlock (&r, &ts);
+ if (e == 0)
+ {
+ puts ("timedrdlock succeeded");
+ exit (1);
+ }
+ if (e != EDEADLK)
+ {
+ puts ("timedrdlock did not return EDEADLK");
+ exit (1);
+ }
+
+ puts ("1st timedrdlock done");
+
+ (void) gettimeofday (&tv, NULL);
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+ ++ts.tv_sec;
+ e = pthread_rwlock_timedwrlock (&r, &ts);
+ if (e == 0)
+ {
+ puts ("2nd timedwrlock succeeded");
+ exit (1);
+ }
+ if (e != EDEADLK)
+ {
+ puts ("2nd timedwrlock did not return EDEADLK");
+ exit (1);
+ }
+
+ puts ("2nd timedwrlock done");
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, &r) != 0)
+ {
+ printf ("round %Zu: create failed\n", cnt);
+ exit (1);
+ }
+
+ puts ("started thread");
+
+ void *status;
+ if (pthread_join (th, &status) != 0)
+ {
+ printf ("round %Zu: join failed\n", cnt);
+ exit (1);
+ }
+ if (status != NULL)
+ {
+ printf ("failure in round %Zu\n", cnt);
+ exit (1);
+ }
+
+ puts ("joined thread");
+
+ if (pthread_rwlock_destroy (&r) != 0)
+ {
+ printf ("round %Zu: rwlock_destroy failed\n", cnt);
+ exit (1);
+ }
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-rwlock7.c b/libc/nptl/tst-rwlock7.c
new file mode 100644
index 000000000..1f34c0650
--- /dev/null
+++ b/libc/nptl/tst-rwlock7.c
@@ -0,0 +1,179 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/time.h>
+
+
+static int kind[] =
+ {
+ PTHREAD_RWLOCK_PREFER_READER_NP,
+ PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,
+ PTHREAD_RWLOCK_PREFER_WRITER_NP,
+ };
+
+
+static void *
+tf (void *arg)
+{
+ pthread_rwlock_t *r = arg;
+
+ /* Timeout: 0.3 secs. */
+ struct timeval tv;
+ (void) gettimeofday (&tv, NULL);
+
+ struct timespec ts;
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+ ts.tv_nsec += 300000000;
+ if (ts.tv_nsec >= 1000000000)
+ {
+ ts.tv_nsec -= 1000000000;
+ ++ts.tv_sec;
+ }
+
+ int err = pthread_rwlock_timedwrlock (r, &ts);
+ if (err == 0)
+ {
+ puts ("rwlock_timedwrlock returned");
+ pthread_exit ((void *) 1l);
+ }
+
+ if (err != ETIMEDOUT)
+ {
+ printf ("err = %s (%d), expected %s (%d)\n",
+ strerror (err), err, strerror (ETIMEDOUT), ETIMEDOUT);
+ pthread_exit ((void *) 1l);
+ }
+
+ struct timeval tv2;
+ (void) gettimeofday (&tv2, NULL);
+
+ timersub (&tv2, &tv, &tv);
+
+ if (tv.tv_usec < 200000)
+ {
+ puts ("timeout too short");
+ pthread_exit ((void *) 1l);
+ }
+
+ (void) gettimeofday (&tv, NULL);
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+ ts.tv_sec += 10;
+ /* Note that the following operation makes ts invalid. */
+ ts.tv_nsec += 1000000000;
+
+ err = pthread_rwlock_timedwrlock (r, &ts);
+ if (err == 0)
+ {
+ puts ("2nd timedwrlock succeeded");
+ pthread_exit ((void *) 1l);
+ }
+ if (err != EINVAL)
+ {
+ puts ("2nd timedwrlock did not return EINVAL");
+ pthread_exit ((void *) 1l);
+ }
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ size_t cnt;
+ for (cnt = 0; cnt < sizeof (kind) / sizeof (kind[0]); ++cnt)
+ {
+ pthread_rwlock_t r;
+ pthread_rwlockattr_t a;
+
+ if (pthread_rwlockattr_init (&a) != 0)
+ {
+ printf ("round %Zu: rwlockattr_t failed\n", cnt);
+ exit (1);
+ }
+
+ if (pthread_rwlockattr_setkind_np (&a, kind[cnt]) != 0)
+ {
+ printf ("round %Zu: rwlockattr_setkind failed\n", cnt);
+ exit (1);
+ }
+
+ if (pthread_rwlock_init (&r, &a) != 0)
+ {
+ printf ("round %Zu: rwlock_init failed\n", cnt);
+ exit (1);
+ }
+
+ if (pthread_rwlockattr_destroy (&a) != 0)
+ {
+ printf ("round %Zu: rwlockattr_destroy failed\n", cnt);
+ exit (1);
+ }
+
+ struct timeval tv;
+ (void) gettimeofday (&tv, NULL);
+
+ struct timespec ts;
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+
+ ++ts.tv_sec;
+
+ /* Get a read lock. */
+ if (pthread_rwlock_timedrdlock (&r, &ts) != 0)
+ {
+ printf ("round %Zu: rwlock_timedrdlock failed\n", cnt);
+ exit (1);
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, &r) != 0)
+ {
+ printf ("round %Zu: create failed\n", cnt);
+ exit (1);
+ }
+
+ void *status;
+ if (pthread_join (th, &status) != 0)
+ {
+ printf ("round %Zu: join failed\n", cnt);
+ exit (1);
+ }
+ if (status != NULL)
+ {
+ printf ("failure in round %Zu\n", cnt);
+ exit (1);
+ }
+
+ if (pthread_rwlock_destroy (&r) != 0)
+ {
+ printf ("round %Zu: rwlock_destroy failed\n", cnt);
+ exit (1);
+ }
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-rwlock8.c b/libc/nptl/tst-rwlock8.c
new file mode 100644
index 000000000..7eeaea885
--- /dev/null
+++ b/libc/nptl/tst-rwlock8.c
@@ -0,0 +1,164 @@
+/* Test program for timedout read/write lock functions.
+ Copyright (C) 2000, 2003 Free Software Foundation, Inc.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2000.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <error.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+
+
+#define NWRITERS 15
+#define WRITETRIES 10
+#define NREADERS 15
+#define READTRIES 15
+
+#define DELAY 1000000
+
+#ifndef INIT
+# define INIT PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP
+#endif
+
+static pthread_rwlock_t lock = INIT;
+
+
+static void *
+writer_thread (void *nr)
+{
+ struct timespec delay;
+ int n;
+
+ delay.tv_sec = 0;
+ delay.tv_nsec = DELAY;
+
+ for (n = 0; n < WRITETRIES; ++n)
+ {
+ printf ("writer thread %ld tries again\n", (long int) nr);
+
+ if (pthread_rwlock_wrlock (&lock) != 0)
+ {
+ puts ("wrlock failed");
+ exit (1);
+ }
+
+ printf ("writer thread %ld succeeded\n", (long int) nr);
+
+ nanosleep (&delay, NULL);
+
+ if (pthread_rwlock_unlock (&lock) != 0)
+ {
+ puts ("unlock for writer failed");
+ exit (1);
+ }
+
+ printf ("writer thread %ld released\n", (long int) nr);
+ }
+
+ return NULL;
+}
+
+
+static void *
+reader_thread (void *nr)
+{
+ struct timespec delay;
+ int n;
+
+ delay.tv_sec = 0;
+ delay.tv_nsec = DELAY;
+
+ for (n = 0; n < READTRIES; ++n)
+ {
+ printf ("reader thread %ld tries again\n", (long int) nr);
+
+ if (pthread_rwlock_rdlock (&lock) != 0)
+ {
+ puts ("rdlock failed");
+ exit (1);
+ }
+
+ printf ("reader thread %ld succeeded\n", (long int) nr);
+
+ nanosleep (&delay, NULL);
+
+ if (pthread_rwlock_unlock (&lock) != 0)
+ {
+ puts ("unlock for reader failed");
+ exit (1);
+ }
+
+ printf ("reader thread %ld released\n", (long int) nr);
+ }
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t thwr[NWRITERS];
+ pthread_t thrd[NREADERS];
+ int n;
+ void *res;
+
+ /* Make standard error the same as standard output. */
+ dup2 (1, 2);
+
+ /* Make sure we see all message, even those on stdout. */
+ setvbuf (stdout, NULL, _IONBF, 0);
+
+ for (n = 0; n < NWRITERS; ++n)
+ if (pthread_create (&thwr[n], NULL, writer_thread,
+ (void *) (long int) n) != 0)
+ {
+ puts ("writer create failed");
+ exit (1);
+ }
+
+ for (n = 0; n < NREADERS; ++n)
+ if (pthread_create (&thrd[n], NULL, reader_thread,
+ (void *) (long int) n) != 0)
+ {
+ puts ("reader create failed");
+ exit (1);
+ }
+
+ /* Wait for all the threads. */
+ for (n = 0; n < NWRITERS; ++n)
+ if (pthread_join (thwr[n], &res) != 0)
+ {
+ puts ("writer join failed");
+ exit (1);
+ }
+ for (n = 0; n < NREADERS; ++n)
+ if (pthread_join (thrd[n], &res) != 0)
+ {
+ puts ("reader join failed");
+ exit (1);
+ }
+
+ return 0;
+}
+
+#define TIMEOUT 30
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-rwlock9.c b/libc/nptl/tst-rwlock9.c
new file mode 100644
index 000000000..a5522ce48
--- /dev/null
+++ b/libc/nptl/tst-rwlock9.c
@@ -0,0 +1,203 @@
+/* Test program for timedout read/write lock functions.
+ Copyright (C) 2000, 2003 Free Software Foundation, Inc.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2000.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <error.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+
+#define NWRITERS 15
+#define WRITETRIES 10
+#define NREADERS 15
+#define READTRIES 15
+
+#define TIMEOUT 1000000
+#define DELAY 1000000
+
+#ifndef INIT
+# define INIT PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP
+#endif
+
+static pthread_rwlock_t lock = INIT;
+
+
+static void *
+writer_thread (void *nr)
+{
+ struct timespec ts;
+ struct timespec delay;
+ int n;
+
+ delay.tv_sec = 0;
+ delay.tv_nsec = DELAY;
+
+ for (n = 0; n < WRITETRIES; ++n)
+ {
+ int e;
+ do
+ {
+ struct timeval tv;
+ (void) gettimeofday (&tv, NULL);
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+
+ ts.tv_nsec += 2 * TIMEOUT;
+ if (ts.tv_nsec >= 1000000000)
+ {
+ ts.tv_nsec -= 1000000000;
+ ++ts.tv_sec;
+ }
+
+ printf ("writer thread %ld tries again\n", (long int) nr);
+
+ e = pthread_rwlock_timedwrlock (&lock, &ts);
+ if (e != 0 && e != ETIMEDOUT)
+ {
+ puts ("timedwrlock failed");
+ exit (1);
+ }
+ }
+ while (e == ETIMEDOUT);
+
+ printf ("writer thread %ld succeeded\n", (long int) nr);
+
+ nanosleep (&delay, NULL);
+
+ if (pthread_rwlock_unlock (&lock) != 0)
+ {
+ puts ("unlock for writer failed");
+ exit (1);
+ }
+
+ printf ("writer thread %ld released\n", (long int) nr);
+ }
+
+ return NULL;
+}
+
+
+static void *
+reader_thread (void *nr)
+{
+ struct timespec ts;
+ struct timespec delay;
+ int n;
+
+ delay.tv_sec = 0;
+ delay.tv_nsec = DELAY;
+
+ for (n = 0; n < READTRIES; ++n)
+ {
+ int e;
+ do
+ {
+ struct timeval tv;
+ (void) gettimeofday (&tv, NULL);
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+
+ ts.tv_nsec += TIMEOUT;
+ if (ts.tv_nsec >= 1000000000)
+ {
+ ts.tv_nsec -= 1000000000;
+ ++ts.tv_sec;
+ }
+
+ printf ("reader thread %ld tries again\n", (long int) nr);
+
+ e = pthread_rwlock_timedrdlock (&lock, &ts);
+ if (e != 0 && e != ETIMEDOUT)
+ {
+ puts ("timedrdlock failed");
+ exit (1);
+ }
+ }
+ while (e == ETIMEDOUT);
+
+ printf ("reader thread %ld succeeded\n", (long int) nr);
+
+ nanosleep (&delay, NULL);
+
+ if (pthread_rwlock_unlock (&lock) != 0)
+ {
+ puts ("unlock for reader failed");
+ exit (1);
+ }
+
+ printf ("reader thread %ld released\n", (long int) nr);
+ }
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_t thwr[NWRITERS];
+ pthread_t thrd[NREADERS];
+ int n;
+ void *res;
+
+ /* Make standard error the same as standard output. */
+ dup2 (1, 2);
+
+ /* Make sure we see all message, even those on stdout. */
+ setvbuf (stdout, NULL, _IONBF, 0);
+
+ for (n = 0; n < NWRITERS; ++n)
+ if (pthread_create (&thwr[n], NULL, writer_thread,
+ (void *) (long int) n) != 0)
+ {
+ puts ("writer create failed");
+ exit (1);
+ }
+
+ for (n = 0; n < NREADERS; ++n)
+ if (pthread_create (&thrd[n], NULL, reader_thread,
+ (void *) (long int) n) != 0)
+ {
+ puts ("reader create failed");
+ exit (1);
+ }
+
+ /* Wait for all the threads. */
+ for (n = 0; n < NWRITERS; ++n)
+ if (pthread_join (thwr[n], &res) != 0)
+ {
+ puts ("writer join failed");
+ exit (1);
+ }
+ for (n = 0; n < NREADERS; ++n)
+ if (pthread_join (thrd[n], &res) != 0)
+ {
+ puts ("reader join failed");
+ exit (1);
+ }
+
+ return 0;
+}
+
+#undef TIMEOUT
+#define TIMEOUT 30
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-sched1.c b/libc/nptl/tst-sched1.c
new file mode 100644
index 000000000..4d0702c79
--- /dev/null
+++ b/libc/nptl/tst-sched1.c
@@ -0,0 +1,98 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+
+static int global;
+
+static void *
+tf (void *a)
+{
+ global = 1;
+
+ return 0;
+}
+
+
+int
+do_test (void)
+{
+ pthread_t th;
+ pthread_attr_t at;
+
+ if (pthread_attr_init (&at) != 0)
+ {
+ puts ("attr_init failed");
+ return 1;
+ }
+
+ if (pthread_attr_setschedpolicy (&at, SCHED_OTHER) != 0)
+ {
+ puts ("attr_setschedpolicy failed");
+ return 1;
+ }
+
+ struct sched_param pa;
+ if (sched_getparam (getpid (), &pa) != 0)
+ {
+ puts ("sched_getschedparam failed");
+ return 1;
+ }
+
+ if (pthread_attr_setschedparam (&at, &pa) != 0)
+ {
+ puts ("attr_setschedparam failed");
+ return 1;
+ }
+
+ if (pthread_attr_setinheritsched (&at, PTHREAD_EXPLICIT_SCHED) != 0)
+ {
+ puts ("attr_setinheritsched failed");
+ return 1;
+ }
+
+ if (pthread_create (&th, &at, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ return 1;
+ }
+
+ int e = pthread_join (th, NULL);
+ if (e != 0)
+ {
+ printf ("join failed: %d\n", e);
+ return 1;
+ }
+
+ if (global == 0)
+ {
+ puts ("thread didn't run");
+ return 1;
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-sem1.c b/libc/nptl/tst-sem1.c
new file mode 100644
index 000000000..32d59eb36
--- /dev/null
+++ b/libc/nptl/tst-sem1.c
@@ -0,0 +1,89 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <semaphore.h>
+#include <stdio.h>
+#include <unistd.h>
+
+
+static int
+do_test (void)
+{
+ sem_t s;
+
+ if (sem_init (&s, 0, 1) == -1)
+ {
+ puts ("init failed");
+ return 1;
+ }
+
+ if (TEMP_FAILURE_RETRY (sem_wait (&s)) == -1)
+ {
+ puts ("1st wait failed");
+ return 1;
+ }
+
+ if (sem_post (&s) == -1)
+ {
+ puts ("1st post failed");
+ return 1;
+ }
+
+ if (TEMP_FAILURE_RETRY (sem_trywait (&s)) == -1)
+ {
+ puts ("1st trywait failed");
+ return 1;
+ }
+
+ errno = 0;
+ if (TEMP_FAILURE_RETRY (sem_trywait (&s)) != -1)
+ {
+ puts ("2nd trywait succeeded");
+ return 1;
+ }
+ else if (errno != EAGAIN)
+ {
+ puts ("2nd trywait did not set errno to EAGAIN");
+ return 1;
+ }
+
+ if (sem_post (&s) == -1)
+ {
+ puts ("2nd post failed");
+ return 1;
+ }
+
+ if (TEMP_FAILURE_RETRY (sem_wait (&s)) == -1)
+ {
+ puts ("2nd wait failed");
+ return 1;
+ }
+
+ if (sem_destroy (&s) == -1)
+ {
+ puts ("destroy failed");
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-sem2.c b/libc/nptl/tst-sem2.c
new file mode 100644
index 000000000..026939ef9
--- /dev/null
+++ b/libc/nptl/tst-sem2.c
@@ -0,0 +1,54 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <semaphore.h>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+
+
+static int
+do_test (void)
+{
+ sem_t s;
+
+ if (sem_init (&s, 0, 0) == -1)
+ {
+ puts ("init failed");
+ return 1;
+ }
+
+ /* Set an alarm for 1 second. The wrapper will expect this. */
+ alarm (1);
+
+ if (TEMP_FAILURE_RETRY (sem_wait (&s)) == -1)
+ {
+ puts ("wait failed");
+ return 1;
+ }
+
+ /* We should never get here. */
+ puts ("wait succeeded");
+ return 1;
+}
+
+#define EXPECTED_SIGNAL SIGALRM
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-sem3.c b/libc/nptl/tst-sem3.c
new file mode 100644
index 000000000..91b9f0877
--- /dev/null
+++ b/libc/nptl/tst-sem3.c
@@ -0,0 +1,142 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <semaphore.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+
+
+int
+main (void)
+{
+ size_t ps = sysconf (_SC_PAGESIZE);
+ char tmpfname[] = "/tmp/tst-sem3.XXXXXX";
+ char data[ps];
+ void *mem;
+ int fd;
+ sem_t *s;
+ pid_t pid;
+ char *p;
+
+ fd = mkstemp (tmpfname);
+ if (fd == -1)
+ {
+ printf ("cannot open temporary file: %m\n");
+ exit (1);
+ }
+
+ /* Make sure it is always removed. */
+ unlink (tmpfname);
+
+ /* Create one page of data. */
+ memset (data, '\0', ps);
+
+ /* Write the data to the file. */
+ if (write (fd, data, ps) != (ssize_t) ps)
+ {
+ puts ("short write");
+ exit (1);
+ }
+
+ mem = mmap (NULL, ps, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if (mem == MAP_FAILED)
+ {
+ printf ("mmap failed: %m\n");
+ exit (1);
+ }
+
+ s = (sem_t *) (((uintptr_t) mem + __alignof (sem_t))
+ & ~(__alignof (sem_t) - 1));
+ p = (char *) (s + 1);
+
+ if (sem_init (s, 1, 1) == -1)
+ {
+ puts ("init failed");
+ exit (1);
+ }
+
+ if (TEMP_FAILURE_RETRY (sem_wait (s)) == -1)
+ {
+ puts ("1st wait failed");
+ exit (1);
+ }
+
+ errno = 0;
+ if (TEMP_FAILURE_RETRY (sem_trywait (s)) != -1)
+ {
+ puts ("trywait succeeded");
+ exit (1);
+ }
+ else if (errno != EAGAIN)
+ {
+ puts ("trywait didn't return EAGAIN");
+ exit (1);
+ }
+
+ *p = 0;
+
+ puts ("going to fork now");
+ pid = fork ();
+ if (pid == -1)
+ {
+ puts ("fork failed");
+ exit (1);
+ }
+ else if (pid == 0)
+ {
+ /* Play some lock ping-pong. It's our turn to unlock first. */
+ if ((*p)++ != 0)
+ {
+ puts ("child: *p != 0");
+ exit (1);
+ }
+
+ if (sem_post (s) == -1)
+ {
+ puts ("child: 1st post failed");
+ exit (1);
+ }
+
+ puts ("child done");
+ }
+ else
+ {
+ if (TEMP_FAILURE_RETRY (sem_wait (s)) == -1)
+ {
+ printf ("parent: 2nd wait failed: %m\n");
+ exit (1);
+ }
+
+ if (*p != 1)
+ {
+ puts ("*p != 1");
+ exit (1);
+ }
+
+ puts ("parent done");
+ }
+
+ exit (0);
+}
diff --git a/libc/nptl/tst-sem4.c b/libc/nptl/tst-sem4.c
new file mode 100644
index 000000000..ccffbdd77
--- /dev/null
+++ b/libc/nptl/tst-sem4.c
@@ -0,0 +1,147 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <fcntl.h>
+#include <semaphore.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static void
+remove_sem (int status, void *arg)
+{
+ sem_unlink (arg);
+}
+
+
+int
+main (void)
+{
+ sem_t *s;
+ sem_t *s2;
+ pid_t pid;
+ int val;
+
+ s = sem_open ("/glibc-tst-sem4", O_CREAT, 0600, 1);
+ if (s == SEM_FAILED)
+ {
+ if (errno == ENOSYS)
+ {
+ puts ("sem_open not supported. Oh well.");
+ return 0;
+ }
+
+ /* Maybe the shm filesystem has strict permissions. */
+ if (errno == EACCES)
+ {
+ puts ("sem_open not allowed. Oh well.");
+ return 0;
+ }
+
+ printf ("sem_open: %m\n");
+ return 1;
+ }
+
+ on_exit (remove_sem, (void *) "/glibc-tst-sem4");
+
+ /* We have the semaphore object. Now try again with O_EXCL, this
+ should fail. */
+ s2 = sem_open ("/glibc-tst-sem4", O_CREAT | O_EXCL, 0600, 1);
+ if (s2 != SEM_FAILED)
+ {
+ puts ("2nd sem_open didn't fail");
+ return 1;
+ }
+ if (errno != EEXIST)
+ {
+ puts ("2nd sem_open returned wrong error");
+ return 1;
+ }
+
+ /* Check the value. */
+ if (sem_getvalue (s, &val) == -1)
+ {
+ puts ("getvalue failed");
+ return 1;
+ }
+ if (val != 1)
+ {
+ printf ("initial value wrong: got %d, expected 1\n", val);
+ return 1;
+ }
+
+ if (TEMP_FAILURE_RETRY (sem_wait (s)) == -1)
+ {
+ puts ("1st sem_wait failed");
+ return 1;
+ }
+
+ pid = fork ();
+ if (pid == -1)
+ {
+ printf ("fork failed: %m\n");
+ return 1;
+ }
+
+ if (pid == 0)
+ {
+ /* Child. */
+
+ /* Check the value. */
+ if (sem_getvalue (s, &val) == -1)
+ {
+ puts ("child: getvalue failed");
+ return 1;
+ }
+ if (val != 0)
+ {
+ printf ("child: value wrong: got %d, expect 0\n", val);
+ return 1;
+ }
+
+ if (sem_post (s) == -1)
+ {
+ puts ("child: post failed");
+ return 1;
+ }
+ }
+ else
+ {
+ if (TEMP_FAILURE_RETRY (sem_wait (s)) == -1)
+ {
+ puts ("2nd sem_wait failed");
+ return 1;
+ }
+
+ if (sem_getvalue (s, &val) == -1)
+ {
+ puts ("parent: 2nd getvalue failed");
+ return 1;
+ }
+ if (val != 0)
+ {
+ printf ("parent: value wrong: got %d, expected 0\n", val);
+ return 1;
+ }
+ }
+
+ return 0;
+}
diff --git a/libc/nptl/tst-sem5.c b/libc/nptl/tst-sem5.c
new file mode 100644
index 000000000..cb85b8e76
--- /dev/null
+++ b/libc/nptl/tst-sem5.c
@@ -0,0 +1,80 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <semaphore.h>
+#include <stdio.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+
+static int
+do_test (void)
+{
+ sem_t s;
+ struct timespec ts;
+ struct timeval tv;
+
+ if (sem_init (&s, 0, 1) == -1)
+ {
+ puts ("sem_init failed");
+ return 1;
+ }
+
+ if (TEMP_FAILURE_RETRY (sem_wait (&s)) == -1)
+ {
+ puts ("sem_wait failed");
+ return 1;
+ }
+
+ if (gettimeofday (&tv, NULL) != 0)
+ {
+ puts ("gettimeofday failed");
+ return 1;
+ }
+
+ TIMEVAL_TO_TIMESPEC (&tv, &ts);
+
+ /* We wait for half a second. */
+ ts.tv_nsec += 500000000;
+ if (ts.tv_nsec >= 1000000000)
+ {
+ ++ts.tv_sec;
+ ts.tv_nsec -= 1000000000;
+ }
+
+ errno = 0;
+ if (TEMP_FAILURE_RETRY (sem_timedwait (&s, &ts)) != -1)
+ {
+ puts ("sem_timedwait succeeded");
+ return 1;
+ }
+ if (errno != ETIMEDOUT)
+ {
+ printf ("sem_timedwait return errno = %d instead of ETIMEDOUT\n",
+ errno);
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-sem6.c b/libc/nptl/tst-sem6.c
new file mode 100644
index 000000000..49240d962
--- /dev/null
+++ b/libc/nptl/tst-sem6.c
@@ -0,0 +1,81 @@
+/* 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 <errno.h>
+#include <semaphore.h>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+
+
+static void
+handler (int sig)
+{
+ struct sigaction sa;
+
+ sa.sa_handler = SIG_DFL;
+ sa.sa_flags = 0;
+ sigemptyset (&sa.sa_mask);
+
+ sigaction (SIGALRM, &sa, NULL);
+
+ /* Rearm the timer. */
+ alarm (1);
+}
+
+
+static int
+do_test (void)
+{
+ sem_t s;
+ struct sigaction sa;
+
+ sa.sa_handler = handler;
+ sa.sa_flags = 0;
+ sigemptyset (&sa.sa_mask);
+
+ sigaction (SIGALRM, &sa, NULL);
+
+ if (sem_init (&s, 0, 0) == -1)
+ {
+ puts ("init failed");
+ return 1;
+ }
+
+ /* Set an alarm for 1 second. The wrapper will expect this. */
+ alarm (1);
+
+ int res = sem_wait (&s);
+ if (res == 0)
+ {
+ puts ("wait succeeded");
+ return 1;
+ }
+ if (res != -1 || errno != EINTR)
+ {
+ puts ("wait didn't fail with EINTR");
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TIMEOUT 3
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-sem7.c b/libc/nptl/tst-sem7.c
new file mode 100644
index 000000000..a85c73e71
--- /dev/null
+++ b/libc/nptl/tst-sem7.c
@@ -0,0 +1,109 @@
+/* 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 <errno.h>
+#include <fcntl.h>
+#include <semaphore.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static void
+remove_sem (int status, void *arg)
+{
+ sem_unlink (arg);
+}
+
+
+int
+main (void)
+{
+ sem_t *s;
+ sem_t *s2;
+ sem_t *s3;
+
+ s = sem_open ("/glibc-tst-sem7", O_CREAT, 0600, 1);
+ if (s == SEM_FAILED)
+ {
+ if (errno == ENOSYS)
+ {
+ puts ("sem_open not supported. Oh well.");
+ return 0;
+ }
+
+ /* Maybe the shm filesystem has strict permissions. */
+ if (errno == EACCES)
+ {
+ puts ("sem_open not allowed. Oh well.");
+ return 0;
+ }
+
+ printf ("sem_open: %m\n");
+ return 1;
+ }
+
+ on_exit (remove_sem, (void *) "/glibc-tst-sem7");
+
+ /* We have the semaphore object. Now try again. We should get the
+ same address. */
+ s2 = sem_open ("/glibc-tst-sem7", O_CREAT, 0600, 1);
+ if (s2 == SEM_FAILED)
+ {
+ puts ("2nd sem_open failed");
+ return 1;
+ }
+ if (s != s2)
+ {
+ puts ("2nd sem_open didn't return the same address");
+ return 1;
+ }
+
+ /* And again, this time without O_CREAT. */
+ s3 = sem_open ("/glibc-tst-sem7", 0);
+ if (s3 == SEM_FAILED)
+ {
+ puts ("3rd sem_open failed");
+ return 1;
+ }
+ if (s != s3)
+ {
+ puts ("3rd sem_open didn't return the same address");
+ return 1;
+ }
+
+ /* Now close the handle. Three times. */
+ if (sem_close (s2) != 0)
+ {
+ puts ("1st sem_close failed");
+ return 1;
+ }
+ if (sem_close (s) != 0)
+ {
+ puts ("2nd sem_close failed");
+ return 1;
+ }
+ if (sem_close (s3) != 0)
+ {
+ puts ("3rd sem_close failed");
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/libc/nptl/tst-sem8.c b/libc/nptl/tst-sem8.c
new file mode 100644
index 000000000..5dea575e9
--- /dev/null
+++ b/libc/nptl/tst-sem8.c
@@ -0,0 +1,74 @@
+/* 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 <errno.h>
+#include <fcntl.h>
+#include <semaphore.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static void
+remove_sem (int status, void *arg)
+{
+ sem_unlink (arg);
+}
+
+
+int
+main (void)
+{
+ sem_t *s;
+ int i;
+
+ on_exit (remove_sem, (void *) "/glibc-tst-sem8");
+
+ for (i = 0; i < 3; ++i)
+ {
+ s = sem_open ("/glibc-tst-sem8", O_CREAT, 0600, 1);
+ if (s == SEM_FAILED)
+ {
+ if (errno == ENOSYS)
+ {
+ puts ("sem_open not supported. Oh well.");
+ return 0;
+ }
+
+ /* Maybe the shm filesystem has strict permissions. */
+ if (errno == EACCES)
+ {
+ puts ("sem_open not allowed. Oh well.");
+ return 0;
+ }
+
+ printf ("sem_open: %m\n");
+ return 1;
+ }
+
+ /* Now close the handle. */
+ if (sem_close (s) != 0)
+ {
+ puts ("sem_close failed");
+ return 1;
+ }
+ }
+
+ return 0;
+}
diff --git a/libc/nptl/tst-sem9.c b/libc/nptl/tst-sem9.c
new file mode 100644
index 000000000..cdd8eaa30
--- /dev/null
+++ b/libc/nptl/tst-sem9.c
@@ -0,0 +1,81 @@
+/* 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 <errno.h>
+#include <fcntl.h>
+#include <semaphore.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static void
+remove_sem (int status, void *arg)
+{
+ sem_unlink (arg);
+}
+
+
+int
+main (void)
+{
+ sem_t *s;
+ int i;
+
+ on_exit (remove_sem, (void *) "/glibc-tst-sem9");
+
+ for (i = 0; i < 3; ++i)
+ {
+ s = sem_open ("/glibc-tst-sem9", O_CREAT, 0600, 1);
+ if (s == SEM_FAILED)
+ {
+ if (errno == ENOSYS)
+ {
+ puts ("sem_open not supported. Oh well.");
+ return 0;
+ }
+
+ /* Maybe the shm filesystem has strict permissions. */
+ if (errno == EACCES)
+ {
+ puts ("sem_open not allowed. Oh well.");
+ return 0;
+ }
+
+ printf ("sem_open: %m\n");
+ return 1;
+ }
+
+ /* Now close the handle. */
+ if (sem_close (s) != 0)
+ {
+ puts ("sem_close failed");
+ return 1;
+ }
+
+ /* And remove it. */
+ if (sem_unlink ("/glibc-tst-sem9") != 0)
+ {
+ puts ("sem_unlink failed");
+ return 1;
+ }
+ }
+
+ return 0;
+}
diff --git a/libc/nptl/tst-setuid1-static.c b/libc/nptl/tst-setuid1-static.c
new file mode 100644
index 000000000..46d26f099
--- /dev/null
+++ b/libc/nptl/tst-setuid1-static.c
@@ -0,0 +1 @@
+#include "tst-setuid1.c"
diff --git a/libc/nptl/tst-setuid1.c b/libc/nptl/tst-setuid1.c
new file mode 100644
index 000000000..f026c576d
--- /dev/null
+++ b/libc/nptl/tst-setuid1.c
@@ -0,0 +1,1085 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jaku@redhat.com>, 2004.
+
+ 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>
+#include <pwd.h>
+#include <grp.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+
+static pthread_barrier_t b3, b4;
+static uid_t prev_ruid, prev_euid, prev_suid, nobody_uid;
+static gid_t prev_rgid, prev_egid, prev_sgid, nobody_gid;
+enum ACTION { PREPARE, SET, CHECK_BEFORE, CHECK_AFTER };
+#define TESTNO(arg) ((long int) (arg) & 0xff)
+#define THREADNO(arg) ((long int) (arg) >> 8)
+
+
+static void
+check_prev_uid (int tno)
+{
+ uid_t ruid, euid, suid;
+ if (getresuid (&ruid, &euid, &suid) < 0)
+ {
+ printf ("getresuid failed: %d %m\n", tno);
+ exit (1);
+ }
+
+ if (ruid != prev_ruid || euid != prev_euid || suid != prev_suid)
+ {
+ printf ("uids before in %d (%d %d %d) != (%d %d %d)\n", tno,
+ ruid, euid, suid, prev_ruid, prev_euid, prev_suid);
+ exit (1);
+ }
+}
+
+
+static void
+check_prev_gid (int tno)
+{
+ gid_t rgid, egid, sgid;
+ if (getresgid (&rgid, &egid, &sgid) < 0)
+ {
+ printf ("getresgid failed: %d %m\n", tno);
+ exit (1);
+ }
+
+ if (rgid != prev_rgid || egid != prev_egid || sgid != prev_sgid)
+ {
+ printf ("gids before in %d (%d %d %d) != (%d %d %d)\n", tno,
+ rgid, egid, sgid, prev_rgid, prev_egid, prev_sgid);
+ exit (1);
+ }
+}
+
+
+static void
+test_setuid1 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ return;
+
+ if (action != CHECK_AFTER)
+ check_prev_uid (tno);
+
+ if (action == SET && setuid (nobody_uid) < 0)
+ {
+ printf ("setuid failed: %m\n");
+ exit (1);
+ }
+
+ if (action != CHECK_BEFORE)
+ {
+ uid_t ruid, euid, suid;
+ if (getresuid (&ruid, &euid, &suid) < 0)
+ {
+ printf ("getresuid failed: %d %m\n", tno);
+ exit (1);
+ }
+
+ if (ruid != nobody_uid || euid != nobody_uid || suid != nobody_uid)
+ {
+ printf ("after setuid %d (%d %d %d) != (%d %d %d)\n", tno,
+ ruid, euid, suid, nobody_uid, nobody_uid, nobody_uid);
+ exit (1);
+ }
+ }
+}
+
+
+static void
+test_setuid2 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ {
+ if (setresuid (nobody_uid, nobody_uid, -1) < 0)
+ {
+ printf ("setresuid failed: %m\n");
+ exit (1);
+ }
+
+ prev_ruid = nobody_uid;
+ prev_euid = nobody_uid;
+ return;
+ }
+
+ if (action != CHECK_AFTER)
+ check_prev_uid (tno);
+
+ if (action == SET && setuid (prev_suid) < 0)
+ {
+ printf ("setuid failed: %m\n");
+ exit (1);
+ }
+
+ if (action != CHECK_BEFORE)
+ {
+ uid_t ruid, euid, suid;
+ if (getresuid (&ruid, &euid, &suid) < 0)
+ {
+ printf ("getresuid failed: %d %m\n", tno);
+ exit (1);
+ }
+
+ if (ruid != nobody_uid || euid != prev_suid || suid != prev_suid)
+ {
+ printf ("after setuid %d (%d %d %d) != (%d %d %d)\n", tno,
+ ruid, euid, suid, nobody_uid, prev_suid, prev_suid);
+ exit (1);
+ }
+ }
+}
+
+
+static void
+test_seteuid1 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ return;
+
+ if (action != CHECK_AFTER)
+ check_prev_uid (tno);
+
+ if (action == SET && seteuid (nobody_uid) < 0)
+ {
+ printf ("seteuid failed: %m\n");
+ exit (1);
+ }
+
+ if (action != CHECK_BEFORE)
+ {
+ uid_t ruid, euid, suid;
+ if (getresuid (&ruid, &euid, &suid) < 0)
+ {
+ printf ("getresuid failed: %d %m\n", tno);
+ exit (1);
+ }
+
+ if (ruid != prev_ruid || euid != nobody_uid || suid != prev_suid)
+ {
+ printf ("after seteuid %d (%d %d %d) != (%d %d %d)\n", tno,
+ ruid, euid, suid, prev_ruid, nobody_uid, prev_suid);
+ exit (1);
+ }
+ }
+}
+
+
+static void
+test_seteuid2 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ {
+ if (setresuid (nobody_uid, nobody_uid, -1) < 0)
+ {
+ printf ("setresuid failed: %m\n");
+ exit (1);
+ }
+
+ prev_ruid = nobody_uid;
+ prev_euid = nobody_uid;
+ nobody_uid = prev_suid;
+ return;
+ }
+
+ test_seteuid1 (action, tno);
+}
+
+
+static void
+test_setreuid1 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ return;
+
+ if (action != CHECK_AFTER)
+ check_prev_uid (tno);
+
+ if (action == SET && setreuid (-1, nobody_uid) < 0)
+ {
+ printf ("setreuid failed: %m\n");
+ exit (1);
+ }
+
+ if (action != CHECK_BEFORE)
+ {
+ uid_t ruid, euid, suid, esuid;
+ if (getresuid (&ruid, &euid, &suid) < 0)
+ {
+ printf ("getresuid failed: %d %m\n", tno);
+ exit (1);
+ }
+
+ if (prev_ruid != nobody_uid)
+ esuid = nobody_uid;
+ else
+ esuid = prev_suid;
+
+ if (ruid != prev_ruid || euid != nobody_uid || suid != esuid)
+ {
+ printf ("after setreuid %d (%d %d %d) != (%d %d %d)\n", tno,
+ ruid, euid, suid, prev_ruid, nobody_uid, esuid);
+ exit (1);
+ }
+ }
+}
+
+
+static void
+test_setreuid2 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ return;
+
+ if (action != CHECK_AFTER)
+ check_prev_uid (tno);
+
+ if (action == SET && setreuid (nobody_uid, -1) < 0)
+ {
+ printf ("setreuid failed: %m\n");
+ exit (1);
+ }
+
+ if (action != CHECK_BEFORE)
+ {
+ uid_t ruid, euid, suid;
+ if (getresuid (&ruid, &euid, &suid) < 0)
+ {
+ printf ("getresuid failed: %d %m\n", tno);
+ exit (1);
+ }
+
+ if (ruid != nobody_uid || euid != prev_euid || suid != prev_euid)
+ {
+ printf ("after setreuid %d (%d %d %d) != (%d %d %d)\n", tno,
+ ruid, euid, suid, nobody_uid, prev_euid, prev_euid);
+ exit (1);
+ }
+ }
+}
+
+
+static void
+test_setreuid3 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ return;
+
+ if (action != CHECK_AFTER)
+ check_prev_uid (tno);
+
+ if (action == SET && setreuid (nobody_uid, nobody_uid) < 0)
+ {
+ printf ("setreuid failed: %m\n");
+ exit (1);
+ }
+
+ if (action != CHECK_BEFORE)
+ {
+ uid_t ruid, euid, suid;
+ if (getresuid (&ruid, &euid, &suid) < 0)
+ {
+ printf ("getresuid failed: %d %m\n", tno);
+ exit (1);
+ }
+
+ if (ruid != nobody_uid || euid != nobody_uid || suid != nobody_uid)
+ {
+ printf ("after setreuid %d (%d %d %d) != (%d %d %d)\n", tno,
+ ruid, euid, suid, nobody_uid, nobody_uid, nobody_uid);
+ exit (1);
+ }
+ }
+}
+
+
+static void
+test_setreuid4 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ {
+ if (setresuid (nobody_uid, nobody_uid, -1) < 0)
+ {
+ printf ("setresuid failed: %m\n");
+ exit (1);
+ }
+
+ prev_ruid = nobody_uid;
+ prev_euid = nobody_uid;
+ nobody_uid = prev_suid;
+ return;
+ }
+
+ test_setreuid1 (action, tno);
+}
+
+
+static void
+test_setresuid1 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ return;
+
+ if (action != CHECK_AFTER)
+ check_prev_uid (tno);
+
+ if (action == SET && setresuid (-1, nobody_uid, -1) < 0)
+ {
+ printf ("setresuid failed: %m\n");
+ exit (1);
+ }
+
+ if (action != CHECK_BEFORE)
+ {
+ uid_t ruid, euid, suid;
+ if (getresuid (&ruid, &euid, &suid) < 0)
+ {
+ printf ("getresuid failed: %d %m\n", tno);
+ exit (1);
+ }
+
+ if (ruid != prev_ruid || euid != nobody_uid || suid != prev_suid)
+ {
+ printf ("after setresuid %d (%d %d %d) != (%d %d %d)\n", tno,
+ ruid, euid, suid, prev_ruid, nobody_uid, prev_suid);
+ exit (1);
+ }
+ }
+}
+
+
+static void
+test_setresuid2 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ return;
+
+ if (action != CHECK_AFTER)
+ check_prev_uid (tno);
+
+ if (action == SET && setresuid (prev_euid, nobody_uid, nobody_uid) < 0)
+ {
+ printf ("setresuid failed: %m\n");
+ exit (1);
+ }
+
+ if (action != CHECK_BEFORE)
+ {
+ uid_t ruid, euid, suid;
+ if (getresuid (&ruid, &euid, &suid) < 0)
+ {
+ printf ("getresuid failed: %d %m\n", tno);
+ exit (1);
+ }
+
+ if (ruid != prev_euid || euid != nobody_uid || suid != nobody_uid)
+ {
+ printf ("after setresuid %d (%d %d %d) != (%d %d %d)\n", tno,
+ ruid, euid, suid, prev_euid, nobody_uid, nobody_uid);
+ exit (1);
+ }
+ }
+}
+
+
+static void
+test_setresuid3 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ return;
+
+ if (action != CHECK_AFTER)
+ check_prev_uid (tno);
+
+ if (action == SET && setresuid (nobody_uid, nobody_uid, nobody_uid) < 0)
+ {
+ printf ("setresuid failed: %m\n");
+ exit (1);
+ }
+
+ if (action != CHECK_BEFORE)
+ {
+ uid_t ruid, euid, suid;
+ if (getresuid (&ruid, &euid, &suid) < 0)
+ {
+ printf ("getresuid failed: %d %m\n", tno);
+ exit (1);
+ }
+
+ if (ruid != nobody_uid || euid != nobody_uid || suid != nobody_uid)
+ {
+ printf ("after setresuid %d (%d %d %d) != (%d %d %d)\n", tno,
+ ruid, euid, suid, nobody_uid, nobody_uid, nobody_uid);
+ exit (1);
+ }
+ }
+}
+
+
+static void
+test_setresuid4 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ {
+ if (setresuid (nobody_uid, nobody_uid, -1) < 0)
+ {
+ printf ("setresuid failed: %m\n");
+ exit (1);
+ }
+
+ prev_ruid = nobody_uid;
+ prev_euid = nobody_uid;
+ nobody_uid = prev_suid;
+ return;
+ }
+
+ test_setresuid1 (action, tno);
+}
+
+
+static void
+test_setgid1 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ return;
+
+ if (action != CHECK_AFTER)
+ check_prev_gid (tno);
+
+ if (action == SET && setgid (nobody_gid) < 0)
+ {
+ printf ("setgid failed: %m\n");
+ exit (1);
+ }
+
+ if (action != CHECK_BEFORE)
+ {
+ gid_t rgid, egid, sgid;
+ if (getresgid (&rgid, &egid, &sgid) < 0)
+ {
+ printf ("getresgid failed: %d %m\n", tno);
+ exit (1);
+ }
+
+ if (rgid != nobody_gid || egid != nobody_gid || sgid != nobody_gid)
+ {
+ printf ("after setgid %d (%d %d %d) != (%d %d %d)\n", tno,
+ rgid, egid, sgid, nobody_gid, nobody_gid, nobody_gid);
+ exit (1);
+ }
+ }
+}
+
+
+static void
+test_setgid2 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ {
+ if (setresgid (nobody_gid, nobody_gid, -1) < 0)
+ {
+ printf ("setresgid failed: %m\n");
+ exit (1);
+ }
+
+ prev_rgid = nobody_gid;
+ prev_egid = nobody_gid;
+
+ if (setresuid (nobody_uid, nobody_uid, -1) < 0)
+ {
+ printf ("setresuid failed: %m\n");
+ exit (1);
+ }
+
+ prev_ruid = nobody_uid;
+ prev_euid = nobody_uid;
+ return;
+ }
+
+ if (action != CHECK_AFTER)
+ check_prev_gid (tno);
+
+ if (action == SET && setgid (prev_sgid) < 0)
+ {
+ printf ("setgid failed: %m\n");
+ exit (1);
+ }
+
+ if (action != CHECK_BEFORE)
+ {
+ gid_t rgid, egid, sgid;
+ if (getresgid (&rgid, &egid, &sgid) < 0)
+ {
+ printf ("getresgid failed: %d %m\n", tno);
+ exit (1);
+ }
+
+ if (rgid != nobody_gid || egid != prev_sgid || sgid != prev_sgid)
+ {
+ printf ("after setgid %d (%d %d %d) != (%d %d %d)\n", tno,
+ rgid, egid, sgid, nobody_gid, prev_sgid, prev_sgid);
+ exit (1);
+ }
+ }
+}
+
+
+static void
+test_setegid1 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ return;
+
+ if (action != CHECK_AFTER)
+ check_prev_gid (tno);
+
+ if (action == SET && setegid (nobody_gid) < 0)
+ {
+ printf ("setegid failed: %m\n");
+ exit (1);
+ }
+
+ if (action != CHECK_BEFORE)
+ {
+ gid_t rgid, egid, sgid;
+ if (getresgid (&rgid, &egid, &sgid) < 0)
+ {
+ printf ("getresgid failed: %d %m\n", tno);
+ exit (1);
+ }
+
+ if (rgid != prev_rgid || egid != nobody_gid || sgid != prev_sgid)
+ {
+ printf ("after setegid %d (%d %d %d) != (%d %d %d)\n", tno,
+ rgid, egid, sgid, prev_rgid, nobody_gid, prev_sgid);
+ exit (1);
+ }
+ }
+}
+
+
+static void
+test_setegid2 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ {
+ if (setresgid (nobody_gid, nobody_gid, -1) < 0)
+ {
+ printf ("setresgid failed: %m\n");
+ exit (1);
+ }
+
+ prev_rgid = nobody_gid;
+ prev_egid = nobody_gid;
+ nobody_gid = prev_sgid;
+ return;
+ }
+
+ test_setegid1 (action, tno);
+}
+
+
+static void
+test_setregid1 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ return;
+
+ if (action != CHECK_AFTER)
+ check_prev_gid (tno);
+
+ if (action == SET && setregid (-1, nobody_gid) < 0)
+ {
+ printf ("setregid failed: %m\n");
+ exit (1);
+ }
+
+ if (action != CHECK_BEFORE)
+ {
+ gid_t rgid, egid, sgid, esgid;
+ if (getresgid (&rgid, &egid, &sgid) < 0)
+ {
+ printf ("getresgid failed: %d %m\n", tno);
+ exit (1);
+ }
+
+ if (prev_rgid != nobody_gid)
+ esgid = nobody_gid;
+ else
+ esgid = prev_sgid;
+
+ if (rgid != prev_rgid || egid != nobody_gid || sgid != esgid)
+ {
+ printf ("after setregid %d (%d %d %d) != (%d %d %d)\n", tno,
+ rgid, egid, sgid, prev_rgid, nobody_gid, esgid);
+ exit (1);
+ }
+ }
+}
+
+
+static void
+test_setregid2 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ return;
+
+ if (action != CHECK_AFTER)
+ check_prev_gid (tno);
+
+ if (action == SET && setregid (nobody_gid, -1) < 0)
+ {
+ printf ("setregid failed: %m\n");
+ exit (1);
+ }
+
+ if (action != CHECK_BEFORE)
+ {
+ gid_t rgid, egid, sgid;
+ if (getresgid (&rgid, &egid, &sgid) < 0)
+ {
+ printf ("getresgid failed: %d %m\n", tno);
+ exit (1);
+ }
+
+ if (rgid != nobody_gid || egid != prev_egid || sgid != prev_egid)
+ {
+ printf ("after setregid %d (%d %d %d) != (%d %d %d)\n", tno,
+ rgid, egid, sgid, nobody_gid, prev_egid, prev_egid);
+ exit (1);
+ }
+ }
+}
+
+
+static void
+test_setregid3 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ return;
+
+ if (action != CHECK_AFTER)
+ check_prev_gid (tno);
+
+ if (action == SET && setregid (nobody_gid, nobody_gid) < 0)
+ {
+ printf ("setregid failed: %m\n");
+ exit (1);
+ }
+
+ if (action != CHECK_BEFORE)
+ {
+ gid_t rgid, egid, sgid;
+ if (getresgid (&rgid, &egid, &sgid) < 0)
+ {
+ printf ("getresgid failed: %d %m\n", tno);
+ exit (1);
+ }
+
+ if (rgid != nobody_gid || egid != nobody_gid || sgid != nobody_gid)
+ {
+ printf ("after setregid %d (%d %d %d) != (%d %d %d)\n", tno,
+ rgid, egid, sgid, nobody_gid, nobody_gid, nobody_gid);
+ exit (1);
+ }
+ }
+}
+
+
+static void
+test_setregid4 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ {
+ if (setresgid (nobody_gid, nobody_gid, -1) < 0)
+ {
+ printf ("setresgid failed: %m\n");
+ exit (1);
+ }
+
+ prev_rgid = nobody_gid;
+ prev_egid = nobody_gid;
+ nobody_gid = prev_sgid;
+ return;
+ }
+
+ test_setregid1 (action, tno);
+}
+
+
+static void
+test_setresgid1 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ return;
+
+ if (action != CHECK_AFTER)
+ check_prev_gid (tno);
+
+ if (action == SET && setresgid (-1, nobody_gid, -1) < 0)
+ {
+ printf ("setresgid failed: %m\n");
+ exit (1);
+ }
+
+ if (action != CHECK_BEFORE)
+ {
+ gid_t rgid, egid, sgid;
+ if (getresgid (&rgid, &egid, &sgid) < 0)
+ {
+ printf ("getresgid failed: %d %m\n", tno);
+ exit (1);
+ }
+
+ if (rgid != prev_rgid || egid != nobody_gid || sgid != prev_sgid)
+ {
+ printf ("after setresgid %d (%d %d %d) != (%d %d %d)\n", tno,
+ rgid, egid, sgid, prev_rgid, nobody_gid, prev_sgid);
+ exit (1);
+ }
+ }
+}
+
+
+static void
+test_setresgid2 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ return;
+
+ if (action != CHECK_AFTER)
+ check_prev_gid (tno);
+
+ if (action == SET && setresgid (prev_egid, nobody_gid, nobody_gid) < 0)
+ {
+ printf ("setresgid failed: %m\n");
+ exit (1);
+ }
+
+ if (action != CHECK_BEFORE)
+ {
+ gid_t rgid, egid, sgid;
+ if (getresgid (&rgid, &egid, &sgid) < 0)
+ {
+ printf ("getresgid failed: %d %m\n", tno);
+ exit (1);
+ }
+
+ if (rgid != prev_egid || egid != nobody_gid || sgid != nobody_gid)
+ {
+ printf ("after setresgid %d (%d %d %d) != (%d %d %d)\n", tno,
+ rgid, egid, sgid, prev_egid, nobody_gid, nobody_gid);
+ exit (1);
+ }
+ }
+}
+
+
+static void
+test_setresgid3 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ return;
+
+ if (action != CHECK_AFTER)
+ check_prev_gid (tno);
+
+ if (action == SET && setresgid (nobody_gid, nobody_gid, nobody_gid) < 0)
+ {
+ printf ("setresgid failed: %m\n");
+ exit (1);
+ }
+
+ if (action != CHECK_BEFORE)
+ {
+ gid_t rgid, egid, sgid;
+ if (getresgid (&rgid, &egid, &sgid) < 0)
+ {
+ printf ("getresgid failed: %d %m\n", tno);
+ exit (1);
+ }
+
+ if (rgid != nobody_gid || egid != nobody_gid || sgid != nobody_gid)
+ {
+ printf ("after setresgid %d (%d %d %d) != (%d %d %d)\n", tno,
+ rgid, egid, sgid, nobody_gid, nobody_gid, nobody_gid);
+ exit (1);
+ }
+ }
+}
+
+
+static void
+test_setresgid4 (enum ACTION action, int tno)
+{
+ if (action == PREPARE)
+ {
+ if (setresgid (nobody_gid, nobody_gid, -1) < 0)
+ {
+ printf ("setresgid failed: %m\n");
+ exit (1);
+ }
+
+ prev_rgid = nobody_gid;
+ prev_egid = nobody_gid;
+ nobody_gid = prev_sgid;
+ return;
+ }
+
+ test_setresgid1 (action, tno);
+}
+
+
+static struct setuid_test
+{
+ const char *name;
+ void (*test) (enum ACTION, int tno);
+} setuid_tests[] =
+{
+ { "setuid1", test_setuid1 },
+ { "setuid2", test_setuid2 },
+ { "seteuid1", test_seteuid1 },
+ { "seteuid2", test_seteuid2 },
+ { "setreuid1", test_setreuid1 },
+ { "setreuid2", test_setreuid2 },
+ { "setreuid3", test_setreuid3 },
+ { "setreuid4", test_setreuid4 },
+ { "setresuid1", test_setresuid1 },
+ { "setresuid2", test_setresuid2 },
+ { "setresuid3", test_setresuid3 },
+ { "setresuid4", test_setresuid4 },
+ { "setgid1", test_setgid1 },
+ { "setgid2", test_setgid2 },
+ { "setegid1", test_setegid1 },
+ { "setegid2", test_setegid2 },
+ { "setregid1", test_setregid1 },
+ { "setregid2", test_setregid2 },
+ { "setregid3", test_setregid3 },
+ { "setregid4", test_setregid4 },
+ { "setresgid1", test_setresgid1 },
+ { "setresgid2", test_setresgid2 },
+ { "setresgid3", test_setresgid3 },
+ { "setresgid4", test_setresgid4 }
+};
+
+
+static void *
+tf2 (void *arg)
+{
+ int e = pthread_barrier_wait (&b4);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ setuid_tests[TESTNO (arg)].test (CHECK_AFTER, THREADNO (arg));
+ return NULL;
+}
+
+
+static void *
+tf (void *arg)
+{
+ setuid_tests[TESTNO (arg)].test (CHECK_BEFORE, THREADNO (arg));
+
+ int e = pthread_barrier_wait (&b3);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ return tf2 (arg);
+}
+
+
+static int
+do_one_test (long int testno)
+{
+ printf ("%s test\n", setuid_tests[testno].name);
+
+ pid_t pid = fork ();
+ if (pid == 0)
+ {
+ setuid_tests[testno].test (PREPARE, 0);
+ setuid_tests[testno].test (SET, 0);
+ exit (0);
+ }
+
+ if (pid < 0)
+ {
+ printf ("fork failed: %m\n");
+ exit (1);
+ }
+
+ int status;
+ if (waitpid (pid, &status, 0) < 0)
+ {
+ printf ("waitpid failed: %m\n");
+ exit (1);
+ }
+
+ if (!WIFEXITED (status))
+ {
+ puts ("child did not exit");
+ exit (1);
+ }
+
+ if (WEXITSTATUS (status))
+ {
+ printf ("skipping %s test\n", setuid_tests[testno].name);
+ return 0;
+ }
+
+ pid = fork ();
+ if (pid == 0)
+ {
+ setuid_tests[testno].test (PREPARE, 0);
+
+ pthread_t th;
+ int e = pthread_create (&th, NULL, tf, (void *) (testno | 0x100L));
+ if (e != 0)
+ {
+ printf ("create failed: %m\n");
+ exit (1);
+ }
+
+ pthread_t th2;
+ e = pthread_create (&th2, NULL, tf, (void *) (testno | 0x200L));
+ if (e != 0)
+ {
+ printf ("create failed: %m\n");
+ exit (1);
+ }
+
+ e = pthread_barrier_wait (&b3);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ setuid_tests[testno].test (SET, 0);
+
+ pthread_t th3;
+ e = pthread_create (&th3, NULL, tf2, (void *) (testno | 0x300L));
+ if (e != 0)
+ {
+ printf ("create failed: %m\n");
+ exit (1);
+ }
+
+ e = pthread_barrier_wait (&b4);
+ if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ exit (1);
+ }
+
+ exit (0);
+ }
+
+ if (pid < 0)
+ {
+ printf ("fork failed: %m\n");
+ exit (1);
+ }
+
+ if (waitpid (pid, &status, 0) < 0)
+ {
+ printf ("waitpid failed: %m\n");
+ exit (1);
+ }
+
+ if (!WIFEXITED (status))
+ {
+ puts ("second child did not exit");
+ exit (1);
+ }
+
+ if (WEXITSTATUS (status))
+ exit (WEXITSTATUS (status));
+
+ return 0;
+}
+
+
+static int
+do_test (void)
+{
+ struct passwd *pwd = getpwnam ("nobody");
+ if (pwd == NULL)
+ {
+ puts ("User nobody doesn't exist");
+ return 0;
+ }
+ nobody_uid = pwd->pw_uid;
+ nobody_gid = pwd->pw_gid;
+
+ if (getresuid (&prev_ruid, &prev_euid, &prev_suid) < 0)
+ {
+ printf ("getresuid failed: %m\n");
+ exit (1);
+ }
+
+ if (getresgid (&prev_rgid, &prev_egid, &prev_sgid) < 0)
+ {
+ printf ("getresgid failed: %m\n");
+ exit (1);
+ }
+
+ if (prev_ruid == nobody_uid || prev_euid == nobody_uid
+ || prev_suid == nobody_uid)
+ {
+ puts ("already running as user nobody, skipping tests");
+ exit (0);
+ }
+
+ if (prev_rgid == nobody_gid || prev_egid == nobody_gid
+ || prev_sgid == nobody_gid)
+ {
+ puts ("already running as group nobody, skipping tests");
+ exit (0);
+ }
+
+ if (pthread_barrier_init (&b3, NULL, 3) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ if (pthread_barrier_init (&b4, NULL, 4) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ for (unsigned long int testno = 0;
+ testno < sizeof (setuid_tests) / sizeof (setuid_tests[0]);
+ ++testno)
+ do_one_test (testno);
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-signal1.c b/libc/nptl/tst-signal1.c
new file mode 100644
index 000000000..3022f1846
--- /dev/null
+++ b/libc/nptl/tst-signal1.c
@@ -0,0 +1,189 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+
+
+static sigset_t ss;
+static pthread_barrier_t *b;
+
+
+static void *
+tf (void *arg)
+{
+ sigdelset (&ss, SIGINT);
+
+ if (pthread_sigmask (SIG_SETMASK, &ss, NULL) != 0)
+ {
+ puts ("2nd pthread_sigmask failed");
+ exit (1);
+ }
+
+ pthread_barrier_wait (b);
+
+ int sig;
+ int res = sigwait (&ss, &sig);
+ if (res == 0)
+ {
+ printf ("sigwait returned successfully with signal %d\n", sig);
+ exit (1);
+ }
+
+ printf ("sigwait returned with %s (%d)\n", strerror (res), res);
+
+ return NULL;
+}
+
+
+static void
+receiver (void)
+{
+ pthread_t th;
+
+ /* Make sure the process doesn't run forever. */
+ alarm (10);
+
+ sigfillset (&ss);
+
+ if (pthread_sigmask (SIG_SETMASK, &ss, NULL) != 0)
+ {
+ puts ("1st pthread_sigmask failed");
+ exit (1);
+ }
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("pthread_create failed");
+ exit (1);
+ }
+
+ if (pthread_join (th, NULL) == 0)
+ {
+ puts ("thread joined?!");
+ exit (1);
+ }
+
+ _exit (0);
+}
+
+
+static int
+do_test (void)
+{
+ char tmp[] = "/tmp/tst-signal1-XXXXXX";
+
+ int fd = mkstemp (tmp);
+ if (fd == -1)
+ {
+ puts ("mkstemp failed");
+ exit (1);
+ }
+
+ unlink (tmp);
+
+ int i;
+ for (i = 0; i < 20; ++i)
+ write (fd, "foobar xyzzy", 12);
+
+ b = mmap (NULL, sizeof (pthread_barrier_t), PROT_READ | PROT_WRITE,
+ MAP_SHARED, fd, 0);
+ if (b == MAP_FAILED)
+ {
+ puts ("mmap failed");
+ exit (1);
+ }
+
+ pthread_barrierattr_t ba;
+ if (pthread_barrierattr_init (&ba) != 0)
+ {
+ puts ("barrierattr_init failed");
+ exit (1);
+ }
+
+ if (pthread_barrierattr_setpshared (&ba, PTHREAD_PROCESS_SHARED) != 0)
+ {
+ puts ("barrierattr_setpshared failed");
+ exit (1);
+ }
+
+ if (pthread_barrier_init (b, &ba, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ if (pthread_barrierattr_destroy (&ba) != 0)
+ {
+ puts ("barrierattr_destroy failed");
+ exit (1);
+ }
+
+ pid_t pid = fork ();
+ if (pid == -1)
+ {
+ puts ("fork failed");
+ exit (1);
+ }
+
+ if (pid == 0)
+ receiver ();
+
+ pthread_barrier_wait (b);
+
+ /* Wait a bit more. */
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 10000000 };
+ nanosleep (&ts, NULL);
+
+ /* Send the signal. */
+ puts ("sending the signal now");
+ kill (pid, SIGINT);
+
+ /* Wait for the process to terminate. */
+ int status;
+ if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid)
+ {
+ puts ("wrong child reported terminated");
+ exit (1);
+ }
+
+ if (!WIFSIGNALED (status))
+ {
+ puts ("child wasn't signalled");
+ exit (1);
+ }
+
+ if (WTERMSIG (status) != SIGINT)
+ {
+ puts ("child not terminated with SIGINT");
+ exit (1);
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-signal2.c b/libc/nptl/tst-signal2.c
new file mode 100644
index 000000000..3f2c75d1f
--- /dev/null
+++ b/libc/nptl/tst-signal2.c
@@ -0,0 +1,198 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+#include <string.h>
+
+
+static sigset_t ss;
+static pthread_barrier_t *b;
+
+
+static void *
+tf (void *arg)
+{
+ pthread_barrier_wait (b);
+
+ puts ("child: calling sigwait now");
+
+ int sig;
+ int err;
+ err = sigwait (&ss, &sig);
+ if (err != 0)
+ {
+ printf ("sigwait returned unsuccessfully: %s (%d)\n",
+ strerror (err), err);
+ _exit (1);
+ }
+
+ puts ("sigwait returned");
+
+ if (sig != SIGINT)
+ {
+ printf ("caught signal %d, expected %d (SIGINT)\n", sig, SIGINT);
+ _exit (1);
+ }
+
+ puts ("child thread terminating now");
+
+ return NULL;
+}
+
+
+static void
+receiver (void)
+{
+ pthread_t th;
+
+ /* Make sure the process doesn't run forever. */
+ alarm (10);
+
+ sigfillset (&ss);
+
+ if (pthread_sigmask (SIG_SETMASK, &ss, NULL) != 0)
+ {
+ puts ("1st pthread_sigmask failed");
+ _exit (1);
+ }
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("pthread_create failed");
+ _exit (1);
+ }
+
+ if (pthread_join (th, NULL) != 0)
+ {
+ puts ("thread didn't join");
+ _exit (1);
+ }
+
+ puts ("join succeeded");
+
+ _exit (0);
+}
+
+
+static int
+do_test (void)
+{
+ char tmp[] = "/tmp/tst-signal1-XXXXXX";
+
+ int fd = mkstemp (tmp);
+ if (fd == -1)
+ {
+ puts ("mkstemp failed");
+ exit (1);
+ }
+
+ unlink (tmp);
+
+ int i;
+ for (i = 0; i < 20; ++i)
+ write (fd, "foobar xyzzy", 12);
+
+ b = mmap (NULL, sizeof (pthread_barrier_t), PROT_READ | PROT_WRITE,
+ MAP_SHARED, fd, 0);
+ if (b == MAP_FAILED)
+ {
+ puts ("mmap failed");
+ exit (1);
+ }
+
+ pthread_barrierattr_t ba;
+ if (pthread_barrierattr_init (&ba) != 0)
+ {
+ puts ("barrierattr_init failed");
+ exit (1);
+ }
+
+ if (pthread_barrierattr_setpshared (&ba, PTHREAD_PROCESS_SHARED) != 0)
+ {
+ puts ("barrierattr_setpshared failed");
+ exit (1);
+ }
+
+ if (pthread_barrier_init (b, &ba, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ if (pthread_barrierattr_destroy (&ba) != 0)
+ {
+ puts ("barrierattr_destroy failed");
+ exit (1);
+ }
+
+ pid_t pid = fork ();
+ if (pid == -1)
+ {
+ puts ("fork failed");
+ exit (1);
+ }
+
+ if (pid == 0)
+ receiver ();
+
+ pthread_barrier_wait (b);
+
+ /* Wait a bit more. */
+ struct timespec ts = { .tv_sec = 0, .tv_nsec = 10000000 };
+ nanosleep (&ts, NULL);
+
+ /* Send the signal. */
+ puts ("sending the signal now");
+ kill (pid, SIGINT);
+
+ /* Wait for the process to terminate. */
+ int status;
+ if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid)
+ {
+ puts ("wrong child reported terminated");
+ exit (1);
+ }
+
+ if (!WIFEXITED (status))
+ {
+ if (WIFSIGNALED (status))
+ printf ("child exited with signal %d\n", WTERMSIG (status));
+ else
+ puts ("child didn't exit normally");
+ exit (1);
+ }
+
+ if (WEXITSTATUS (status) != 0)
+ {
+ printf ("exit status %d != 0\n", WEXITSTATUS (status));
+ exit (1);
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-signal3.c b/libc/nptl/tst-signal3.c
new file mode 100644
index 000000000..e4756c56a
--- /dev/null
+++ b/libc/nptl/tst-signal3.c
@@ -0,0 +1,261 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+/* Number of different signalss to use. Also is the number of
+ threads. */
+#define N 10
+/* Maximum number of threads in flight at any one time. */
+#define INFLIGHT 5
+/* Number of signals sent in total. */
+#define ROUNDS 10000
+
+
+static int received[N][N];
+static int nsig[N];
+static pthread_t th[N];
+static sem_t sem;
+static pthread_mutex_t lock[N];
+static pthread_t th_main;
+static int sig0;
+
+static void
+handler (int sig)
+{
+ int i;
+ for (i = 0; i < N; ++i)
+ if (pthread_equal (pthread_self (), th[i]))
+ break;
+
+ if (i == N)
+ {
+ if (pthread_equal (pthread_self (), th_main))
+ puts ("signal received by main thread");
+ else
+ printf ("signal received by unknown thread (%lx)\n",
+ (unsigned long int) pthread_self ());
+ exit (1);
+ }
+
+ ++received[i][sig - sig0];
+
+ sem_post (&sem);
+}
+
+
+static void *
+tf (void *arg)
+{
+ int idx = (long int) arg;
+
+ sigset_t ss;
+ sigemptyset (&ss);
+
+ int i;
+ for (i = 0; i <= idx; ++i)
+ sigaddset (&ss, sig0 + i);
+
+ if (pthread_sigmask (SIG_UNBLOCK, &ss, NULL) != 0)
+ {
+ printf ("thread %d: pthread_sigmask failed\n", i);
+ exit (1);
+ }
+
+ pthread_mutex_lock (&lock[idx]);
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ /* Block all signals. */
+ sigset_t ss;
+ sigfillset (&ss);
+
+ th_main = pthread_self ();
+
+ sig0 = SIGRTMIN;
+
+ if (pthread_sigmask (SIG_SETMASK, &ss, NULL) != 0)
+ {
+ puts ("1st pthread_sigmask failed");
+ exit (1);
+ }
+
+ /* Install the handler. */
+ int i;
+ for (i = 0; i < N; ++i)
+ {
+ struct sigaction sa =
+ {
+ .sa_handler = handler,
+ .sa_flags = 0
+ };
+ sigfillset (&sa.sa_mask);
+
+ if (sigaction (sig0 + i, &sa, NULL) != 0)
+ {
+ printf ("sigaction for signal %d failed\n", i);
+ exit (1);
+ }
+ }
+
+ if (sem_init (&sem, 0, INFLIGHT) != 0)
+ {
+ puts ("sem_init failed");
+ exit (1);
+ }
+
+ pthread_attr_t a;
+
+ if (pthread_attr_init (&a) != 0)
+ {
+ puts ("attr_init failed");
+ exit (1);
+ }
+
+ if (pthread_attr_setstacksize (&a, 1 * 1024 * 1024) != 0)
+ {
+ puts ("attr_setstacksize failed");
+ return 1;
+ }
+
+ for (i = 0; i < N; ++i)
+ {
+ if (pthread_mutex_init (&lock[i], NULL) != 0)
+ {
+ printf ("mutex_init[%d] failed\n", i);
+ }
+
+ if (pthread_mutex_lock (&lock[i]) != 0)
+ {
+ printf ("mutex_lock[%d] failed\n", i);
+ }
+
+ if (pthread_create (&th[i], &a, tf, (void *) (long int) i) != 0)
+ {
+ printf ("create of thread %d failed\n", i);
+ exit (1);
+ }
+ }
+
+ if (pthread_attr_destroy (&a) != 0)
+ {
+ puts ("attr_destroy failed");
+ exit (1);
+ }
+
+ int result = 0;
+ unsigned int r = 42;
+ pid_t pid = getpid ();
+
+ for (i = 0; i < ROUNDS; ++i)
+ {
+ if (TEMP_FAILURE_RETRY (sem_wait (&sem)) != 0)
+ {
+ printf ("sem_wait round %d failed: %m\n", i);
+ exit (1);
+ }
+
+ int s = rand_r (&r) % N;
+
+ kill (pid, sig0 + s);
+ }
+
+ void *status;
+ for (i = 0; i < N; ++i)
+ {
+ if (pthread_mutex_unlock (&lock[i]) != 0)
+ {
+ printf ("unlock %d failed\n", i);
+ exit (1);
+ }
+
+ if (pthread_join (th[i], &status) != 0)
+ {
+ printf ("join %d failed\n", i);
+ result = 1;
+ }
+ else if (status != NULL)
+ {
+ printf ("%d: result != NULL\n", i);
+ result = 1;
+ }
+ }
+
+ int total = 0;
+ for (i = 0; i < N; ++i)
+ {
+ int j;
+
+ for (j = 0; j <= i; ++j)
+ total += received[i][j];
+
+ for (j = i + 1; j < N; ++j)
+ if (received[i][j] != 0)
+ {
+ printf ("thread %d received signal SIGRTMIN+%d\n", i, j);
+ result = 1;
+ }
+ }
+
+ if (total != ROUNDS)
+ {
+ printf ("total number of handled signals is %d, expected %d\n",
+ total, ROUNDS);
+ result = 1;
+ }
+
+ printf ("A total of %d signals sent and received\n", total);
+ for (i = 0; i < N; ++i)
+ {
+ printf ("thread %2d:", i);
+
+ int j;
+ for (j = 0; j <= i; ++j)
+ {
+ printf (" %5d", received[i][j]);
+ nsig[j] += received[i][j];
+ }
+
+ putchar ('\n');
+
+ }
+
+ printf ("\nTotal :");
+ for (i = 0; i < N; ++i)
+ printf (" %5d", nsig[i]);
+ putchar ('\n');
+
+ return result;
+}
+
+#define TIMEOUT 10
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-signal4.c b/libc/nptl/tst-signal4.c
new file mode 100644
index 000000000..dcb2893a0
--- /dev/null
+++ b/libc/nptl/tst-signal4.c
@@ -0,0 +1,60 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static int
+do_test (void)
+{
+ sigset_t ss;
+
+ sigemptyset (&ss);
+
+ int i;
+ for (i = 0; i < 10000; ++i)
+ {
+ long int r = random ();
+
+ if (r != SIG_BLOCK && r != SIG_SETMASK && r != SIG_UNBLOCK)
+ {
+ int e = pthread_sigmask (r, &ss, NULL);
+
+ if (e == 0)
+ {
+ printf ("pthread_sigmask succeeded for how = %ld\n", r);
+ exit (1);
+ }
+
+ if (e != EINVAL)
+ {
+ puts ("pthread_sigmask didn't return EINVAL");
+ exit (1);
+ }
+ }
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-signal5.c b/libc/nptl/tst-signal5.c
new file mode 100644
index 000000000..cea6ec143
--- /dev/null
+++ b/libc/nptl/tst-signal5.c
@@ -0,0 +1,111 @@
+/* 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 <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+
+
+static sigset_t ss;
+
+
+static void *
+tf (void *arg)
+{
+ sigset_t ss2;
+ if (pthread_sigmask (SIG_SETMASK, NULL, &ss2) != 0)
+ {
+ puts ("child: sigmask failed");
+ exit (1);
+ }
+
+ int i;
+ for (i = 1; i < 32; ++i)
+ if (sigismember (&ss, i) && ! sigismember (&ss2, i))
+ {
+ printf ("signal %d set in parent mask, but not in child\n", i);
+ exit (1);
+ }
+ else if (! sigismember (&ss, i) && sigismember (&ss2, i))
+ {
+ printf ("signal %d set in child mask, but not in parent\n", i);
+ exit (1);
+ }
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ sigemptyset (&ss);
+ sigaddset (&ss, SIGUSR1);
+ if (pthread_sigmask (SIG_SETMASK, &ss, NULL) != 0)
+ {
+ puts ("1st sigmask failed");
+ exit (1);
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("1st create failed");
+ exit (1);
+ }
+
+ void *r;
+ if (pthread_join (th, &r) != 0)
+ {
+ puts ("1st join failed");
+ exit (1);
+ }
+
+ sigemptyset (&ss);
+ sigaddset (&ss, SIGUSR2);
+ sigaddset (&ss, SIGFPE);
+ if (pthread_sigmask (SIG_SETMASK, &ss, NULL) != 0)
+ {
+ puts ("2nd sigmask failed");
+ exit (1);
+ }
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("2nd create failed");
+ exit (1);
+ }
+
+ if (pthread_join (th, &r) != 0)
+ {
+ puts ("2nd join failed");
+ exit (1);
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-signal6.c b/libc/nptl/tst-signal6.c
new file mode 100644
index 000000000..85a864002
--- /dev/null
+++ b/libc/nptl/tst-signal6.c
@@ -0,0 +1,192 @@
+/* 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>
+#include <signal.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+#define N 2
+static pthread_barrier_t bar;
+static struct
+{
+ void *p;
+ pthread_t s;
+} ti[N];
+static int sig1;
+
+
+static void
+handler (int sig)
+{
+ pthread_t self = pthread_self ();
+ size_t i;
+
+ for (i = 0; i < N; ++i)
+ if (ti[i].s == self)
+ {
+ if ((uintptr_t) ti[i].p <= (uintptr_t) &self
+ && (uintptr_t) ti[i].p + 2 * MINSIGSTKSZ > (uintptr_t) &self)
+ {
+ puts ("alt stack not used");
+ exit (1);
+ }
+
+ printf ("thread %zu used alt stack for signal %d\n", i, sig);
+
+ return;
+ }
+
+ puts ("handler: thread not found");
+ exit (1);
+}
+
+
+static void *
+tf (void *arg)
+{
+ size_t nr = (uintptr_t) arg;
+ if (nr >= N)
+ {
+ puts ("wrong nr parameter");
+ exit (1);
+ }
+
+ sigset_t ss;
+ sigemptyset (&ss);
+ size_t i;
+ for (i = 0; i < N; ++i)
+ if (i != nr)
+ if (sigaddset (&ss, sig1 + i) != 0)
+ {
+ puts ("tf: sigaddset failed");
+ exit (1);
+ }
+ if (pthread_sigmask (SIG_BLOCK, &ss, NULL) != 0)
+ {
+ puts ("tf: sigmask failed");
+ exit (1);
+ }
+
+ void *p = malloc (2 * MINSIGSTKSZ);
+ if (p == NULL)
+ {
+ puts ("tf: malloc failed");
+ exit (1);
+ }
+
+ stack_t s;
+ s.ss_sp = p;
+ s.ss_size = 2 * MINSIGSTKSZ;
+ s.ss_flags = 0;
+ if (sigaltstack (&s, NULL) != 0)
+ {
+ puts ("tf: sigaltstack failed");
+ exit (1);
+ }
+
+ ti[nr].p = p;
+ ti[nr].s = pthread_self ();
+
+ pthread_barrier_wait (&bar);
+
+ pthread_barrier_wait (&bar);
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ sig1 = SIGRTMIN;
+ if (sig1 + N > SIGRTMAX)
+ {
+ puts ("too few RT signals");
+ return 0;
+ }
+
+ struct sigaction sa;
+ sa.sa_handler = handler;
+ sa.sa_flags = 0;
+ sigemptyset (&sa.sa_mask);
+
+ if (sigaction (sig1, &sa, NULL) != 0
+ || sigaction (sig1 + 1, &sa, NULL) != 0
+ || sigaction (sig1 + 2, &sa, NULL) != 0)
+ {
+ puts ("sigaction failed");
+ return 1;
+ }
+
+ if (pthread_barrier_init (&bar, NULL, 1 + N) != 0)
+ {
+ puts ("barrier_init failed");
+ return 1;
+ }
+
+ pthread_t th[N];
+ size_t i;
+ for (i = 0; i < N; ++i)
+ if (pthread_create (&th[i], NULL, tf, (void *) (long int) i) != 0)
+ {
+ puts ("create failed");
+ return 1;
+ }
+
+ /* Block the three signals. */
+ sigset_t ss;
+ sigemptyset (&ss);
+ for (i = 0; i <= N; ++i)
+ sigaddset (&ss, sig1 + i);
+ if (pthread_sigmask (SIG_BLOCK, &ss, NULL) != 0)
+ {
+ puts ("main: sigmask failed");
+ return 1;
+ }
+
+ pthread_barrier_wait (&bar);
+
+ /* Send some signals. */
+ pid_t me = getpid ();
+ kill (me, sig1 + N);
+ for (i = 0; i < N; ++i)
+ kill (me, sig1 + i);
+ kill (me, sig1 + N);
+
+ /* Give the signals a chance to be worked on. */
+ sleep (1);
+
+ pthread_barrier_wait (&bar);
+
+ for (i = 0; i < N; ++i)
+ if (pthread_join (th[i], NULL) != 0)
+ {
+ puts ("join failed");
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-signal7.c b/libc/nptl/tst-signal7.c
new file mode 100644
index 000000000..82ef11c2d
--- /dev/null
+++ b/libc/nptl/tst-signal7.c
@@ -0,0 +1,59 @@
+/* Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2005.
+
+ 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 <errno.h>
+#include <pthreadP.h>
+#include <signal.h>
+#include <stdio.h>
+
+
+static int
+do_test (void)
+{
+ int result = 0;
+
+ errno = 0;
+ if (sigaction (SIGCANCEL, NULL, NULL) == 0)
+ {
+ puts ("sigaction(SIGCANCEL) did not fail");
+ result = 1;
+ }
+ else if (errno != EINVAL)
+ {
+ puts ("sigaction(SIGCANCEL) did not set errno to EINVAL");
+ result = 1;
+ }
+
+ errno = 0;
+ if (sigaction (SIGSETXID, NULL, NULL) == 0)
+ {
+ puts ("sigaction(SIGSETXID) did not fail");
+ result = 1;
+ }
+ else if (errno != EINVAL)
+ {
+ puts ("sigaction(SIGSETXID) did not set errno to EINVAL");
+ result = 1;
+ }
+
+ return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-spin1.c b/libc/nptl/tst-spin1.c
new file mode 100644
index 000000000..259b4b4d6
--- /dev/null
+++ b/libc/nptl/tst-spin1.c
@@ -0,0 +1,57 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+
+
+static int
+do_test (void)
+{
+ pthread_spinlock_t s;
+
+ if (pthread_spin_init (&s, PTHREAD_PROCESS_PRIVATE) != 0)
+ {
+ puts ("spin_init failed");
+ return 1;
+ }
+
+ if (pthread_spin_lock (&s) != 0)
+ {
+ puts ("spin_lock failed");
+ return 1;
+ }
+
+ if (pthread_spin_unlock (&s) != 0)
+ {
+ puts ("spin_unlock failed");
+ return 1;
+ }
+
+ if (pthread_spin_destroy (&s) != 0)
+ {
+ puts ("spin_destroy failed");
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-spin2.c b/libc/nptl/tst-spin2.c
new file mode 100644
index 000000000..5b1df6c4a
--- /dev/null
+++ b/libc/nptl/tst-spin2.c
@@ -0,0 +1,159 @@
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+
+
+static int
+do_test (void)
+{
+ size_t ps = sysconf (_SC_PAGESIZE);
+ char tmpfname[] = "/tmp/tst-spin2.XXXXXX";
+ char data[ps];
+ void *mem;
+ int fd;
+ pthread_spinlock_t *s;
+ pid_t pid;
+ char *p;
+ int err;
+
+ fd = mkstemp (tmpfname);
+ if (fd == -1)
+ {
+ printf ("cannot open temporary file: %m\n");
+ return 1;
+ }
+
+ /* Make sure it is always removed. */
+ unlink (tmpfname);
+
+ /* Create one page of data. */
+ memset (data, '\0', ps);
+
+ /* Write the data to the file. */
+ if (write (fd, data, ps) != (ssize_t) ps)
+ {
+ puts ("short write");
+ return 1;
+ }
+
+ mem = mmap (NULL, ps, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if (mem == MAP_FAILED)
+ {
+ printf ("mmap failed: %m\n");
+ return 1;
+ }
+
+ s = (pthread_spinlock_t *) (((uintptr_t) mem
+ + __alignof (pthread_spinlock_t))
+ & ~(__alignof (pthread_spinlock_t) - 1));
+ p = (char *) (s + 1);
+
+ if (pthread_spin_init (s, PTHREAD_PROCESS_SHARED) != 0)
+ {
+ puts ("spin_init failed");
+ return 1;
+ }
+
+ if (pthread_spin_lock (s) != 0)
+ {
+ puts ("spin_lock failed");
+ return 1;
+ }
+
+ err = pthread_spin_trylock (s);
+ if (err == 0)
+ {
+ puts ("1st spin_trylock succeeded");
+ return 1;
+ }
+ else if (err != EBUSY)
+ {
+ puts ("1st spin_trylock didn't return EBUSY");
+ return 1;
+ }
+
+ err = pthread_spin_unlock (s);
+ if (err != 0)
+ {
+ puts ("parent: spin_unlock failed");
+ return 1;
+ }
+
+ err = pthread_spin_trylock (s);
+ if (err != 0)
+ {
+ puts ("2nd spin_trylock failed");
+ return 1;
+ }
+
+ *p = 0;
+
+ puts ("going to fork now");
+ pid = fork ();
+ if (pid == -1)
+ {
+ puts ("fork failed");
+ return 1;
+ }
+ else if (pid == 0)
+ {
+ /* Play some lock ping-pong. It's our turn to unlock first. */
+ if ((*p)++ != 0)
+ {
+ puts ("child: *p != 0");
+ return 1;
+ }
+
+ if (pthread_spin_unlock (s) != 0)
+ {
+ puts ("child: 1st spin_unlock failed");
+ return 1;
+ }
+
+ puts ("child done");
+ }
+ else
+ {
+ if (pthread_spin_lock (s) != 0)
+ {
+ puts ("parent: 2nd spin_lock failed");
+ return 1;
+ }
+
+ puts ("waiting for child");
+
+ waitpid (pid, NULL, 0);
+
+ puts ("parent done");
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-spin3.c b/libc/nptl/tst-spin3.c
new file mode 100644
index 000000000..443774032
--- /dev/null
+++ b/libc/nptl/tst-spin3.c
@@ -0,0 +1,55 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+
+
+static int
+do_test (void)
+{
+ pthread_spinlock_t s;
+
+ if (pthread_spin_init (&s, PTHREAD_PROCESS_PRIVATE) != 0)
+ {
+ puts ("spin_init failed");
+ return 1;
+ }
+
+ if (pthread_spin_lock (&s) != 0)
+ {
+ puts ("1st spin_lock failed");
+ return 1;
+ }
+
+ /* Set an alarm for 1 second. The wrapper will expect this. */
+ alarm (1);
+
+ /* This call should never return. */
+ pthread_spin_lock (&s);
+
+ puts ("2nd spin_lock returned");
+ return 1;
+}
+
+#define EXPECTED_SIGNAL SIGALRM
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-stack1.c b/libc/nptl/tst-stack1.c
new file mode 100644
index 000000000..93405981d
--- /dev/null
+++ b/libc/nptl/tst-stack1.c
@@ -0,0 +1,146 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <limits.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/param.h>
+#include <unistd.h>
+
+
+static void *stack;
+static size_t size;
+
+
+static void *
+tf (void *a)
+{
+ int result = 0;
+
+ puts ("child start");
+
+ pthread_attr_t attr;
+ if (pthread_getattr_np (pthread_self (), &attr) != 0)
+ {
+ puts ("getattr_np failed");
+ exit (1);
+ }
+
+ size_t test_size;
+ void *test_stack;
+ if (pthread_attr_getstack (&attr, &test_stack, &test_size) != 0)
+ {
+ puts ("attr_getstack failed");
+ exit (1);
+ }
+
+ if (test_size != size)
+ {
+ printf ("child: reported size differs: is %zu, expected %zu\n",
+ test_size, size);
+ result = 1;
+ }
+
+ if (test_stack != stack)
+ {
+ printf ("child: reported stack address differs: is %p, expected %p\n",
+ test_stack, stack);
+ result = 1;
+ }
+
+ puts ("child OK");
+
+ return result ? (void *) 1l : NULL;
+}
+
+
+int
+do_test (void)
+{
+ int result = 0;
+
+ size = MAX (4 * getpagesize (), PTHREAD_STACK_MIN);
+ if (posix_memalign (&stack, getpagesize (), size) != 0)
+ {
+ puts ("out of memory while allocating the stack memory");
+ exit (1);
+ }
+
+ pthread_attr_t attr;
+ if (pthread_attr_init (&attr) != 0)
+ {
+ puts ("attr_init failed");
+ exit (1);
+ }
+
+ puts ("attr_setstack");
+ if (pthread_attr_setstack (&attr, stack, size) != 0)
+ {
+ puts ("attr_setstack failed");
+ exit (1);
+ }
+
+ size_t test_size;
+ void *test_stack;
+ puts ("attr_getstack");
+ if (pthread_attr_getstack (&attr, &test_stack, &test_size) != 0)
+ {
+ puts ("attr_getstack failed");
+ exit (1);
+ }
+
+ if (test_size != size)
+ {
+ printf ("reported size differs: is %zu, expected %zu\n",
+ test_size, size);
+ result = 1;
+ }
+
+ if (test_stack != stack)
+ {
+ printf ("reported stack address differs: is %p, expected %p\n",
+ test_stack, stack);
+ result = 1;
+ }
+
+ puts ("create");
+
+ pthread_t th;
+ if (pthread_create (&th, &attr, tf, NULL) != 0)
+ {
+ puts ("failed to create thread");
+ exit (1);
+ }
+
+ void *status;
+ if (pthread_join (th, &status) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ result |= status != NULL;
+
+ return result;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-stack2.c b/libc/nptl/tst-stack2.c
new file mode 100644
index 000000000..9b2788ca5
--- /dev/null
+++ b/libc/nptl/tst-stack2.c
@@ -0,0 +1,79 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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. */
+
+/* Test whether it is possible to create a thread with PTHREAD_STACK_MIN
+ stack size. */
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+static int seen;
+
+static void *
+tf (void *p)
+{
+ ++seen;
+ return NULL;
+}
+
+static int
+do_test (void)
+{
+ pthread_attr_t attr;
+ pthread_attr_init (&attr);
+
+ int result = 0;
+ int res = pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
+ if (res)
+ {
+ printf ("pthread_attr_setstacksize failed %d\n", res);
+ result = 1;
+ }
+
+ /* Create the thread. */
+ pthread_t th;
+ res = pthread_create (&th, &attr, tf, NULL);
+ if (res)
+ {
+ printf ("pthread_create failed %d\n", res);
+ result = 1;
+ }
+ else
+ {
+ res = pthread_join (th, NULL);
+ if (res)
+ {
+ printf ("pthread_join failed %d\n", res);
+ result = 1;
+ }
+ }
+
+ if (seen != 1)
+ {
+ printf ("seen %d != 1\n", seen);
+ result = 1;
+ }
+
+ return result;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-stack3.c b/libc/nptl/tst-stack3.c
new file mode 100644
index 000000000..d99e1eacf
--- /dev/null
+++ b/libc/nptl/tst-stack3.c
@@ -0,0 +1,101 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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. */
+
+/* Test whether pthread_create/pthread_join with user defined stacks
+ doesn't leak memory.
+ NOTE: this tests functionality beyond POSIX. In POSIX user defined
+ stacks cannot be ever freed once used by pthread_create nor they can
+ be reused for other thread. */
+
+#include <limits.h>
+#include <mcheck.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+static int seen;
+
+static void *
+tf (void *p)
+{
+ ++seen;
+ return NULL;
+}
+
+static int
+do_test (void)
+{
+ mtrace ();
+
+ void *stack;
+ int res = posix_memalign (&stack, getpagesize (), 4 * PTHREAD_STACK_MIN);
+ if (res)
+ {
+ printf ("malloc failed %s\n", strerror (res));
+ return 1;
+ }
+
+ pthread_attr_t attr;
+ pthread_attr_init (&attr);
+
+ int result = 0;
+ res = pthread_attr_setstack (&attr, stack, 4 * PTHREAD_STACK_MIN);
+ if (res)
+ {
+ printf ("pthread_attr_setstack failed %d\n", res);
+ result = 1;
+ }
+
+ for (int i = 0; i < 16; ++i)
+ {
+ /* Create the thread. */
+ pthread_t th;
+ res = pthread_create (&th, &attr, tf, NULL);
+ if (res)
+ {
+ printf ("pthread_create failed %d\n", res);
+ result = 1;
+ }
+ else
+ {
+ res = pthread_join (th, NULL);
+ if (res)
+ {
+ printf ("pthread_join failed %d\n", res);
+ result = 1;
+ }
+ }
+ }
+
+ pthread_attr_destroy (&attr);
+
+ if (seen != 16)
+ {
+ printf ("seen %d != 16\n", seen);
+ result = 1;
+ }
+
+ free (stack);
+ return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-stackguard1-static.c b/libc/nptl/tst-stackguard1-static.c
new file mode 100644
index 000000000..db1e21554
--- /dev/null
+++ b/libc/nptl/tst-stackguard1-static.c
@@ -0,0 +1 @@
+#include "tst-stackguard1.c"
diff --git a/libc/nptl/tst-stackguard1.c b/libc/nptl/tst-stackguard1.c
new file mode 100644
index 000000000..15c30aeb6
--- /dev/null
+++ b/libc/nptl/tst-stackguard1.c
@@ -0,0 +1,226 @@
+/* Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2005.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/wait.h>
+#include <elf/stackguard-macros.h>
+#include <unistd.h>
+
+static const char *command;
+static bool child;
+static uintptr_t stack_chk_guard_copy;
+static bool stack_chk_guard_copy_set;
+static int fds[2];
+
+static void __attribute__ ((constructor))
+con (void)
+{
+ stack_chk_guard_copy = STACK_CHK_GUARD;
+ stack_chk_guard_copy_set = true;
+}
+
+static int
+uintptr_t_cmp (const void *a, const void *b)
+{
+ if (*(uintptr_t *) a < *(uintptr_t *) b)
+ return 1;
+ if (*(uintptr_t *) a > *(uintptr_t *) b)
+ return -1;
+ return 0;
+}
+
+static void *
+tf (void *arg)
+{
+ if (stack_chk_guard_copy != STACK_CHK_GUARD)
+ {
+ puts ("STACK_CHK_GUARD changed in thread");
+ return (void *) 1L;
+ }
+ return NULL;
+}
+
+static int
+do_test (void)
+{
+ if (!stack_chk_guard_copy_set)
+ {
+ puts ("constructor has not been run");
+ return 1;
+ }
+
+ if (stack_chk_guard_copy != STACK_CHK_GUARD)
+ {
+ puts ("STACK_CHK_GUARD changed between constructor and do_test");
+ return 1;
+ }
+
+ if (child)
+ {
+ int i;
+ pthread_t th[4];
+ void *ret;
+ for (i = 0; i < 4; ++i)
+ if (pthread_create (&th[i], NULL, tf, NULL))
+ {
+ puts ("thread creation failed");
+ return 1;
+ }
+ for (i = 0; i < 4; ++i)
+ if (pthread_join (th[i], &ret))
+ {
+ puts ("thread join failed");
+ return 1;
+ }
+ else if (ret != NULL)
+ return 1;
+
+ write (2, &stack_chk_guard_copy, sizeof (stack_chk_guard_copy));
+ return 0;
+ }
+
+ if (command == NULL)
+ {
+ puts ("missing --command or --child argument");
+ return 1;
+ }
+
+#define N 16
+ uintptr_t child_stack_chk_guards[N + 1];
+ child_stack_chk_guards[N] = stack_chk_guard_copy;
+ int i;
+ for (i = 0; i < N; ++i)
+ {
+ if (pipe (fds) < 0)
+ {
+ printf ("couldn't create pipe: %m\n");
+ return 1;
+ }
+
+ pid_t pid = fork ();
+ if (pid < 0)
+ {
+ printf ("fork failed: %m\n");
+ return 1;
+ }
+
+ if (!pid)
+ {
+ if (stack_chk_guard_copy != STACK_CHK_GUARD)
+ {
+ puts ("STACK_CHK_GUARD changed after fork");
+ exit (1);
+ }
+
+ close (fds[0]);
+ close (2);
+ dup2 (fds[1], 2);
+ close (fds[1]);
+
+ system (command);
+ exit (0);
+ }
+
+ close (fds[1]);
+
+ if (TEMP_FAILURE_RETRY (read (fds[0], &child_stack_chk_guards[i],
+ sizeof (uintptr_t))) != sizeof (uintptr_t))
+ {
+ puts ("could not read stack_chk_guard value from child");
+ return 1;
+ }
+
+ close (fds[0]);
+
+ pid_t termpid;
+ int status;
+ termpid = TEMP_FAILURE_RETRY (waitpid (pid, &status, 0));
+ if (termpid == -1)
+ {
+ printf ("waitpid failed: %m\n");
+ return 1;
+ }
+ else if (termpid != pid)
+ {
+ printf ("waitpid returned %ld != %ld\n",
+ (long int) termpid, (long int) pid);
+ return 1;
+ }
+ else if (!WIFEXITED (status) || WEXITSTATUS (status))
+ {
+ puts ("child hasn't exited with exit status 0");
+ return 1;
+ }
+ }
+
+ qsort (child_stack_chk_guards, N + 1, sizeof (uintptr_t), uintptr_t_cmp);
+
+ uintptr_t default_guard = 0;
+ unsigned char *p = (unsigned char *) &default_guard;
+ p[sizeof (uintptr_t) - 1] = 255;
+ p[sizeof (uintptr_t) - 2] = '\n';
+ p[0] = 0;
+
+ /* Test if the stack guard canaries are either randomized,
+ or equal to the default stack guard canary value.
+ Even with randomized stack guards it might happen
+ that the random number generator generates the same
+ values, but if that happens in more than half from
+ the 16 runs, something is very wrong. */
+ int ndifferences = 0;
+ int ndefaults = 0;
+ for (i = 0; i < N; ++i)
+ {
+ if (child_stack_chk_guards[i] != child_stack_chk_guards[i+1])
+ ndifferences++;
+ else if (child_stack_chk_guards[i] == default_guard)
+ ndefaults++;
+ }
+
+ printf ("differences %d defaults %d\n", ndifferences, ndefaults);
+
+ if (ndifferences < N / 2 && ndefaults < N / 2)
+ {
+ puts ("stack guard canaries are not randomized enough");
+ puts ("nor equal to the default canary value");
+ return 1;
+ }
+
+ return 0;
+}
+
+#define OPT_COMMAND 10000
+#define OPT_CHILD 10001
+#define CMDLINE_OPTIONS \
+ { "command", required_argument, NULL, OPT_COMMAND }, \
+ { "child", no_argument, NULL, OPT_CHILD },
+#define CMDLINE_PROCESS \
+ case OPT_COMMAND: \
+ command = optarg; \
+ break; \
+ case OPT_CHILD: \
+ child = true; \
+ break;
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-stdio1.c b/libc/nptl/tst-stdio1.c
new file mode 100644
index 000000000..ebb3e2f0b
--- /dev/null
+++ b/libc/nptl/tst-stdio1.c
@@ -0,0 +1,57 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+
+
+static void *tf (void *a)
+{
+ flockfile (stdout);
+ /* This call should never return. */
+ return a;
+}
+
+
+int
+do_test (void)
+{
+ pthread_t th;
+
+ flockfile (stdout);
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ write (2, "create failed\n", 14);
+ _exit (1);
+ }
+
+ pthread_join (th, NULL);
+
+ puts ("join returned");
+
+ return 0;
+}
+
+
+#define EXPECTED_SIGNAL SIGALRM
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-stdio2.c b/libc/nptl/tst-stdio2.c
new file mode 100644
index 000000000..08d6addf4
--- /dev/null
+++ b/libc/nptl/tst-stdio2.c
@@ -0,0 +1,82 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static void *tf (void *a)
+{
+ puts ("start tf");
+
+ /* Multiple locking, implicitly or explicitly, must be possible. */
+ flockfile (stdout);
+
+ puts ("after first flockfile");
+
+ flockfile (stdout);
+
+ puts ("foo");
+
+ funlockfile (stdout);
+
+ puts ("after first funlockfile");
+
+ funlockfile (stdout);
+
+ puts ("all done");
+
+ return a;
+}
+
+
+int
+do_test (void)
+{
+ pthread_t th;
+
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ write (2, "create failed\n", 14);
+ _exit (1);
+ }
+
+ void *result;
+ if (pthread_join (th, &result) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+ else if (result != NULL)
+ {
+ printf ("wrong return value: %p, expected %p\n", result, NULL);
+ exit (1);
+ }
+
+ puts ("join returned succsefully");
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-sysconf.c b/libc/nptl/tst-sysconf.c
new file mode 100644
index 000000000..3ad1b6a3c
--- /dev/null
+++ b/libc/nptl/tst-sysconf.c
@@ -0,0 +1,48 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+#include <unistd.h>
+
+
+static int
+do_test (void)
+{
+ puts ("We expect no limits");
+ /* We have no fixed limit on the number of threads. Make sure the
+ headers tell the right story. */
+#ifdef PTHREAD_THREADS_MAX
+ printf ("Header report maximum number of threads = %lu\n",
+ (unsigned long int) PTHREAD_THREADS_MAX);
+ return 1;
+#else
+ long int r = sysconf (_SC_THREAD_THREADS_MAX);
+ if (r != -1)
+ {
+ printf ("sysconf(_SC_THREAD_THREADS_MAX) return %ld\n", r);
+ return 1;
+ }
+#endif
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-tls1.c b/libc/nptl/tst-tls1.c
new file mode 100644
index 000000000..4e191222a
--- /dev/null
+++ b/libc/nptl/tst-tls1.c
@@ -0,0 +1,122 @@
+/* Copyright (C) 2003, 2004 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>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+#if HAVE___THREAD
+struct test_s
+{
+ int a;
+ int b;
+};
+
+#define INIT_A 1
+#define INIT_B 42
+/* Deliberately not static. */
+__thread struct test_s s __attribute__ ((tls_model ("initial-exec"))) =
+{
+ .a = INIT_A,
+ .b = INIT_B
+};
+
+
+static void *
+tf (void *arg)
+{
+ if (s.a != INIT_A || s.b != INIT_B)
+ {
+ puts ("initial value of s in child thread wrong");
+ exit (1);
+ }
+
+ ++s.a;
+
+ return NULL;
+}
+#endif
+
+
+int
+do_test (void)
+{
+#if !HAVE___THREAD
+
+ puts ("No __thread support in compiler, test skipped.");
+
+ return 0;
+#else
+
+ if (s.a != INIT_A || s.b != INIT_B)
+ {
+ puts ("initial value of s in main thread wrong");
+ exit (1);
+ }
+
+ pthread_attr_t a;
+
+ if (pthread_attr_init (&a) != 0)
+ {
+ puts ("attr_init failed");
+ exit (1);
+ }
+
+ if (pthread_attr_setstacksize (&a, 1 * 1024 * 1024) != 0)
+ {
+ puts ("attr_setstacksize failed");
+ return 1;
+ }
+
+#define N 10
+ int i;
+ for (i = 0; i < N; ++i)
+ {
+#define M 10
+ pthread_t th[M];
+ int j;
+ for (j = 0; j < M; ++j, ++s.a)
+ if (pthread_create (&th[j], &a, tf, NULL) != 0)
+ {
+ puts ("pthread_create failed");
+ exit (1);
+ }
+
+ for (j = 0; j < M; ++j)
+ if (pthread_join (th[j], NULL) != 0)
+ {
+ puts ("pthread_join failed");
+ exit (1);
+ }
+ }
+
+ if (pthread_attr_destroy (&a) != 0)
+ {
+ puts ("attr_destroy failed");
+ exit (1);
+ }
+
+ return 0;
+#endif
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-tls2.c b/libc/nptl/tst-tls2.c
new file mode 100644
index 000000000..73ed33eb6
--- /dev/null
+++ b/libc/nptl/tst-tls2.c
@@ -0,0 +1,215 @@
+/* Copyright (C) 2003, 2004 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 <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <semaphore.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#if HAVE___THREAD
+
+#define N 10
+static pthread_t th[N];
+
+
+#define CB(n) \
+static void \
+cb##n (void) \
+{ \
+ if (th[n] != pthread_self ()) \
+ { \
+ write (STDOUT_FILENO, "wrong callback\n", 15); \
+ _exit (1); \
+ } \
+}
+CB (0)
+CB (1)
+CB (2)
+CB (3)
+CB (4)
+CB (5)
+CB (6)
+CB (7)
+CB (8)
+CB (9)
+static void (*cbs[]) (void) =
+{
+ cb0, cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, cb9
+};
+
+
+static __thread void (*fp) (void) __attribute__ ((tls_model ("local-exec")));
+
+
+static sem_t s;
+
+
+#define THE_SIG SIGUSR1
+static void
+handler (int sig)
+{
+ if (sig != THE_SIG)
+ {
+ write (STDOUT_FILENO, "wrong signal\n", 13);
+ _exit (1);
+ }
+
+ fp ();
+
+ if (sem_post (&s) != 0)
+ {
+ write (STDOUT_FILENO, "sem_post failed\n", 16);
+ _exit (1);
+ }
+}
+
+
+static pthread_barrier_t b;
+
+#define TOTAL_SIGS 1000
+static int nsigs;
+
+
+static void *
+tf (void *arg)
+{
+ fp = arg;
+
+ pthread_barrier_wait (&b);
+
+ pthread_barrier_wait (&b);
+
+ if (nsigs != TOTAL_SIGS)
+ {
+ puts ("barrier_wait prematurely returns");
+ exit (1);
+ }
+
+ return NULL;
+}
+#endif
+
+int
+do_test (void)
+{
+#if !HAVE___THREAD
+
+ puts ("No __thread support in compiler, test skipped.");
+
+ return 0;
+#else
+
+ if (pthread_barrier_init (&b, NULL, N + 1) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ if (sem_init (&s, 0, 0) != 0)
+ {
+ puts ("sem_init failed");
+ exit (1);
+ }
+
+ struct sigaction sa;
+ sa.sa_handler = handler;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = 0;
+ if (sigaction (THE_SIG, &sa, NULL) != 0)
+ {
+ puts ("sigaction failed");
+ exit (1);
+ }
+
+ pthread_attr_t a;
+
+ if (pthread_attr_init (&a) != 0)
+ {
+ puts ("attr_init failed");
+ exit (1);
+ }
+
+ if (pthread_attr_setstacksize (&a, 1 * 1024 * 1024) != 0)
+ {
+ puts ("attr_setstacksize failed");
+ return 1;
+ }
+
+ int i;
+ for (i = 0; i < N; ++i)
+ if (pthread_create (&th[i], &a, tf, cbs[i]) != 0)
+ {
+ puts ("pthread_create failed");
+ exit (1);
+ }
+
+ if (pthread_attr_destroy (&a) != 0)
+ {
+ puts ("attr_destroy failed");
+ exit (1);
+ }
+
+ pthread_barrier_wait (&b);
+
+ sigset_t ss;
+ sigemptyset (&ss);
+ sigaddset (&ss, THE_SIG);
+ if (pthread_sigmask (SIG_BLOCK, &ss, NULL) != 0)
+ {
+ puts ("pthread_sigmask failed");
+ exit (1);
+ }
+
+ /* Start sending signals. */
+ for (i = 0; i < TOTAL_SIGS; ++i)
+ {
+ if (kill (getpid (), THE_SIG) != 0)
+ {
+ puts ("kill failed");
+ exit (1);
+ }
+
+ if (TEMP_FAILURE_RETRY (sem_wait (&s)) != 0)
+ {
+ puts ("sem_wait failed");
+ exit (1);
+ }
+
+ ++nsigs;
+ }
+
+ pthread_barrier_wait (&b);
+
+ for (i = 0; i < N; ++i)
+ if (pthread_join (th[i], NULL) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ return 0;
+#endif
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-tls3.c b/libc/nptl/tst-tls3.c
new file mode 100644
index 000000000..8c2663bb0
--- /dev/null
+++ b/libc/nptl/tst-tls3.c
@@ -0,0 +1,215 @@
+/* Copyright (C) 2003, 2004 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 <dlfcn.h>
+#include <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <semaphore.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <pthreaddef.h>
+
+#define THE_SIG SIGUSR1
+
+
+#define N 10
+static pthread_t th[N];
+
+
+#define CB(n) \
+static void \
+cb##n (void) \
+{ \
+ if (th[n] != pthread_self ()) \
+ { \
+ write (STDOUT_FILENO, "wrong callback\n", 15); \
+ _exit (1); \
+ } \
+}
+CB (0)
+CB (1)
+CB (2)
+CB (3)
+CB (4)
+CB (5)
+CB (6)
+CB (7)
+CB (8)
+CB (9)
+static void (*cbs[]) (void) =
+{
+ cb0, cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, cb9
+};
+
+
+sem_t s;
+
+
+pthread_barrier_t b;
+
+#define TOTAL_SIGS 1000
+int nsigs;
+
+
+int
+do_test (void)
+{
+#if !HAVE___THREAD
+
+ puts ("No __thread support in compiler, test skipped.");
+
+ return 0;
+#else
+
+ if ((uintptr_t) pthread_self () & (TCB_ALIGNMENT - 1))
+ {
+ puts ("initial thread's struct pthread not aligned enough");
+ exit (1);
+ }
+
+ if (pthread_barrier_init (&b, NULL, N + 1) != 0)
+ {
+ puts ("barrier_init failed");
+ exit (1);
+ }
+
+ if (sem_init (&s, 0, 0) != 0)
+ {
+ puts ("sem_init failed");
+ exit (1);
+ }
+
+ void *h = dlopen ("tst-tls3mod.so", RTLD_LAZY);
+ if (h == NULL)
+ {
+ puts ("dlopen failed");
+ exit (1);
+ }
+
+ void *(*tf) (void *) = dlsym (h, "tf");
+ if (tf == NULL)
+ {
+ puts ("dlsym for tf failed");
+ exit (1);
+ }
+
+ struct sigaction sa;
+ sa.sa_handler = dlsym (h, "handler");
+ if (sa.sa_handler == NULL)
+ {
+ puts ("dlsym for handler failed");
+ exit (1);
+ }
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = 0;
+ if (sigaction (THE_SIG, &sa, NULL) != 0)
+ {
+ puts ("sigaction failed");
+ exit (1);
+ }
+
+ pthread_attr_t a;
+
+ if (pthread_attr_init (&a) != 0)
+ {
+ puts ("attr_init failed");
+ exit (1);
+ }
+
+ if (pthread_attr_setstacksize (&a, 1 * 1024 * 1024) != 0)
+ {
+ puts ("attr_setstacksize failed");
+ return 1;
+ }
+
+ int r;
+ for (r = 0; r < 10; ++r)
+ {
+ int i;
+ for (i = 0; i < N; ++i)
+ if (pthread_create (&th[i], &a, tf, cbs[i]) != 0)
+ {
+ puts ("pthread_create failed");
+ exit (1);
+ }
+
+ nsigs = 0;
+
+ pthread_barrier_wait (&b);
+
+ sigset_t ss;
+ sigemptyset (&ss);
+ sigaddset (&ss, THE_SIG);
+ if (pthread_sigmask (SIG_BLOCK, &ss, NULL) != 0)
+ {
+ puts ("pthread_sigmask failed");
+ exit (1);
+ }
+
+ /* Start sending signals. */
+ for (i = 0; i < TOTAL_SIGS; ++i)
+ {
+ if (kill (getpid (), THE_SIG) != 0)
+ {
+ puts ("kill failed");
+ exit (1);
+ }
+
+ if (TEMP_FAILURE_RETRY (sem_wait (&s)) != 0)
+ {
+ puts ("sem_wait failed");
+ exit (1);
+ }
+
+ ++nsigs;
+ }
+
+ pthread_barrier_wait (&b);
+
+ if (pthread_sigmask (SIG_UNBLOCK, &ss, NULL) != 0)
+ {
+ puts ("pthread_sigmask failed");
+ exit (1);
+ }
+
+ for (i = 0; i < N; ++i)
+ if (pthread_join (th[i], NULL) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+ }
+
+ if (pthread_attr_destroy (&a) != 0)
+ {
+ puts ("attr_destroy failed");
+ exit (1);
+ }
+
+ return 0;
+#endif
+}
+
+
+#define TIMEOUT 5
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-tls3mod.c b/libc/nptl/tst-tls3mod.c
new file mode 100644
index 000000000..4cb96452e
--- /dev/null
+++ b/libc/nptl/tst-tls3mod.c
@@ -0,0 +1,92 @@
+/* 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>
+#include <semaphore.h>
+#include <signal.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <pthreaddef.h>
+
+#if HAVE___THREAD
+
+extern pthread_barrier_t b;
+
+#define TOTAL_SIGS 1000
+extern int nsigs;
+
+extern sem_t s;
+
+
+static __thread void (*fp) (void);
+
+
+#define THE_SIG SIGUSR1
+void
+handler (int sig)
+{
+ if (sig != THE_SIG)
+ {
+ write (STDOUT_FILENO, "wrong signal\n", 13);
+ _exit (1);
+ }
+
+ fp ();
+
+ if (sem_post (&s) != 0)
+ {
+ write (STDOUT_FILENO, "sem_post failed\n", 16);
+ _exit (1);
+ }
+}
+
+
+void *
+tf (void *arg)
+{
+ if ((uintptr_t) pthread_self () & (TCB_ALIGNMENT - 1))
+ {
+ puts ("thread's struct pthread not aligned enough");
+ exit (1);
+ }
+
+ if (fp != NULL)
+ {
+ puts ("fp not initially NULL");
+ exit (1);
+ }
+
+ fp = arg;
+
+ pthread_barrier_wait (&b);
+
+ pthread_barrier_wait (&b);
+
+ if (nsigs != TOTAL_SIGS)
+ {
+ puts ("barrier_wait prematurely returns");
+ exit (1);
+ }
+
+ return NULL;
+}
+
+#endif
diff --git a/libc/nptl/tst-tls4.c b/libc/nptl/tst-tls4.c
new file mode 100644
index 000000000..52775dee8
--- /dev/null
+++ b/libc/nptl/tst-tls4.c
@@ -0,0 +1,191 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 <dlfcn.h>
+#include <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <tls.h>
+
+#if HAVE___THREAD && defined HAVE_TLS_MODEL_ATTRIBUTE
+
+#define N 3
+
+void (*test1) (void), (*test2) (void);
+
+pthread_barrier_t b2, b3;
+
+static void *
+tf (void *arg)
+{
+ int i;
+
+ for (i = 0; i <= (uintptr_t) arg; ++i)
+ {
+ int r = pthread_barrier_wait (&b3);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("tf: barrier_wait failed");
+ exit (1);
+ }
+ }
+
+ test1 ();
+
+ for (i = 0; i < 3; ++i)
+ {
+ int r = pthread_barrier_wait (&b3);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("tf: barrier_wait failed");
+ exit (1);
+ }
+ }
+
+ test2 ();
+
+ for (i = 0; i < 3 - (uintptr_t) arg; ++i)
+ {
+ int r = pthread_barrier_wait (&b3);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("tf: barrier_wait failed");
+ exit (1);
+ }
+ }
+
+ return NULL;
+}
+
+static void *
+tf2 (void *arg)
+{
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("tf2: barrier_wait failed");
+ exit (1);
+ }
+
+ int i;
+ for (i = 0; i < N; ++i)
+ tf (arg);
+ return NULL;
+}
+
+int
+do_test (void)
+{
+ pthread_t th[2];
+ const char *modules[N]
+ = { "tst-tls4moda.so", "tst-tls4moda.so", "tst-tls4modb.so" };
+
+ if (pthread_barrier_init (&b2, NULL, 2) != 0)
+ {
+ puts ("barrier_init failed");
+ return 1;
+ }
+
+ if (pthread_barrier_init (&b3, NULL, 3) != 0)
+ {
+ puts ("barrier_init failed");
+ return 1;
+ }
+
+ if (pthread_create (&th[0], NULL, tf2, (void *) (uintptr_t) 1))
+ {
+ puts ("pthread_create failed");
+ return 1;
+ }
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ puts ("barrier_wait failed");
+ return 1;
+ }
+
+ int i;
+ for (i = 0; i < N; ++i)
+ {
+ void *h = dlopen (modules[i], RTLD_LAZY);
+ if (h == NULL)
+ {
+ printf ("dlopen failed %s\n", dlerror ());
+ return 1;
+ }
+
+ test1 = dlsym (h, "test1");
+ if (test1 == NULL)
+ {
+ printf ("dlsym for test1 failed %s\n", dlerror ());
+ return 1;
+ }
+
+ test2 = dlsym (h, "test2");
+ if (test2 == NULL)
+ {
+ printf ("dlsym for test2 failed %s\n", dlerror ());
+ return 1;
+ }
+
+ if (pthread_create (&th[1], NULL, tf, (void *) (uintptr_t) 2))
+ {
+ puts ("pthread_create failed");
+ return 1;
+ }
+
+ tf ((void *) (uintptr_t) 0);
+
+ if (pthread_join (th[1], NULL) != 0)
+ {
+ puts ("join failed");
+ return 1;
+ }
+
+ if (dlclose (h))
+ {
+ puts ("dlclose failed");
+ return 1;
+ }
+
+ printf ("test %d with %s succeeded\n", i, modules[i]);
+ }
+
+ if (pthread_join (th[0], NULL) != 0)
+ {
+ puts ("join failed");
+ return 1;
+ }
+
+ return 0;
+}
+
+#define TIMEOUT 5
+#define TEST_FUNCTION do_test ()
+
+#else
+
+#define TEST_FUNCTION 0
+
+#endif
+
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-tls4moda.c b/libc/nptl/tst-tls4moda.c
new file mode 100644
index 000000000..ff7ee5604
--- /dev/null
+++ b/libc/nptl/tst-tls4moda.c
@@ -0,0 +1,56 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <tls.h>
+
+#if HAVE___THREAD && defined HAVE_TLS_MODEL_ATTRIBUTE
+
+static __thread unsigned char foo [32]
+ __attribute__ ((tls_model ("initial-exec"), aligned (sizeof (void *))));
+
+void
+test1 (void)
+{
+ size_t s;
+
+ for (s = 0; s < sizeof (foo); ++s)
+ {
+ if (foo [s])
+ abort ();
+ foo [s] = s;
+ }
+}
+
+void
+test2 (void)
+{
+ size_t s;
+
+ for (s = 0; s < sizeof (foo); ++s)
+ {
+ if (foo [s] != s)
+ abort ();
+ foo [s] = sizeof (foo) - s;
+ }
+}
+
+#endif
diff --git a/libc/nptl/tst-tls4modb.c b/libc/nptl/tst-tls4modb.c
new file mode 100644
index 000000000..99f3b5405
--- /dev/null
+++ b/libc/nptl/tst-tls4modb.c
@@ -0,0 +1,65 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <tls.h>
+
+#if HAVE___THREAD && defined HAVE_TLS_MODEL_ATTRIBUTE
+
+static int i;
+int bar;
+
+static __thread void *foo [32 / sizeof (void *)]
+ __attribute__ ((tls_model ("initial-exec"), aligned (sizeof (void *))))
+ = { &i, &bar };
+
+void
+test1 (void)
+{
+ size_t s;
+
+ if (foo [0] != &i || foo [1] != &bar)
+ abort ();
+
+ foo [0] = NULL;
+ foo [1] = NULL;
+ for (s = 0; s < sizeof (foo) / sizeof (void *); ++s)
+ {
+ if (foo [s])
+ abort ();
+ foo [s] = &foo[s];
+ }
+}
+
+void
+test2 (void)
+{
+ size_t s;
+
+ for (s = 0; s < sizeof (foo) / sizeof (void *); ++s)
+ {
+ if (foo [s] != &foo [s])
+ abort ();
+ foo [s] = &foo [s ^ 1];
+ }
+}
+
+#endif
diff --git a/libc/nptl/tst-tls5.c b/libc/nptl/tst-tls5.c
new file mode 100644
index 000000000..546253256
--- /dev/null
+++ b/libc/nptl/tst-tls5.c
@@ -0,0 +1,120 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@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. */
+
+/* Check alignment, overlapping and layout of TLS variables. */
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <pthreadP.h>
+#include <sys/param.h>
+
+#include "tst-tls5.h"
+
+#ifdef TLS_REGISTER
+
+struct tls_obj tls_registry[64];
+
+static int
+tls_addr_cmp (const void *a, const void *b)
+{
+ if (((struct tls_obj *)a)->addr < ((struct tls_obj *)b)->addr)
+ return -1;
+ if (((struct tls_obj *)a)->addr > ((struct tls_obj *)b)->addr)
+ return 1;
+ return 0;
+}
+
+static int
+do_test (void)
+{
+ size_t cnt, i;
+ int res = 0;
+ uintptr_t min_addr = ~(uintptr_t) 0, max_addr = 0;
+
+ for (cnt = 0; tls_registry[cnt].name; ++cnt);
+ tls_registry[cnt].name = NULL;
+ tls_registry[cnt].addr = (uintptr_t) pthread_self ();
+ tls_registry[cnt].size = sizeof (struct pthread);
+ tls_registry[cnt++].align = __alignof__ (struct pthread);
+
+ qsort (tls_registry, cnt, sizeof (struct tls_obj), tls_addr_cmp);
+
+ for (i = 0; i < cnt; ++i)
+ {
+ printf ("%s%s = %p, size %zd, align %zd",
+ tls_registry[i].name ? "&" : "",
+ tls_registry[i].name ?: "pthread_self ()",
+ (void *) tls_registry[i].addr,
+ tls_registry[i].size, tls_registry[i].align);
+ if (tls_registry[i].addr & (tls_registry[i].align - 1))
+ {
+ fputs (", WRONG ALIGNMENT", stdout);
+ res = 1;
+ }
+ if (i > 0
+ && (tls_registry[i - 1].addr + tls_registry[i - 1].size
+ > tls_registry[i].addr))
+ {
+ fputs (", ADDRESS OVERLAP", stdout);
+ res = 1;
+ }
+ puts ("");
+ if (tls_registry[i].name)
+ {
+ min_addr = MIN (tls_registry[i].addr, min_addr);
+ max_addr = MAX (tls_registry[i].addr + tls_registry[i].size,
+ max_addr);
+ }
+ }
+
+ if (cnt > 1)
+ {
+#if TLS_TCB_AT_TP
+ if (tls_registry[cnt - 1].name)
+ {
+ puts ("pthread_self () not larger than all TLS addresses");
+ res = 1;
+ }
+ else
+ max_addr = MAX (tls_registry[cnt - 1].addr, max_addr);
+#elif TLS_DTV_AT_TP
+ if (tls_registry[0].name)
+ {
+ puts ("pthread_self () not smaller than all TLS addresses");
+ res = 1;
+ }
+#else
+ abort ();
+#endif
+ printf ("Initial TLS used block size %zd\n",
+ (size_t) (max_addr - min_addr));
+ }
+ return res;
+}
+
+#define TEST_FUNCTION do_test ()
+
+#else
+
+#define TEST_FUNCTION 0
+
+#endif
+
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-tls5.h b/libc/nptl/tst-tls5.h
new file mode 100644
index 000000000..b7c14eb82
--- /dev/null
+++ b/libc/nptl/tst-tls5.h
@@ -0,0 +1,28 @@
+#include <stdint.h>
+#include <stdlib.h>
+#include <tls.h>
+
+#if USE_TLS && HAVE___THREAD
+
+struct tls_obj
+{
+ const char *name;
+ uintptr_t addr;
+ size_t size;
+ size_t align;
+};
+extern struct tls_obj tls_registry[];
+
+#define TLS_REGISTER(x) \
+static void __attribute__((constructor)) \
+tls_register_##x (void) \
+{ \
+ size_t i; \
+ for (i = 0; tls_registry[i].name; ++i); \
+ tls_registry[i].name = #x; \
+ tls_registry[i].addr = (uintptr_t) &x; \
+ tls_registry[i].size = sizeof (x); \
+ tls_registry[i].align = __alignof__ (x); \
+}
+
+#endif
diff --git a/libc/nptl/tst-tls5mod.c b/libc/nptl/tst-tls5mod.c
new file mode 100644
index 000000000..b308bd60e
--- /dev/null
+++ b/libc/nptl/tst-tls5mod.c
@@ -0,0 +1,6 @@
+#include <tst-tls5.h>
+
+#ifdef TLS_REGISTER
+/* Ensure tls_registry is exported from the binary. */
+void *tst_tls5mod attribute_hidden = tls_registry;
+#endif
diff --git a/libc/nptl/tst-tls5moda.c b/libc/nptl/tst-tls5moda.c
new file mode 100644
index 000000000..a035c96cd
--- /dev/null
+++ b/libc/nptl/tst-tls5moda.c
@@ -0,0 +1,6 @@
+#include <tst-tls5.h>
+
+#ifdef TLS_REGISTER
+static __thread char a [32] __attribute__ ((aligned (64)));
+TLS_REGISTER (a)
+#endif
diff --git a/libc/nptl/tst-tls5modb.c b/libc/nptl/tst-tls5modb.c
new file mode 100644
index 000000000..848a80363
--- /dev/null
+++ b/libc/nptl/tst-tls5modb.c
@@ -0,0 +1,6 @@
+#include <tst-tls5.h>
+
+#ifdef TLS_REGISTER
+static __thread int b;
+TLS_REGISTER (b)
+#endif
diff --git a/libc/nptl/tst-tls5modc.c b/libc/nptl/tst-tls5modc.c
new file mode 100644
index 000000000..d63ceff8d
--- /dev/null
+++ b/libc/nptl/tst-tls5modc.c
@@ -0,0 +1,6 @@
+#include <tst-tls5.h>
+
+#ifdef TLS_REGISTER
+static __thread int c;
+TLS_REGISTER (c)
+#endif
diff --git a/libc/nptl/tst-tls5modd.c b/libc/nptl/tst-tls5modd.c
new file mode 100644
index 000000000..202a66a15
--- /dev/null
+++ b/libc/nptl/tst-tls5modd.c
@@ -0,0 +1,6 @@
+#include <tst-tls5.h>
+
+#ifdef TLS_REGISTER
+static __thread int d;
+TLS_REGISTER (d)
+#endif
diff --git a/libc/nptl/tst-tls5mode.c b/libc/nptl/tst-tls5mode.c
new file mode 100644
index 000000000..3e53ee1a6
--- /dev/null
+++ b/libc/nptl/tst-tls5mode.c
@@ -0,0 +1,8 @@
+#include <tst-tls5.h>
+
+#ifdef TLS_REGISTER
+static __thread int e1 = 24;
+static __thread char e2 [32] __attribute__ ((aligned (64)));
+TLS_REGISTER (e1)
+TLS_REGISTER (e2)
+#endif
diff --git a/libc/nptl/tst-tls5modf.c b/libc/nptl/tst-tls5modf.c
new file mode 100644
index 000000000..8e50962de
--- /dev/null
+++ b/libc/nptl/tst-tls5modf.c
@@ -0,0 +1,9 @@
+#include <tst-tls5.h>
+
+#ifdef TLS_REGISTER
+char tst_tls5modf[60] attribute_hidden = { 26 };
+static __thread int f1 = 24;
+static __thread char f2 [32] __attribute__ ((aligned (64)));
+TLS_REGISTER (f1)
+TLS_REGISTER (f2)
+#endif
diff --git a/libc/nptl/tst-tls6.sh b/libc/nptl/tst-tls6.sh
new file mode 100755
index 000000000..1ae24fc6f
--- /dev/null
+++ b/libc/nptl/tst-tls6.sh
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+common_objpfx=$1; shift
+elf_objpfx=$1; shift
+rtld_installed_name=$1; shift
+logfile=$common_objpfx/nptl/tst-tls6.out
+
+# We have to find libc and nptl
+library_path=${common_objpfx}:${common_objpfx}nptl
+tst_tls5="${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
+ ${common_objpfx}/nptl/tst-tls5"
+
+LC_ALL=C
+export LC_ALL
+LANG=C
+export LANG
+
+> $logfile
+fail=0
+
+for aligned in a e f; do
+ echo "preload tst-tls5mod{$aligned,b,c,d}.so" >> $logfile
+ echo "===============" >> $logfile
+ LD_PRELOAD=`echo ${common_objpfx}nptl/tst-tls5mod{$aligned,b,c,d}.so \
+ | sed 's/:$//;s/: /:/g'` ${tst_tls5} >> $logfile || fail=1
+ echo >> $logfile
+
+ echo "preload tst-tls5mod{b,$aligned,c,d}.so" >> $logfile
+ echo "===============" >> $logfile
+ LD_PRELOAD=`echo ${common_objpfx}nptl/tst-tls5mod{b,$aligned,c,d}.so \
+ | sed 's/:$//;s/: /:/g'` ${tst_tls5} >> $logfile || fail=1
+ echo >> $logfile
+
+ echo "preload tst-tls5mod{b,c,d,$aligned}.so" >> $logfile
+ echo "===============" >> $logfile
+ LD_PRELOAD=`echo ${common_objpfx}nptl/tst-tls5mod{b,c,d,$aligned}.so \
+ | sed 's/:$//;s/: /:/g'` ${tst_tls5} >> $logfile || fail=1
+ echo >> $logfile
+done
+
+echo "preload tst-tls5mod{d,a,b,c,e}" >> $logfile
+echo "===============" >> $logfile
+LD_PRELOAD=`echo ${common_objpfx}nptl/tst-tls5mod{d,a,b,c,e}.so \
+ | sed 's/:$//;s/: /:/g'` ${tst_tls5} >> $logfile || fail=1
+echo >> $logfile
+
+echo "preload tst-tls5mod{d,a,b,e,f}" >> $logfile
+echo "===============" >> $logfile
+LD_PRELOAD=`echo ${common_objpfx}nptl/tst-tls5mod{d,a,b,e,f}.so \
+ | sed 's/:$//;s/: /:/g'` ${tst_tls5} >> $logfile || fail=1
+echo >> $logfile
+
+exit $fail
diff --git a/libc/nptl/tst-tpp.h b/libc/nptl/tst-tpp.h
new file mode 100644
index 000000000..c5844b26d
--- /dev/null
+++ b/libc/nptl/tst-tpp.h
@@ -0,0 +1,94 @@
+/* Copyright (C) 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2006.
+
+ 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 <errno.h>
+#include <pthread.h>
+#include <sched.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+
+/* This test is Linux specific. */
+#define CHECK_TPP_PRIORITY(normal, boosted) \
+ do \
+ { \
+ pid_t tid = syscall (__NR_gettid); \
+ \
+ struct sched_param cep_sp; \
+ int cep_policy; \
+ if (pthread_getschedparam (pthread_self (), &cep_policy, \
+ &cep_sp) != 0) \
+ { \
+ puts ("getschedparam failed"); \
+ ret = 1; \
+ } \
+ else if (cep_sp.sched_priority != (normal)) \
+ { \
+ printf ("unexpected priority %d != %d\n", \
+ cep_sp.sched_priority, (normal)); \
+ } \
+ if (syscall (__NR_sched_getparam, tid, &cep_sp) == 0 \
+ && cep_sp.sched_priority != (boosted)) \
+ { \
+ printf ("unexpected boosted priority %d != %d\n", \
+ cep_sp.sched_priority, (boosted)); \
+ ret = 1; \
+ } \
+ } \
+ while (0)
+
+int fifo_min, fifo_max;
+
+void
+init_tpp_test (void)
+{
+ fifo_min = sched_get_priority_min (SCHED_FIFO);
+ if (fifo_min < 0)
+ {
+ printf ("couldn't get min priority for SCHED_FIFO: %m\n");
+ exit (1);
+ }
+
+ fifo_max = sched_get_priority_max (SCHED_FIFO);
+ if (fifo_max < 0)
+ {
+ printf ("couldn't get max priority for SCHED_FIFO: %m\n");
+ exit (1);
+ }
+
+ if (fifo_min > 4 || fifo_max < 10)
+ {
+ printf ("%d..%d SCHED_FIFO priority interval not suitable for this test\n",
+ fifo_min, fifo_max);
+ exit (0);
+ }
+
+ struct sched_param sp;
+ memset (&sp, 0, sizeof (sp));
+ sp.sched_priority = 4;
+ int e = pthread_setschedparam (pthread_self (), SCHED_FIFO, &sp);
+ if (e != 0)
+ {
+ errno = e;
+ printf ("cannot set scheduling params: %m\n");
+ exit (0);
+ }
+}
diff --git a/libc/nptl/tst-tsd1.c b/libc/nptl/tst-tsd1.c
new file mode 100644
index 000000000..51b2d0cb2
--- /dev/null
+++ b/libc/nptl/tst-tsd1.c
@@ -0,0 +1,118 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+#include <string.h>
+
+
+static int
+do_test (void)
+{
+ pthread_key_t key1;
+ pthread_key_t key2;
+ void *value;
+ int result = 0;
+ int err;
+
+ err = pthread_key_create (&key1, NULL);
+ if (err != 0)
+ {
+ printf ("1st key_create failed: %s\n", strerror (err));
+ return 1;
+ }
+
+ /* Initial value must be NULL. */
+ value = pthread_getspecific (key1);
+ if (value != NULL)
+ {
+ puts ("1st getspecific != NULL");
+ result = 1;
+ }
+
+ err = pthread_setspecific (key1, (void *) -2l);
+ if (err != 0)
+ {
+ printf ("1st setspecific failed: %s\n", strerror (err));
+ return 1;
+ }
+
+ value = pthread_getspecific (key1);
+ if (value == NULL)
+ {
+ puts ("2nd getspecific == NULL\n");
+ result = 1;
+ }
+ else if (value != (void *) -2l)
+ {
+ puts ("2nd getspecific != -2l\n");
+ result = 1;
+ }
+
+ err = pthread_setspecific (key1, (void *) -3l);
+ if (err != 0)
+ {
+ printf ("2nd setspecific failed: %s\n", strerror (err));
+ return 1;
+ }
+
+ value = pthread_getspecific (key1);
+ if (value == NULL)
+ {
+ puts ("3rd getspecific == NULL\n");
+ result = 1;
+ }
+ else if (value != (void *) -3l)
+ {
+ puts ("3rd getspecific != -2l\n");
+ result = 1;
+ }
+
+ err = pthread_key_delete (key1);
+ if (err != 0)
+ {
+ printf ("key_delete failed: %s\n", strerror (err));
+ result = 1;
+ }
+
+
+ err = pthread_key_create (&key2, NULL);
+ if (err != 0)
+ {
+ printf ("2nd key_create failed: %s\n", strerror (err));
+ return 1;
+ }
+
+ if (key1 != key2)
+ puts ("key1 != key2; no more tests performed");
+ else
+ {
+ value = pthread_getspecific (key2);
+ if (value != NULL)
+ {
+ puts ("4th getspecific != NULL");
+ result = 1;
+ }
+ }
+
+ return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-tsd2.c b/libc/nptl/tst-tsd2.c
new file mode 100644
index 000000000..19d8a69f9
--- /dev/null
+++ b/libc/nptl/tst-tsd2.c
@@ -0,0 +1,97 @@
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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>
+#include <stdio.h>
+#include <string.h>
+
+
+static int result;
+
+
+static void
+destr (void *arg)
+{
+ if (arg != (void *) -2l)
+ result = 2;
+ else
+ result = 0;
+}
+
+
+static void *
+tf (void *arg)
+{
+ pthread_key_t key = (pthread_key_t) (long int) arg;
+ int err;
+
+ err = pthread_setspecific (key, (void *) -2l);
+ if (err != 0)
+ result = 3;
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ pthread_key_t key;
+ pthread_t th;
+ int err;
+
+ err = pthread_key_create (&key, destr);
+ if (err != 0)
+ {
+ printf ("key_create failed: %s\n", strerror (err));
+ return 1;
+ }
+
+ result = 1;
+
+ err = pthread_create (&th, NULL, tf, (void *) (long int) key);
+ if (err != 0)
+ {
+ printf ("create failed: %s\n", strerror (err));
+ return 1;
+ }
+
+ /* Wait for the thread to terminate. */
+ err = pthread_join (th, NULL);
+ if (err != 0)
+ {
+ printf ("join failed: %s\n", strerror (err));
+ return 1;
+ }
+
+ if (result == 1)
+ puts ("destructor not called");
+ else if (result == 2)
+ puts ("destructor got passed a wrong value");
+ else if (result == 3)
+ puts ("setspecific in child failed");
+ else if (result != 0)
+ puts ("result != 0");
+
+ return result;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-tsd3.c b/libc/nptl/tst-tsd3.c
new file mode 100644
index 000000000..6cdf74991
--- /dev/null
+++ b/libc/nptl/tst-tsd3.c
@@ -0,0 +1,129 @@
+/* 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 <limits.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static pthread_key_t key1;
+static pthread_key_t key2;
+
+
+static int left;
+
+
+static void
+destr1 (void *arg)
+{
+ if (--left > 0)
+ {
+ puts ("set key2");
+
+ if (pthread_setspecific (key2, (void *) 1l) != 0)
+ {
+ puts ("destr1: setspecific failed");
+ exit (1);
+ }
+ }
+}
+
+
+static void
+destr2 (void *arg)
+{
+ if (--left > 0)
+ {
+ puts ("set key1");
+
+ if (pthread_setspecific (key1, (void *) 1l) != 0)
+ {
+ puts ("destr2: setspecific failed");
+ exit (1);
+ }
+ }
+}
+
+
+static void *
+tf (void *arg)
+{
+ /* Let the destructors work. */
+ left = 7;
+
+ if (pthread_setspecific (key1, (void *) 1l) != 0
+ || pthread_setspecific (key2, (void *) 1l) != 0)
+ {
+ puts ("tf: setspecific failed");
+ exit (1);
+ }
+
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ /* Allocate two keys, both with destructors. */
+ if (pthread_key_create (&key1, destr1) != 0
+ || pthread_key_create (&key2, destr2) != 0)
+ {
+ puts ("key_create failed");
+ return 1;
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ return 1;
+ }
+
+ if (pthread_join (th, NULL) != 0)
+ {
+ puts ("join failed");
+ return 1;
+ }
+
+ if (left != 0)
+ {
+ printf ("left == %d\n", left);
+ return 1;
+ }
+
+ if (pthread_getspecific (key1) != NULL)
+ {
+ puts ("key1 data != NULL");
+ return 1;
+ }
+ if (pthread_getspecific (key2) != NULL)
+ {
+ puts ("key2 data != NULL");
+ return 1;
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-tsd4.c b/libc/nptl/tst-tsd4.c
new file mode 100644
index 000000000..44bbadb42
--- /dev/null
+++ b/libc/nptl/tst-tsd4.c
@@ -0,0 +1,103 @@
+/* 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 <limits.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static pthread_key_t key;
+
+
+static int rounds;
+
+
+static void
+destr (void *arg)
+{
+ ++rounds;
+
+ if (pthread_setspecific (key, (void *) 1l) != 0)
+ {
+ puts ("destr: setspecific failed");
+ exit (1);
+ }
+}
+
+
+static void *
+tf (void *arg)
+{
+ if (pthread_setspecific (key, (void *) 1l) != 0)
+ {
+ puts ("tf: setspecific failed");
+ exit (1);
+ }
+
+ return NULL;
+}
+
+
+/* This test check non-standard behavior. The standard does not
+ require that the implementation has to stop calling TSD destructors
+ when they are set over and over again. But NPTL does. */
+static int
+do_test (void)
+{
+ /* Allocate two keys, both with destructors. */
+ if (pthread_key_create (&key, destr) != 0)
+ {
+ puts ("key_create failed");
+ return 1;
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ return 1;
+ }
+
+ if (pthread_join (th, NULL) != 0)
+ {
+ puts ("join failed");
+ return 1;
+ }
+
+ if (rounds < PTHREAD_DESTRUCTOR_ITERATIONS)
+ {
+ printf ("rounds == %d, PTHREAD_DESTRUCTOR_ITERATIONS = %d\n",
+ rounds, PTHREAD_DESTRUCTOR_ITERATIONS);
+ return 1;
+ }
+
+ if (pthread_getspecific (key) != NULL)
+ {
+ puts ("key data != NULL");
+ return 1;
+ }
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-tsd5.c b/libc/nptl/tst-tsd5.c
new file mode 100644
index 000000000..8793e339a
--- /dev/null
+++ b/libc/nptl/tst-tsd5.c
@@ -0,0 +1,81 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
+
+ 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>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
+
+
+static void
+cl (void *p)
+{
+ pthread_mutex_unlock (&m);
+}
+
+
+static void *
+tf (void *arg)
+{
+ if (pthread_mutex_lock (&m) != 0)
+ {
+ puts ("2nd mutex_lock failed");
+ exit (1);
+ }
+
+ exit (0);
+}
+
+
+static int
+do_test (void)
+{
+ pthread_key_t k;
+ if (pthread_key_create (&k, cl) != 0)
+ {
+ puts ("key_create failed");
+ return 1;
+ }
+ if (pthread_setspecific (k, (void *) 1) != 0)
+ {
+ puts ("setspecific failed");
+ return 1;
+ }
+
+ if (pthread_mutex_lock (&m) != 0)
+ {
+ puts ("1st mutex_lock failed");
+ return 1;
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
+ {
+ puts ("create failed");
+ return 1;
+ }
+
+ pthread_exit (NULL);
+}
+
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-typesizes.c b/libc/nptl/tst-typesizes.c
new file mode 100644
index 000000000..db8936f5f
--- /dev/null
+++ b/libc/nptl/tst-typesizes.c
@@ -0,0 +1,68 @@
+/* Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2005.
+
+ 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 <stdio.h>
+#include <pthreadP.h>
+#include <semaphore.h>
+
+
+static int
+do_test (void)
+{
+ int result = 0;
+
+#define TEST_TYPE(name) \
+ printf ("%s: ", #name); \
+ if (sizeof (name) != sizeof (((name *) 0)->__size)) \
+ { \
+ printf ("expected %zu, is %zu\n", \
+ sizeof (((name *) 0)->__size), sizeof (name)); \
+ result = 1; \
+ } \
+ else \
+ puts ("OK")
+
+ TEST_TYPE (pthread_mutex_t);
+ TEST_TYPE (pthread_cond_t);
+ TEST_TYPE (pthread_rwlock_t);
+
+#define TEST_TYPE2(name, internal) \
+ printf ("%s: ", #name); \
+ if (sizeof (((name *) 0)->__size) < sizeof (internal)) \
+ { \
+ printf ("expected %zu, is %zu\n", \
+ sizeof (((name *) 0)->__size), sizeof (internal)); \
+ result = 1; \
+ } \
+ else \
+ puts ("OK")
+
+ TEST_TYPE2 (pthread_attr_t, struct pthread_attr);
+ TEST_TYPE2 (pthread_mutexattr_t, struct pthread_mutexattr);
+ TEST_TYPE2 (pthread_condattr_t, struct pthread_condattr);
+ TEST_TYPE2 (pthread_rwlockattr_t, struct pthread_rwlockattr);
+ TEST_TYPE2 (pthread_barrier_t, struct pthread_barrier);
+ TEST_TYPE2 (pthread_barrierattr_t, struct pthread_barrierattr);
+ TEST_TYPE2 (sem_t, struct sem);
+
+ return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-umask1.c b/libc/nptl/tst-umask1.c
new file mode 100644
index 000000000..bd7531901
--- /dev/null
+++ b/libc/nptl/tst-umask1.c
@@ -0,0 +1,137 @@
+/* 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 <fcntl.h>
+#include <pthread.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/stat.h>
+
+
+static struct
+{
+ int (*fp) (const char *, mode_t);
+ const char *name;
+ bool is_fd;
+} fcts[] =
+{
+ { creat, "creat", true },
+ { mkdir, "mkdir", false },
+ { mkfifo, "mkfifo", false },
+};
+#define nfcts (sizeof (fcts) / sizeof (fcts[0]))
+
+
+static int
+work (const char *fname, int mask)
+{
+ int result = 0;
+ size_t i;
+ for (i = 0; i < nfcts; ++i)
+ {
+ remove (fname);
+ int fd = fcts[i].fp (fname, 0777);
+ if (fd == -1)
+ {
+ printf ("cannot %s %s: %m\n", fcts[i].name, fname);
+ exit (1);
+ }
+ if (fcts[i].is_fd)
+ close (fd);
+ struct stat64 st;
+ if (stat64 (fname, &st) == -1)
+ {
+ printf ("cannot stat %s after %s: %m\n", fname, fcts[i].name);
+ exit (1);
+ }
+
+ if ((st.st_mode & mask) != 0)
+ {
+ printf ("mask not successful after %s: %x still set\n",
+ fcts[i].name, (unsigned int) (st.st_mode & mask));
+ result = 1;
+ }
+ }
+
+ return result;
+}
+
+
+static pthread_barrier_t bar;
+
+
+static void *
+tf (void *arg)
+{
+ pthread_barrier_wait (&bar);
+
+ int result = work (arg, 022);
+
+ pthread_barrier_wait (&bar);
+
+ pthread_barrier_wait (&bar);
+
+ return (work (arg, 0) | result) ? (void *) -1l : NULL;
+}
+
+
+static int
+do_test (const char *fname)
+{
+ int result = 0;
+
+ umask (0);
+ result |= work (fname, 0);
+
+ pthread_barrier_init (&bar, NULL, 2);
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, (void *) fname) != 0)
+ {
+ puts ("cannot create thread");
+ exit (1);
+ }
+
+ umask (022);
+ result |= work (fname, 022);
+
+ pthread_barrier_wait (&bar);
+
+ pthread_barrier_wait (&bar);
+
+ umask (0);
+
+ pthread_barrier_wait (&bar);
+
+ void *res;
+ if (pthread_join (th, &res) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ remove (fname);
+
+ return result || res != NULL;
+}
+
+#define TEST_FUNCTION do_test (argc < 2 ? "/tmp/tst-umask.tmp" : argv[1])
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-unload.c b/libc/nptl/tst-unload.c
new file mode 100644
index 000000000..4ff43bb63
--- /dev/null
+++ b/libc/nptl/tst-unload.c
@@ -0,0 +1,48 @@
+/* Tests for non-unloading of libpthread.
+ Copyright (C) 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2000.
+
+ 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; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <dlfcn.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <gnu/lib-names.h>
+
+static int
+do_test (void)
+{
+ void *p = dlopen (LIBPTHREAD_SO, RTLD_LAZY);
+
+ if (p == NULL)
+ {
+ puts ("failed to load " LIBPTHREAD_SO);
+ return 1;
+ }
+
+ if (dlclose (p) != 0)
+ {
+ puts ("dlclose (" LIBPTHREAD_SO ") failed");
+ return 1;
+ }
+
+ puts ("seems to work");
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/libc/nptl/tst-vfork1.c b/libc/nptl/tst-vfork1.c
new file mode 100644
index 000000000..f409ec49b
--- /dev/null
+++ b/libc/nptl/tst-vfork1.c
@@ -0,0 +1 @@
+#include <posix/tst-vfork1.c>
diff --git a/libc/nptl/tst-vfork1x.c b/libc/nptl/tst-vfork1x.c
new file mode 100644
index 000000000..f409ec49b
--- /dev/null
+++ b/libc/nptl/tst-vfork1x.c
@@ -0,0 +1 @@
+#include <posix/tst-vfork1.c>
diff --git a/libc/nptl/tst-vfork2.c b/libc/nptl/tst-vfork2.c
new file mode 100644
index 000000000..5356e8311
--- /dev/null
+++ b/libc/nptl/tst-vfork2.c
@@ -0,0 +1 @@
+#include <posix/tst-vfork2.c>
diff --git a/libc/nptl/tst-vfork2x.c b/libc/nptl/tst-vfork2x.c
new file mode 100644
index 000000000..5356e8311
--- /dev/null
+++ b/libc/nptl/tst-vfork2x.c
@@ -0,0 +1 @@
+#include <posix/tst-vfork2.c>
diff --git a/libc/nptl/unwind.c b/libc/nptl/unwind.c
new file mode 100644
index 000000000..9a35695cb
--- /dev/null
+++ b/libc/nptl/unwind.c
@@ -0,0 +1,176 @@
+/* Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>
+ and Richard Henderson <rth@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 <setjmp.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "pthreadP.h"
+#include <jmpbuf-unwind.h>
+
+#ifdef HAVE_FORCED_UNWIND
+
+#ifdef _STACK_GROWS_DOWN
+# define FRAME_LEFT(frame, other, adj) \
+ ((uintptr_t) frame - adj >= (uintptr_t) other - adj)
+#elif _STACK_GROWS_UP
+# define FRAME_LEFT(frame, other, adj) \
+ ((uintptr_t) frame - adj <= (uintptr_t) other - adj)
+#else
+# error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
+#endif
+
+static _Unwind_Reason_Code
+unwind_stop (int version, _Unwind_Action actions,
+ _Unwind_Exception_Class exc_class,
+ struct _Unwind_Exception *exc_obj,
+ struct _Unwind_Context *context, void *stop_parameter)
+{
+ struct pthread_unwind_buf *buf = stop_parameter;
+ struct pthread *self = THREAD_SELF;
+ struct _pthread_cleanup_buffer *curp = THREAD_GETMEM (self, cleanup);
+ int do_longjump = 0;
+
+ /* Adjust all pointers used in comparisons, so that top of thread's
+ stack is at the top of address space. Without that, things break
+ if stack is allocated above the main stack. */
+ uintptr_t adj = (uintptr_t) self->stackblock + self->stackblock_size;
+
+ /* Do longjmp if we're at "end of stack", aka "end of unwind data".
+ We assume there are only C frame without unwind data in between
+ here and the jmp_buf target. Otherwise simply note that the CFA
+ of a function is NOT within it's stack frame; it's the SP of the
+ previous frame. */
+ if ((actions & _UA_END_OF_STACK)
+ || ! _JMPBUF_CFA_UNWINDS_ADJ (buf->cancel_jmp_buf[0].jmp_buf, context,
+ adj))
+ do_longjump = 1;
+
+ if (__builtin_expect (curp != NULL, 0))
+ {
+ /* Handle the compatibility stuff. Execute all handlers
+ registered with the old method which would be unwound by this
+ step. */
+ struct _pthread_cleanup_buffer *oldp = buf->priv.data.cleanup;
+ void *cfa = (void *) _Unwind_GetCFA (context);
+
+ if (curp != oldp && (do_longjump || FRAME_LEFT (cfa, curp, adj)))
+ {
+ do
+ {
+ /* Pointer to the next element. */
+ struct _pthread_cleanup_buffer *nextp = curp->__prev;
+
+ /* Call the handler. */
+ curp->__routine (curp->__arg);
+
+ /* To the next. */
+ curp = nextp;
+ }
+ while (curp != oldp
+ && (do_longjump || FRAME_LEFT (cfa, curp, adj)));
+
+ /* Mark the current element as handled. */
+ THREAD_SETMEM (self, cleanup, curp);
+ }
+ }
+
+ if (do_longjump)
+ __libc_unwind_longjmp ((struct __jmp_buf_tag *) buf->cancel_jmp_buf, 1);
+
+ return _URC_NO_REASON;
+}
+
+
+static void
+unwind_cleanup (_Unwind_Reason_Code reason, struct _Unwind_Exception *exc)
+{
+ /* When we get here a C++ catch block didn't rethrow the object. We
+ cannot handle this case and therefore abort. */
+# define STR_N_LEN(str) str, strlen (str)
+ INTERNAL_SYSCALL_DECL (err);
+ INTERNAL_SYSCALL (write, err, 3, STDERR_FILENO,
+ STR_N_LEN ("FATAL: exception not rethrown\n"));
+ abort ();
+}
+
+#endif /* have forced unwind */
+
+
+void
+__cleanup_fct_attribute __attribute ((noreturn))
+__pthread_unwind (__pthread_unwind_buf_t *buf)
+{
+ struct pthread_unwind_buf *ibuf = (struct pthread_unwind_buf *) buf;
+ struct pthread *self = THREAD_SELF;
+
+#ifdef HAVE_FORCED_UNWIND
+ /* This is not a catchable exception, so don't provide any details about
+ the exception type. We do need to initialize the field though. */
+ THREAD_SETMEM (self, exc.exception_class, 0);
+ THREAD_SETMEM (self, exc.exception_cleanup, unwind_cleanup);
+
+ _Unwind_ForcedUnwind (&self->exc, unwind_stop, ibuf);
+#else
+ /* Handle the compatibility stuff first. Execute all handlers
+ registered with the old method. We don't execute them in order,
+ instead, they will run first. */
+ struct _pthread_cleanup_buffer *oldp = ibuf->priv.data.cleanup;
+ struct _pthread_cleanup_buffer *curp = THREAD_GETMEM (self, cleanup);
+
+ if (curp != oldp)
+ {
+ do
+ {
+ /* Pointer to the next element. */
+ struct _pthread_cleanup_buffer *nextp = curp->__prev;
+
+ /* Call the handler. */
+ curp->__routine (curp->__arg);
+
+ /* To the next. */
+ curp = nextp;
+ }
+ while (curp != oldp);
+
+ /* Mark the current element as handled. */
+ THREAD_SETMEM (self, cleanup, curp);
+ }
+
+ /* We simply jump to the registered setjmp buffer. */
+ __libc_unwind_longjmp ((struct __jmp_buf_tag *) ibuf->cancel_jmp_buf, 1);
+#endif
+ /* NOTREACHED */
+
+ /* We better do not get here. */
+ abort ();
+}
+hidden_def (__pthread_unwind)
+
+
+void
+__cleanup_fct_attribute __attribute ((noreturn))
+__pthread_unwind_next (__pthread_unwind_buf_t *buf)
+{
+ struct pthread_unwind_buf *ibuf = (struct pthread_unwind_buf *) buf;
+
+ __pthread_unwind ((__pthread_unwind_buf_t *) ibuf->priv.data.prev);
+}
+hidden_def (__pthread_unwind_next)
diff --git a/libc/nptl/vars.c b/libc/nptl/vars.c
new file mode 100644
index 000000000..1e1a3cf5b
--- /dev/null
+++ b/libc/nptl/vars.c
@@ -0,0 +1,43 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ 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 <pthreadP.h>
+#include <stdlib.h>
+#include <tls.h>
+#include <unistd.h>
+
+/* Default stack size. */
+size_t __default_stacksize attribute_hidden
+#ifdef SHARED
+;
+#else
+ = PTHREAD_STACK_MIN;
+#endif
+
+/* Flag whether the machine is SMP or not. */
+int __is_smp attribute_hidden;
+
+#ifndef TLS_MULTIPLE_THREADS_IN_TCB
+/* Variable set to a nonzero value if more than one thread runs or ran. */
+int __pthread_multiple_threads attribute_hidden;
+#endif
+
+/* Table of the key information. */
+struct pthread_key_struct __pthread_keys[PTHREAD_KEYS_MAX]
+ __attribute__ ((nocommon));
+hidden_data_def (__pthread_keys)
diff --git a/libc/nptl/version.c b/libc/nptl/version.c
new file mode 100644
index 000000000..b69556e94
--- /dev/null
+++ b/libc/nptl/version.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <unistd.h>
+#include <sysdep.h>
+
+
+static const char banner[] =
+#include "banner.h"
+"Copyright (C) 2006 Free Software Foundation, Inc.\n\
+This is free software; see the source for copying conditions.\n\
+There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A\n\
+PARTICULAR PURPOSE.\n"
+#ifdef HAVE_FORCED_UNWIND
+"Forced unwind support included.\n"
+#endif
+;
+
+
+extern void __nptl_main (void) __attribute__ ((noreturn));
+void
+__nptl_main (void)
+{
+ INTERNAL_SYSCALL_DECL (err);
+ INTERNAL_SYSCALL (write, err, 3, STDOUT_FILENO, (const char *) banner,
+ sizeof banner - 1);
+
+ _exit (0);
+}