This is the mail archive of the glibc-cvs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GNU C Library master sources branch sthibaul/hurd-builds created. glibc-2.26.9000-1194-g4d292fd


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, sthibaul/hurd-builds has been created
        at  4d292fdd58502f449458b5a43bcc62b705d2bdb9 (commit)

- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=4d292fdd58502f449458b5a43bcc62b705d2bdb9

commit 4d292fdd58502f449458b5a43bcc62b705d2bdb9
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Thu Jan 25 02:22:50 2018 +0100

    fix spurious whitespaces

diff --git a/htl/Makefile b/htl/Makefile
index d64be68..29fd8cd 100644
--- a/htl/Makefile
+++ b/htl/Makefile
@@ -163,7 +163,7 @@ ifeq ($(IN_GLIBC),no)
 SRCS := $(addsuffix .c,$(libpthread-routines))
 OBJS = $(addsuffix .o,$(basename $(notdir $(SRCS))))
 
-OTHERTAGS = 
+OTHERTAGS =
 
 libname = libpthread
 endif
@@ -360,10 +360,10 @@ maintainer.;								\
 	fi
 
 #  ifeq ($(VERSIONING),yes)
-#  
+#
 #  # Adding this dependency gets it included in the command line,
 #  # where ld will read it as a linker script.
 #  $(libname).so.$(hurd-version): $(srcdir)/$(libname).map
-#  
+#
 #  endif
 endif
diff --git a/htl/pthread/pt-alloc.c b/htl/pthread/pt-alloc.c
index 21063d5..e34a043 100644
--- a/htl/pthread/pt-alloc.c
+++ b/htl/pthread/pt-alloc.c
@@ -28,7 +28,7 @@
 /* This braindamage is necessary because the standard says that some
    of the threads functions "shall fail" if "No thread could be found
    corresponding to that specified by the given thread ID."  */
-   
+
 /* Thread ID lookup table.  */
 struct __pthread **__pthread_threads;
 
diff --git a/htl/pthread/pt-create.c b/htl/pthread/pt-create.c
index c9e0730..e517087 100644
--- a/htl/pthread/pt-create.c
+++ b/htl/pthread/pt-create.c
@@ -185,7 +185,7 @@ __pthread_create_internal (struct __pthread **thread,
   else
     err = __pthread_sigstate (_pthread_self (), 0, 0, &sigset, 0);
   assert_perror (err);
-   
+
   err = __pthread_sigstate (pthread, SIG_SETMASK, &sigset, 0, 1);
   assert_perror (err);
 
diff --git a/htl/sysdeps/generic/pt-attr-setstack.c b/htl/sysdeps/generic/pt-attr-setstack.c
index 360d27a..431d6a4 100644
--- a/htl/sysdeps/generic/pt-attr-setstack.c
+++ b/htl/sysdeps/generic/pt-attr-setstack.c
@@ -46,6 +46,6 @@ pthread_attr_setstack (pthread_attr_t *attr,
 
       return err;
     }
-      
+
   return 0;
 }
diff --git a/htl/sysdeps/generic/pt-cond-signal.c b/htl/sysdeps/generic/pt-cond-signal.c
index 4b5450c..93f7ac7 100644
--- a/htl/sysdeps/generic/pt-cond-signal.c
+++ b/htl/sysdeps/generic/pt-cond-signal.c
@@ -27,7 +27,7 @@ int
 __pthread_cond_signal (pthread_cond_t *cond)
 {
   struct __pthread *wakeup;
-  
+
   __pthread_spin_lock (&cond->__lock);
   wakeup = cond->__queue;
   if (wakeup)
diff --git a/htl/sysdeps/generic/pt-key.h b/htl/sysdeps/generic/pt-key.h
index 46830d7..759ab68 100644
--- a/htl/sysdeps/generic/pt-key.h
+++ b/htl/sysdeps/generic/pt-key.h
@@ -30,7 +30,7 @@
 /* __PTHREAD_KEY_DESTRUCTORS is an array of destructors with
    __PTHREAD_KEY_SIZE elements.  If an element with index less than
    __PTHREAD_KEY_COUNT is invalid, it shall contain the value
-   PTHREAD_KEY_INVALID which shall be distinct from NULL.  
+   PTHREAD_KEY_INVALID which shall be distinct from NULL.
 
    Normally, we just add new keys to the end of the array and realloc
    it as necessary.  The pthread_key_create routine may decide to
diff --git a/htl/sysdeps/generic/pt-rwlock-unlock.c b/htl/sysdeps/generic/pt-rwlock-unlock.c
index 0506ae6..b796508 100644
--- a/htl/sysdeps/generic/pt-rwlock-unlock.c
+++ b/htl/sysdeps/generic/pt-rwlock-unlock.c
@@ -28,7 +28,7 @@ int
 __pthread_rwlock_unlock (pthread_rwlock_t *rwlock)
 {
   struct __pthread *wakeup;
-  
+
   __pthread_spin_lock (&rwlock->__lock);
 
   assert (__pthread_spin_trylock (&rwlock->__held) == EBUSY);
@@ -44,7 +44,7 @@ __pthread_rwlock_unlock (pthread_rwlock_t *rwlock)
   if (rwlock->__readers == 1)
     /* Last reader.  */
     rwlock->__readers = 0;
-      
+
 
   /* Wake someone else up.  Try the writer queue first, then the
      reader queue if that is empty.  */
diff --git a/htl/sysdeps/mach/hurd/pt-docancel.c b/htl/sysdeps/mach/hurd/pt-docancel.c
index b3a5507..12bbafb 100644
--- a/htl/sysdeps/mach/hurd/pt-docancel.c
+++ b/htl/sysdeps/mach/hurd/pt-docancel.c
@@ -47,7 +47,7 @@ __pthread_do_cancel (struct __pthread *p)
   else
     {
       error_t err;
-      
+
       err = __thread_suspend (p->kernel_thread);
       assert_perror (err);
 
diff --git a/htl/sysdeps/mach/hurd/pt-mutexattr-gettype.c b/htl/sysdeps/mach/hurd/pt-mutexattr-gettype.c
index 746f628..754cc04 100644
--- a/htl/sysdeps/mach/hurd/pt-mutexattr-gettype.c
+++ b/htl/sysdeps/mach/hurd/pt-mutexattr-gettype.c
@@ -28,4 +28,3 @@ int pthread_mutexattr_gettype (const pthread_mutexattr_t *attrp, int *outp)
   *outp = attrp->__mutex_type;
   return (0);
 }
-
diff --git a/htl/sysdeps/mach/pt-wakeup.c b/htl/sysdeps/mach/pt-wakeup.c
index 95fdbf9..c2eb9ca 100644
--- a/htl/sysdeps/mach/pt-wakeup.c
+++ b/htl/sysdeps/mach/pt-wakeup.c
@@ -30,7 +30,7 @@ void
 __pthread_wakeup (struct __pthread *thread)
 {
   error_t err;
-  
+
   err = __mach_msg (&thread->wakeupmsg, MACH_SEND_MSG | MACH_SEND_TIMEOUT,
 		    sizeof (thread->wakeupmsg), 0, MACH_PORT_NULL,
 		    0 , MACH_PORT_NULL);
diff --git a/htl/sysdeps/pthread/bits/cancelation.h b/htl/sysdeps/pthread/bits/cancelation.h
index 1ed16c6..42c0a3a 100644
--- a/htl/sysdeps/pthread/bits/cancelation.h
+++ b/htl/sysdeps/pthread/bits/cancelation.h
@@ -41,7 +41,7 @@ struct __pthread_cancelation_handler **__pthread_get_cleanup_stack (void);
 	      *__handlers \
 	    }; \
 	  *__handlers = &__handler;
-	  
+
 #define __pthread_cleanup_pop(execute) \
 	  if (execute) \
 	    __handler.__handler (__handler.__arg); \
diff --git a/htl/sysdeps/pthread/bits/pthreadtypes.h b/htl/sysdeps/pthread/bits/pthreadtypes.h
index 3e44d6b..bdbfc19 100644
--- a/htl/sysdeps/pthread/bits/pthreadtypes.h
+++ b/htl/sysdeps/pthread/bits/pthreadtypes.h
@@ -1,4 +1,4 @@
-/* 
+/*
    Copyright (C) 2000-2017 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
diff --git a/htl/sysdeps/pthread/pthread-functions.h b/htl/sysdeps/pthread/pthread-functions.h
index 0fc8968..db30f13 100644
--- a/htl/sysdeps/pthread/pthread-functions.h
+++ b/htl/sysdeps/pthread/pthread-functions.h
@@ -29,9 +29,9 @@ int __pthread_attr_setdetachstate (pthread_attr_t *, int);
 int __pthread_attr_getinheritsched (const pthread_attr_t *, int *);
 int __pthread_attr_setinheritsched (pthread_attr_t *, int);
 int __pthread_attr_getschedparam (const pthread_attr_t *,
-    				 struct sched_param *);
+				 struct sched_param *);
 int __pthread_attr_setschedparam (pthread_attr_t *,
-    				 const struct sched_param *);
+				 const struct sched_param *);
 int __pthread_attr_getschedpolicy (const pthread_attr_t *, int *);
 int __pthread_attr_setschedpolicy (pthread_attr_t *, int);
 int __pthread_attr_getscope (const pthread_attr_t *, int *);
@@ -41,19 +41,19 @@ int __pthread_condattr_init (pthread_condattr_t *);
 int __pthread_cond_broadcast (pthread_cond_t *);
 int __pthread_cond_destroy (pthread_cond_t *);
 int __pthread_cond_init (pthread_cond_t *,
-    		       const pthread_condattr_t *);
+		       const pthread_condattr_t *);
 int __pthread_cond_signal (pthread_cond_t *);
 int __pthread_cond_wait (pthread_cond_t *, pthread_mutex_t *);
 int __pthread_cond_timedwait (pthread_cond_t *, pthread_mutex_t *,
-    			     const struct timespec *);
+			     const struct timespec *);
 int __pthread_equal (pthread_t, pthread_t);
 void __pthread_exit (void *);
 int __pthread_getschedparam (pthread_t, int *, struct sched_param *);
 int __pthread_setschedparam (pthread_t, int,
-    			    const struct sched_param *);
+			    const struct sched_param *);
 int _pthread_mutex_destroy (pthread_mutex_t *);
 int _pthread_mutex_init (pthread_mutex_t *,
-    			 const pthread_mutexattr_t *);
+			 const pthread_mutexattr_t *);
 int __pthread_mutex_lock (pthread_mutex_t *);
 int __pthread_mutex_trylock (pthread_mutex_t *);
 int __pthread_mutex_unlock (pthread_mutex_t *);
diff --git a/htl/tests/test-11.c b/htl/tests/test-11.c
index de779a4..f5a5aa0 100644
--- a/htl/tests/test-11.c
+++ b/htl/tests/test-11.c
@@ -109,11 +109,11 @@ main (int argc, char **argv)
   /* Read lock it.  */
   err = pthread_rwlock_tryrdlock (&lock);
   assert (err == 0);
-  
+
   /* Try to write lock it.  It should fail with EBUSY.  */
   err = pthread_rwlock_trywrlock (&lock);
   assert (err == EBUSY);
-  
+
   /* Drop the read lock.  */
   err = pthread_rwlock_unlock (&lock);
   assert (err == 0);
diff --git a/htl/tests/test-6.c b/htl/tests/test-6.c
index edf2919..205c7a4 100644
--- a/htl/tests/test-6.c
+++ b/htl/tests/test-6.c
@@ -50,7 +50,7 @@ main (int argc, char **argv)
     error (1, err, "pthread_barrier_init");
 
   for (j = 0; j < WAITS; j ++)
-    {    
+    {
 
       for (i = 0; i < THREADS; i ++)
 	{
diff --git a/htl/tests/test-7.c b/htl/tests/test-7.c
index 22fb1ca..be724ce 100644
--- a/htl/tests/test-7.c
+++ b/htl/tests/test-7.c
@@ -23,7 +23,7 @@ thr (void *arg)
       assert (pthread_getspecific (key[i]) == NULL);
       printf ("pthread_setspecific(%d, %d).\n", key[i], pthread_self ());
       err = pthread_setspecific (key[i], (void *) pthread_self ());
-      printf ("pthread_setspecific(%d, %d) => %d.\n", key[i], pthread_self (), err);      
+      printf ("pthread_setspecific(%d, %d) => %d.\n", key[i], pthread_self (), err);
       assert_perror (err);
     }
 

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=c89f6f3b3bc1d2eea57468be843a3d2412f7a002

commit c89f6f3b3bc1d2eea57468be843a3d2412f7a002
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Thu Jan 25 02:07:26 2018 +0100

    Update directory name

diff --git a/htl/Makeconfig b/htl/Makeconfig
index e90f5f7..044c4e6 100644
--- a/htl/Makeconfig
+++ b/htl/Makeconfig
@@ -3,11 +3,11 @@
 
 have-thread-library = yes
 
-shared-thread-library = $(common-objpfx)libpthread/libpthread_nonshared.a \
-			$(common-objpfx)libpthread/libpthread.so
-static-thread-library = $(common-objpfx)libpthread/libpthread.a
+shared-thread-library = $(common-objpfx)htl/libpthread_nonshared.a \
+			$(common-objpfx)htl/libpthread.so
+static-thread-library = $(common-objpfx)htl/libpthread.a
 bounded-thread-library = $(static-thread-library)
 
-rpath-dirs += libpthread
+rpath-dirs += htl
 
-+includes += -I$(..)libpthread/include
++includes += -I$(..)htl/include
diff --git a/htl/Makefile b/htl/Makefile
index 2fab448..d64be68 100644
--- a/htl/Makefile
+++ b/htl/Makefile
@@ -278,7 +278,7 @@ $(inst_libdir)/libpthread2_pic.a: $(inst_libdir)/libpthread_pic.a
 ifeq ($(IN_GLIBC),yes)
 libc-link.so = $(common-objpfx)libc.so
 
-extra-B-pthread.so = -B$(common-objpfx)libpthread/
+extra-B-pthread.so = -B$(common-objpfx)htl/
 
 include ../Rules
 
diff --git a/nscd/Depend b/nscd/Depend
index c29ffb5..ba64a2d 100644
--- a/nscd/Depend
+++ b/nscd/Depend
@@ -1,2 +1,2 @@
 nptl
-libpthread
+htl
diff --git a/resolv/Depend b/resolv/Depend
index c29ffb5..ba64a2d 100644
--- a/resolv/Depend
+++ b/resolv/Depend
@@ -1,2 +1,2 @@
 nptl
-libpthread
+htl
diff --git a/rt/Depend b/rt/Depend
index c29ffb5..ba64a2d 100644
--- a/rt/Depend
+++ b/rt/Depend
@@ -1,2 +1,2 @@
 nptl
-libpthread
+htl

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=e10387595e3f75361eed50636074646590756481

commit e10387595e3f75361eed50636074646590756481
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Thu Jan 25 01:49:49 2018 +0100

    Revert signal disposition, not in glibc's cvs yet

diff --git a/htl/sysdeps/mach/hurd/pt-sigstate.c b/htl/sysdeps/mach/hurd/pt-sigstate.c
index 74fd72a..c7b4093 100644
--- a/htl/sysdeps/mach/hurd/pt-sigstate.c
+++ b/htl/sysdeps/mach/hurd/pt-sigstate.c
@@ -21,7 +21,6 @@
 #include <assert.h>
 #include <signal.h>
 #include <hurd/signal.h>
-#include <hurd/msg.h>
 
 #include <pt-internal.h>
 
@@ -32,12 +31,11 @@ __pthread_sigstate (struct __pthread *thread, int how,
 {
   error_t err = 0;
   struct hurd_sigstate *ss;
-  sigset_t pending;
 
   ss = _hurd_thread_sigstate (thread->kernel_thread);
   assert (ss);
 
-  _hurd_sigstate_lock (ss);
+  __pthread_spin_lock (&ss->lock);
 
   if (oset)
     *oset = ss->blocked;
@@ -68,13 +66,7 @@ __pthread_sigstate (struct __pthread *thread, int how,
   if (! err && clear_pending)
     __sigemptyset (&ss->pending);
 
-  pending = _hurd_sigstate_pending (ss) & ~ss->blocked;
-  _hurd_sigstate_unlock (ss);
-
-  if (! err && pending)
-    /* Send a message to the signal thread so it
-       will wake up and check for pending signals.  */
-    __msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ());
+  __pthread_spin_unlock (&ss->lock);
 
   return err;
 }

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=eea5b8c0ea315c3f23a6a06d1803e030abaa26fa

commit eea5b8c0ea315c3f23a6a06d1803e030abaa26fa
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Thu Jan 25 01:48:24 2018 +0100

    plug htl subdir to the build, hackish for now

diff --git a/sysdeps/htl/Makeconfig b/sysdeps/htl/Makeconfig
new file mode 100644
index 0000000..c4c5ba2
--- /dev/null
+++ b/sysdeps/htl/Makeconfig
@@ -0,0 +1 @@
+include $(..)htl/Makeconfig
diff --git a/sysdeps/mach/hurd/Implies b/sysdeps/mach/hurd/Implies
index d2d5234..666c3e0 100644
--- a/sysdeps/mach/hurd/Implies
+++ b/sysdeps/mach/hurd/Implies
@@ -3,3 +3,9 @@
 gnu
 # The Hurd provides a rough superset of the functionality of 4.4 BSD.
 unix/bsd
+htl
+../htl/sysdeps/mach/hurd
+../htl/sysdeps/hurd
+../htl/sysdeps/mach
+../htl/sysdeps/posix
+../htl/sysdeps/generic
diff --git a/sysdeps/mach/hurd/Subdirs b/sysdeps/mach/hurd/Subdirs
index 7a77575..d0fa0e8 100644
--- a/sysdeps/mach/hurd/Subdirs
+++ b/sysdeps/mach/hurd/Subdirs
@@ -7,3 +7,5 @@
 # way with more somewhat expensive `make' invocations.
 
 first hurd
+
+htl
diff --git a/sysdeps/mach/hurd/i386/Implies b/sysdeps/mach/hurd/i386/Implies
index 94db5e9..50ecde8 100644
--- a/sysdeps/mach/hurd/i386/Implies
+++ b/sysdeps/mach/hurd/i386/Implies
@@ -1 +1,3 @@
 mach/hurd/x86
+../htl/sysdeps/mach/hurd/i386
+../htl/sysdeps/i386

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=e36f5832e11deff6d943e3d7fcb2dd06577b0700

commit e36f5832e11deff6d943e3d7fcb2dd06577b0700
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Thu Jan 25 01:47:51 2018 +0100

    Until posix thread signal distribution is commited

diff --git a/htl/sysdeps/mach/hurd/pt-sigstate-destroy.c b/htl/sysdeps/mach/hurd/pt-sigstate-destroy.c
index d5e28d2..fce56c5 100644
--- a/htl/sysdeps/mach/hurd/pt-sigstate-destroy.c
+++ b/htl/sysdeps/mach/hurd/pt-sigstate-destroy.c
@@ -24,5 +24,5 @@
 void
 __pthread_sigstate_destroy (struct __pthread *thread)
 {
-  _hurd_sigstate_delete (thread->kernel_thread);
+  //_hurd_sigstate_delete (thread->kernel_thread);
 }
diff --git a/htl/sysdeps/mach/hurd/pt-sigstate-init.c b/htl/sysdeps/mach/hurd/pt-sigstate-init.c
index 500b4d4..753d40e 100644
--- a/htl/sysdeps/mach/hurd/pt-sigstate-init.c
+++ b/htl/sysdeps/mach/hurd/pt-sigstate-init.c
@@ -35,7 +35,7 @@ __pthread_sigstate_init (struct __pthread *thread)
   if (do_init_global)
     {
       struct hurd_sigstate *ss = _hurd_thread_sigstate (thread->kernel_thread);
-      _hurd_sigstate_set_global_rcv (ss);
+      //_hurd_sigstate_set_global_rcv (ss);
     }
   else if (__pthread_num_threads >= 2)
     do_init_global = 1;

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=b4224e5fb7252684dbc047f17d34713b96930e98

commit b4224e5fb7252684dbc047f17d34713b96930e98
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Thu Jan 25 01:47:29 2018 +0100

    Hack htl build failures

diff --git a/htl/pthread/pt-initialize.c b/htl/pthread/pt-initialize.c
index 4435a36..282205f 100644
--- a/htl/pthread/pt-initialize.c
+++ b/htl/pthread/pt-initialize.c
@@ -77,6 +77,11 @@ static const struct pthread_functions pthread_functions =
   };
 #endif /* IS_IN (libpthread) */
 
+static void none(void)
+{
+}
+text_set_element (__pthread_init, none);
+
 /* Initialize the pthreads library.  */
 void
 ___pthread_init (void)
diff --git a/resolv/gai_notify.c b/resolv/gai_notify.c
index dad2546..93924d2 100644
--- a/resolv/gai_notify.c
+++ b/resolv/gai_notify.c
@@ -31,7 +31,9 @@ struct notify_func
 static void *
 notify_func_wrapper (void *arg)
 {
+#ifdef gai_start_notify_thread
   gai_start_notify_thread ();
+#endif
   struct notify_func *const n = arg;
   void (*func) (sigval_t) = n->func;
   sigval_t value = n->value;

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=70e2ece674c3be8393e96423443dc70e1f0155a8

commit 70e2ece674c3be8393e96423443dc70e1f0155a8
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Thu Jan 25 01:44:57 2018 +0100

    Import Hurd libpthread git snapshot 4cd68f934f6e

diff --git a/htl/ChangeLog b/htl/ChangeLog
new file mode 100644
index 0000000..e991eac
--- /dev/null
+++ b/htl/ChangeLog
@@ -0,0 +1,6 @@
+51839d398b0f9885a17ab5c0768b8dec4dd9eb79 is the last commit imported from CVS.
+All commits after that one have valid author and committer information.
+
+Use this to examine the change log for earlier changes:
+
+    $ git show 51839d398b0f9885a17ab5c0768b8dec4dd9eb79:ChangeLog
diff --git a/htl/Makeconfig b/htl/Makeconfig
new file mode 100644
index 0000000..e90f5f7
--- /dev/null
+++ b/htl/Makeconfig
@@ -0,0 +1,13 @@
+# Makeconfig fragment for Hurd libpthread add-on.
+# This gets included at the end of the main glibc Makeconfig.
+
+have-thread-library = yes
+
+shared-thread-library = $(common-objpfx)libpthread/libpthread_nonshared.a \
+			$(common-objpfx)libpthread/libpthread.so
+static-thread-library = $(common-objpfx)libpthread/libpthread.a
+bounded-thread-library = $(static-thread-library)
+
+rpath-dirs += libpthread
+
++includes += -I$(..)libpthread/include
diff --git a/htl/Makefile b/htl/Makefile
new file mode 100644
index 0000000..2fab448
--- /dev/null
+++ b/htl/Makefile
@@ -0,0 +1,369 @@
+#
+#   Copyright (C) 1994, 1995, 1996, 1997, 2000, 2002, 2004, 2005, 2006, 2007,
+#     2008, 2011 Free Software Foundation, Inc.
+#
+#   This program is free software; you can redistribute it and/or
+#   modify it under the terms of the GNU General Public License as
+#   published by the Free Software Foundation; either version 2, or (at
+#   your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful, but
+#   WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#   General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program; if not, write to the Free Software
+#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ifeq ($(..),)
+# non-glibc build
+IN_GLIBC = no
+else
+# glibc build
+IN_GLIBC = yes
+# set elf=yes, to retain compatibility with glibc < 2.16
+ifeq ($(elf),)
+elf = yes
+endif
+endif
+
+ifeq ($(IN_GLIBC),no)
+dir := libpthread
+makemode := library
+else
+subdir := htl
+
+pthread-version := 0.3
+
+srcdir = .
+endif
+
+MICROKERNEL := mach
+SYSDEPS := lockfile
+
+LCLHDRS :=
+
+libpthread-routines := pt-attr pt-attr-destroy pt-attr-getdetachstate	    \
+	pt-attr-getguardsize pt-attr-getinheritsched			    \
+	pt-attr-getschedparam pt-attr-getschedpolicy pt-attr-getscope	    \
+	pt-attr-getstack pt-attr-getstackaddr pt-attr-getstacksize	    \
+	pt-attr-init pt-attr-setdetachstate pt-attr-setguardsize	    \
+	pt-attr-setinheritsched pt-attr-setschedparam			    \
+	pt-attr-setschedpolicy pt-attr-setscope pt-attr-setstack	    \
+	pt-attr-setstackaddr pt-attr-setstacksize			    \
+									    \
+	pt-barrier-destroy pt-barrier-init pt-barrier-wait		    \
+	pt-barrier pt-barrierattr-destroy pt-barrierattr-init		    \
+	pt-barrierattr-getpshared pt-barrierattr-setpshared		    \
+									    \
+	pt-destroy-specific pt-init-specific				    \
+	pt-key-create pt-key-delete					    \
+	pt-getspecific pt-setspecific					    \
+									    \
+	pt-once								    \
+									    \
+	pt-alloc							    \
+	pt-create							    \
+	pt-getattr							    \
+	pt-equal							    \
+	pt-dealloc							    \
+	pt-detach							    \
+	pt-exit								    \
+	pt-initialize							    \
+	pt-join								    \
+	pt-self								    \
+	pt-sigmask							    \
+	pt-spin-inlines							    \
+	pt-cleanup							    \
+	pt-setcancelstate						    \
+	pt-setcanceltype						    \
+	pt-testcancel							    \
+	pt-cancel							    \
+									    \
+	pt-mutexattr							    \
+	pt-mutexattr-destroy pt-mutexattr-init				    \
+	pt-mutexattr-getprioceiling pt-mutexattr-getprotocol		    \
+	pt-mutexattr-getpshared pt-mutexattr-gettype			    \
+	pt-mutexattr-setprioceiling pt-mutexattr-setprotocol		    \
+	pt-mutexattr-setpshared pt-mutexattr-settype			    \
+	pt-mutexattr-getrobust pt-mutexattr-setrobust			    \
+									    \
+	pt-mutex-init pt-mutex-destroy					    \
+	pt-mutex-lock pt-mutex-trylock pt-mutex-timedlock		    \
+	pt-mutex-unlock							    \
+	pt-mutex-transfer-np						    \
+	pt-mutex-getprioceiling pt-mutex-setprioceiling			    \
+	pt-mutex-consistent 						    \
+									    \
+	pt-rwlock-attr							    \
+	pt-rwlockattr-init pt-rwlockattr-destroy			    \
+	pt-rwlockattr-getpshared pt-rwlockattr-setpshared		    \
+									    \
+	pt-rwlock-init pt-rwlock-destroy				    \
+	pt-rwlock-rdlock pt-rwlock-tryrdlock				    \
+	pt-rwlock-trywrlock pt-rwlock-wrlock				    \
+	pt-rwlock-timedrdlock pt-rwlock-timedwrlock			    \
+	pt-rwlock-unlock						    \
+									    \
+	pt-cond								    \
+	pt-condattr-init pt-condattr-destroy				    \
+	pt-condattr-getclock pt-condattr-getpshared			    \
+	pt-condattr-setclock pt-condattr-setpshared			    \
+									    \
+	pt-cond-destroy pt-cond-init					    \
+	pt-cond-brdcast							    \
+	pt-cond-signal							    \
+	pt-cond-wait							    \
+	pt-cond-timedwait						    \
+	pt-hurd-cond-wait						    \
+	pt-hurd-cond-timedwait						    \
+									    \
+	pt-stack-alloc							    \
+	pt-thread-alloc							    \
+	pt-thread-start							    \
+	pt-thread-terminate						    \
+	pt-startup							    \
+									    \
+	pt-getconcurrency pt-setconcurrency				    \
+									    \
+	pt-block							    \
+	pt-timedblock							    \
+	pt-wakeup							    \
+	pt-docancel							    \
+	pt-sysdep							    \
+	pt-setup							    \
+	pt-machdep							    \
+	pt-spin								    \
+									    \
+	pt-sigstate-init						    \
+	pt-sigstate-destroy						    \
+	pt-sigstate							    \
+									    \
+	pt-atfork							    \
+	old_pt-atfork							    \
+	pt-kill								    \
+	pt-getcpuclockid						    \
+									    \
+	pt-getschedparam pt-setschedparam pt-setschedprio		    \
+	pt-yield							    \
+									    \
+	sem-close sem-destroy sem-getvalue sem-init sem-open		    \
+	sem-post sem-timedwait sem-trywait sem-unlink			    \
+	sem-wait							    \
+									    \
+	shm-directory							    \
+									    \
+	cthreads-compat							    \
+	$(SYSDEPS)
+
+libpthread-static-only-routines = pt-atfork
+
+ifeq ($(IN_GLIBC),no)
+SRCS := $(addsuffix .c,$(libpthread-routines))
+OBJS = $(addsuffix .o,$(basename $(notdir $(SRCS))))
+
+OTHERTAGS = 
+
+libname = libpthread
+endif
+
+headers :=				\
+              pthread.h				\
+              pthread/pthread.h			\
+              pthread/pthreadtypes.h		\
+	      semaphore.h			\
+						\
+              bits/pthread.h			\
+              bits/pthread-np.h			\
+              bits/pthreadtypes.h		\
+              bits/pthreadtypes-arch.h		\
+              bits/thread-shared-types.h	\
+              bits/mutex.h			\
+              bits/condition.h			\
+              bits/condition-attr.h		\
+              bits/spin-lock.h			\
+              bits/spin-lock-inline.h		\
+              bits/cancelation.h		\
+              bits/thread-attr.h		\
+              bits/barrier-attr.h		\
+              bits/barrier.h			\
+              bits/thread-specific.h		\
+              bits/once.h			\
+              bits/mutex-attr.h			\
+              bits/rwlock.h			\
+              bits/rwlock-attr.h		\
+	      bits/semaphore.h
+
+ifeq ($(IN_GLIBC),yes)
+distribute :=
+
+routines := forward libc_pthread_init alloca_cutoff
+shared-only-routines = forward
+
+vpath %.c
+
+extra-libs := libpthread
+extra-libs-others := $(extra-libs)
+install-lib := libpthread.so
+
+include ../Makeconfig
+endif
+
+SYSDEP_PATH = $(srcdir)/sysdeps/$(MICROKERNEL)/hurd/i386	\
+	 $(srcdir)/sysdeps/$(MICROKERNEL)/i386			\
+	 $(srcdir)/sysdeps/i386					\
+	 $(srcdir)/sysdeps/$(MICROKERNEL)/hurd			\
+	 $(srcdir)/sysdeps/$(MICROKERNEL)			\
+	 $(srcdir)/sysdeps/hurd					\
+	 $(srcdir)/sysdeps/generic				\
+	 $(srcdir)/sysdeps/posix				\
+	 $(srcdir)/pthread					\
+	 $(srcdir)/include
+
+VPATH += $(SYSDEP_PATH)
+
+ifeq ($(IN_GLIBC),no)
+installhdrs :=
+installhdrsubdir := .
+
+include ../Makeconf
+endif
+
+CPPFLAGS += \
+	  -DENABLE_TLS					\
+	  $(addprefix -I, $(SYSDEP_PATH))
+
+ifeq ($(IN_GLIBC),no)
+CPPFLAGS += \
+	  -imacros $(srcdir)/include/libc-symbols.h	\
+	  -imacros $(srcdir)/not-in-libc.h
+endif
+
+ifeq ($(IN_GLIBC),yes)
+CFLAGS-lockfile.c = -D_IO_MTSAFE_IO
+
+all: # Make this the default target; it will be defined in Rules.
+endif
+
+ifeq ($(IN_GLIBC),no)
+inst_libdir = $(libdir)
+endif
+
+ifeq ($(IN_GLIBC),no)
+install: install-headers
+install-headers: $(addprefix $(includedir)/, $(headers))
+
+install: $(inst_libdir)/libpthread2.a $(inst_libdir)/libpthread2_pic.a
+else
+subdir_install: $(inst_libdir)/libpthread2.a
+endif
+
+# XXX: If $(inst_libdir)/libpthread2.a is installed and
+# $(inst_libdir)/libpthread is not, we can have some issues.
+.PHONY: $(inst_libdir)/libpthread.a $(inst_libdir)/libpthread_pic.a
+
+# XXX: These rules are a hack.  But it is better than messing with
+# ../Makeconf at the moment.  Note that the linker scripts
+# $(srcdir)/libpthread.a and $(srcdir)/libpthread_pic.a get overwritten
+# when building in $(srcdir) and not a seperate build directory.
+$(inst_libdir)/libpthread2.a: $(inst_libdir)/libpthread.a
+	mv $< $@
+	$(INSTALL_DATA) $(srcdir)/libpthread.a $<
+
+$(inst_libdir)/libpthread2_pic.a: $(inst_libdir)/libpthread_pic.a
+	mv $< $@
+	$(INSTALL_DATA) $(srcdir)/libpthread_pic.a $<
+
+ifeq ($(IN_GLIBC),yes)
+libc-link.so = $(common-objpfx)libc.so
+
+extra-B-pthread.so = -B$(common-objpfx)libpthread/
+
+include ../Rules
+
+ifeq (yes,$(build-shared))
+# 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 $@
+
+$(addprefix $(objpfx), \
+  $(filter-out $(tests-static) $(xtests-static) $(tests-reverse) \
+    $(tests-nolibpthread), \
+    $(tests) $(xtests) $(test-srcs))): $(objpfx)libpthread.so \
+				       $(objpfx)libpthread_nonshared.a
+endif
+
+generated += libpthread_nonshared.a
+
+# 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: $(libc-link.so) $(common-objpfx)libc_nonshared.a \
+			$(if $(filter yes,$(elf)), $(elf-objpfx)/ld.so) \
+			$(common-objpfx)/mach/libmachuser.so \
+			$(common-objpfx)/hurd/libhurduser.so
+endif
+
+ifeq ($(IN_GLIBC),no)
+.PHONY: $(addprefix $(includedir)/, $(headers))
+
+$(addprefix $(includedir)/, $(headers)):
+	@set -e;							\
+	t="$@";								\
+	t=$${t#$(includedir)/};						\
+	header_ok=0;							\
+	for dir in $(SYSDEP_PATH);					\
+	do								\
+	  if test -e "$$dir/$$t";					\
+	  then								\
+	    tdir=`dirname "$@"`;					\
+	    if test ! -e $$tdir;					\
+	    then							\
+	      mkdir $$tdir;						\
+	    fi;								\
+	    echo $(INSTALL_DATA) "$$dir/$$t" "$@";			\
+	    $(INSTALL_DATA) "$$dir/$$t" "$@";				\
+	    header_ok=1;						\
+	    break;							\
+	  fi;								\
+	done;								\
+	if test "$${header_ok}" -ne 1;					\
+	then								\
+	  echo;								\
+	  echo '*** 'The header file \`$@\' is required, but not	\
+provided, by;								\
+	  echo '*** 'this configuration.  Please report this to the	\
+maintainer.;								\
+	  echo;								\
+	  false;							\
+	fi
+
+#  ifeq ($(VERSIONING),yes)
+#  
+#  # Adding this dependency gets it included in the command line,
+#  # where ld will read it as a linker script.
+#  $(libname).so.$(hurd-version): $(srcdir)/$(libname).map
+#  
+#  endif
+endif
diff --git a/htl/TODO b/htl/TODO
new file mode 100644
index 0000000..979c38c
--- /dev/null
+++ b/htl/TODO
@@ -0,0 +1,131 @@
+-*- Mode: outline -*-
+
+* Interfaces
+** All interfaces specified by IEEE Std 1003.1-2001 are present, however,
+   pthread_kill and pthread_sigmask are defined in <pthread.h> and not
+   <signal.h> as they should be.  Once we are compiled with glibc,
+   this should be eaiser.
+
+* Test cases.  Can never have enough.
+
+* Ports
+  Port to other kernels (e.g. Linux and FreeBSD) and test on other
+  platforms.
+
+* Implementation details
+** pthread_atfork
+   This cannot be implemented without either changing glibc to export
+   some hooks (c.f. libc/sysdeps/mach/hurd/fork.c) or by providing a
+   custom fork implementation that wraps the origial using dlopen et
+   al.
+
+** Scheduling and priorities
+
+   We do not support scheduling right now in any way what so ever.
+
+   This affects:
+     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_mutexattr_getprioceiling
+     pthread_mutexattr_setprioceiling
+     pthread_mutexattr_getprotocol
+     pthread_mutexattr_setprotocol
+     pthread_mutex_getprioceiling
+     pthread_mutex_setprioceiling
+
+     pthread_setschedprio
+     pthread_getschedparam
+     pthread_setschedparam
+
+** Cancelation
+*** Cancelation points
+    The only cancelation points are pthread_join, pthread_cond_wait,
+    pthead_cond_timedwait and pthread_testcancel.  Need to explore if
+    the hurd_sigstate->cancel_hook (c.f. <hurd/signal.h>) provides the
+    desired semantics.  If not, must either wrap the some functions
+    using dlsym or wait until integration with glibc.
+*** Async cancelation
+    We inject a new IP into the cancelled (running) thread and then
+    run the cancelation handlers
+    (c.f. sysdeps/mach/hurd/pt-docancel.c).  The handlers need to have
+    access to the stack as they may use local variables.  I think that
+    this method may leave the frame pointer in a corrupted state if
+    the thread was in, for instance, the middle of a function call.
+    The robustness needs to be confirmed.
+
+** Process Shared Attribute
+
+   Currently, there is no real support for the process shared
+   attribute.  spinlocks work because we just use a test and set loop,
+   however, barriers, conditions mutexes and rwlocks, however, signal
+   wakeups via ports of which the names are process local.
+
+   We could have some process local data that is hashed to via the
+   address of the data structure.  Then the first thread that blocks
+   per process would spin on the shared memory area and all others
+   would then block as normal.  When the resource became available,
+   the first thread would signal the other local threads as necessary.
+   Alternatively, there could be some server, however, this opens a
+   new question: what can we use as an authentication agent.
+
+** Locking algorithm
+
+   When a thread blocks, it puts itself on a queue and then waits for
+   a message on a thread local port.  The thread which eventually does
+   the wakeup sends a message to the waiter thereby waking it up.  If
+   the wakeup is a broadcast wakeup (e.g. pthread_cond_broadcast,
+   pthread_barrier_wait and pthread_rdlock_unlock), the thread must
+   send O(N) messages where N is the number of waiting threads.  If
+   all the threads instead received on a lock local (rather than
+   thread local) port then the thread which eventually does the wake
+   need just do one operation, mach_port_destroy and all of the
+   waiting threads would wakeup and get MACH_RCV_PORT_DIED back from
+   mach_msg.  Note that the trade off is that the port must be
+   recreated.  This needs to be benchmarked.
+
+   A possible problem with this is scheduling priorities.  There may
+   be a preference for certain threads to wakeup before others
+   (especially if we are not doing a broadcast, for instance,
+   pthread_mutex_unlock and pthread_cond_signal).  If we take this
+   approach, the kernel chooses which threads are awakened.  If we
+   find that the kernel makes the wrong choices, we can still overcome
+   this by merging the two algorithms: have a list of ports sorted in
+   priority order and the waker does a mach_port_destroy on each as
+   appropriate.
+
+** Barriers
+
+   Barriers can be very slow and the contention can be very high.  The
+   above algorithm is very appealing, however, this may be augmented
+   with an initial number of spins and yields.  It is expected that
+   all of the threads reach the barrier within close succession, thus
+   queuing a message may be more expensive.  This needs to be
+   benchmarked.
+
+** Clocks
+*** pthread_condattr_setclock allows a process to specify a clock for
+    use with pthread_cond_timedwaits.  What is the correct default for
+    this, right now, we use CLOCK_REALTIME, however, we are really
+    using the system clock which, if I understand correctly, is
+    completely different.
+*** Could we even use other clocks? mach_msg uses a relative time against
+    the system clock.
+*** pthread_getcpuclockid just returns CLOCK_THREAD_CPUTIME_ID if defined.
+    Is this the correct behavior?
+
+** Timed Blocking
+*** pthread_cond_timedwait, pthead_mutex_timedlock, pthread_rwlock_timedrdlock
+    and pthread_rwlock_timedwrlock all take absolute times.  We need
+    to convert them to relative times for mach_msg.  Is there a way
+    around this?  How will clock skew affect us?
+
+** weak aliases
+   Use them consistently and correctly and start by reading
+   http://sources.redhat.com/ml/libc-alpha/2002-08/msg00278.html.
diff --git a/htl/Versions b/htl/Versions
new file mode 100644
index 0000000..67c6032
--- /dev/null
+++ b/htl/Versions
@@ -0,0 +1,155 @@
+libc {
+  GLIBC_2.13 {
+    pthread_attr_destroy; pthread_attr_getdetachstate;
+    pthread_attr_getinheritsched; pthread_attr_getschedparam;
+    pthread_attr_getschedpolicy; pthread_attr_getscope; pthread_attr_init;
+    pthread_attr_setdetachstate; pthread_attr_setinheritsched;
+    pthread_attr_setschedparam; pthread_attr_setschedpolicy;
+    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_trylock; pthread_mutex_unlock;
+    pthread_self; pthread_setcancelstate; pthread_setcanceltype;
+    __pthread_get_cleanup_stack;
+  }
+  GLIBC_2.22 {
+    __register_atfork;
+  }
+  GLIBC_PRIVATE {
+    __libc_alloca_cutoff;
+    __libc_pthread_init;
+  }
+}
+
+libpthread {
+  GLIBC_2.2.6 {
+    _IO_flockfile; _IO_ftrylockfile; _IO_funlockfile;
+  }
+  GLIBC_2.12 {
+    __pthread_errorcheck_mutexattr; __pthread_recursive_mutexattr;
+
+    __pthread_get_cleanup_stack;
+
+    __pthread_mutex_transfer_np;
+
+    _pthread_mutex_destroy; _pthread_mutex_init;
+    _pthread_mutex_lock; _pthread_mutex_trylock; _pthread_mutex_unlock;
+    _pthread_rwlock_destroy; _pthread_rwlock_init;
+
+    _cthread_init_routine;
+
+    cthread_detach;
+    cthread_fork;
+    cthread_keycreate;
+    cthread_getspecific;
+    cthread_setspecific;
+    __mutex_lock_solid;
+    __mutex_unlock_solid;
+    _cthreads_flockfile;
+    _cthreads_ftrylockfile;
+    _cthreads_funlockfile;
+
+    flockfile; ftrylockfile; funlockfile;
+
+    pthread_atfork;
+
+    pthread_attr_destroy; pthread_attr_getdetachstate;
+    pthread_attr_getguardsize; pthread_attr_getinheritsched;
+    pthread_attr_getschedparam; pthread_attr_getschedpolicy;
+    pthread_attr_getscope; pthread_attr_getstack; pthread_attr_getstackaddr;
+    pthread_attr_getstacksize; pthread_attr_init; pthread_attr_setdetachstate;
+    pthread_attr_setguardsize; pthread_attr_setinheritsched;
+    pthread_attr_setschedparam; pthread_attr_setschedpolicy;
+    pthread_attr_setscope; pthread_attr_setstack; pthread_attr_setstackaddr;
+    pthread_attr_setstacksize;
+
+    pthread_barrier_destroy; pthread_barrier_init; pthread_barrier_wait;
+    pthread_barrierattr_destroy; pthread_barrierattr_getpshared;
+    pthread_barrierattr_init; pthread_barrierattr_setpshared;
+
+    pthread_cancel;
+
+    pthread_cond_broadcast; pthread_cond_destroy; pthread_cond_init;
+    pthread_cond_signal; pthread_cond_timedwait; pthread_cond_wait;
+
+    pthread_condattr_destroy; pthread_condattr_getclock;
+    pthread_condattr_getpshared; pthread_condattr_init;
+    pthread_condattr_setclock; pthread_condattr_setpshared;
+
+    pthread_create; pthread_detach; pthread_equal; pthread_exit;
+
+    pthread_getattr_np;
+
+    pthread_getconcurrency; pthread_getcpuclockid;
+    pthread_getschedparam; pthread_getspecific;
+
+    pthread_join;
+
+    pthread_key_create; pthread_key_delete;
+    __pthread_key_create;
+
+    pthread_kill;
+    __pthread_kill;
+
+    pthread_mutex_destroy; pthread_mutex_getprioceiling;
+    pthread_mutex_init; pthread_mutex_lock; pthread_mutex_setprioceiling;
+    pthread_mutex_timedlock; pthread_mutex_transfer_np;
+    pthread_mutex_trylock; pthread_mutex_unlock;
+
+    pthread_mutexattr_destroy; pthread_mutexattr_getprioceiling;
+    pthread_mutexattr_getprotocol; pthread_mutexattr_getpshared;
+    pthread_mutexattr_gettype; pthread_mutexattr_init;
+    pthread_mutexattr_setprioceiling; pthread_mutexattr_setprotocol;
+    pthread_mutexattr_setpshared; pthread_mutexattr_settype;
+
+    pthread_once;
+
+    pthread_rwlock_destroy; pthread_rwlock_init; pthread_rwlock_rdlock;
+    pthread_rwlock_timedrdlock; pthread_rwlock_timedwrlock;
+    pthread_rwlock_tryrdlock; pthread_rwlock_trywrlock;
+    pthread_rwlock_unlock; pthread_rwlock_wrlock;
+
+    pthread_rwlockattr_destroy; pthread_rwlockattr_getpshared;
+    pthread_rwlockattr_init; pthread_rwlockattr_setpshared;
+
+    pthread_self;
+
+    pthread_setcancelstate; pthread_setcanceltype;
+    pthread_setconcurrency; pthread_setschedparam;
+    pthread_setschedprio; pthread_setspecific;
+
+    pthread_sigmask;
+    pthread_testcancel;
+    pthread_yield;
+
+    sem_close; sem_destroy; sem_getvalue; sem_init; sem_open; sem_post;
+    sem_timedwait; sem_trywait; sem_unlink; sem_wait;
+
+    pthread_spin_destroy; pthread_spin_init; pthread_spin_lock;
+    pthread_spin_trylock; pthread_spin_unlock;
+    __pthread_spin_destroy; __pthread_spin_init;
+    __pthread_spin_lock; __pthread_spin_trylock; __pthread_spin_unlock;
+    _pthread_spin_lock;
+  }
+  GLIBC_2.17 {
+    pthread_hurd_cond_wait_np;
+    pthread_hurd_cond_timedwait_np;
+  }
+  GLIBC_PRIVATE {
+    __shm_directory;
+    __pthread_threads;
+
+    __cthread_detach;
+    __cthread_fork;
+    __cthread_keycreate;
+    __cthread_getspecific;
+    __cthread_setspecific;
+    __pthread_getattr_np;
+    __pthread_attr_getstack;
+  }
+}
diff --git a/htl/configure b/htl/configure
new file mode 100644
index 0000000..5983490
--- /dev/null
+++ b/htl/configure
@@ -0,0 +1,2 @@
+libc_add_on_canonical=libpthread
+libc_add_on_subdirs=.
diff --git a/htl/configure.in b/htl/configure.in
new file mode 100644
index 0000000..4e140b1
--- /dev/null
+++ b/htl/configure.in
@@ -0,0 +1,4 @@
+GLIBC_PROVIDES
+
+libc_add_on_canonical=libpthread
+libc_add_on_subdirs=.
diff --git a/htl/forward.c b/htl/forward.c
new file mode 100644
index 0000000..0ee84a0
--- /dev/null
+++ b/htl/forward.c
@@ -0,0 +1,281 @@
+/* Copyright (C) 2002, 2003, 2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with 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 <dlfcn.h>
+#include <stdlib.h>
+#include <shlib-compat.h>
+#include <pthread-functions.h>
+#include <fork.h>
+
+/* Pointers to the libc functions.  */
+struct pthread_functions __libc_pthread_functions attribute_hidden;
+int __libc_pthread_functions_init attribute_hidden;
+
+
+# define FORWARD2(name, rettype, decl, params, defaction) \
+rettype									      \
+name decl								      \
+{									      \
+  if (!__libc_pthread_functions_init)			      \
+    defaction;								      \
+									      \
+  return PTHFCT_CALL (ptr_##name, params);			      \
+}
+
+/* Same as FORWARD2, only without return.  */
+# define FORWARD_NORETURN(name, rettype, decl, params, defaction) \
+rettype									      \
+name decl								      \
+{									      \
+  if (!__libc_pthread_functions_init)			      \
+    defaction;								      \
+									      \
+  PTHFCT_CALL (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)
+
+FORWARD (pthread_attr_init, (pthread_attr_t *attr), (attr), 0)
+
+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)
+
+
+FORWARD (pthread_cond_broadcast, (pthread_cond_t *cond), (cond), 0)
+FORWARD (pthread_cond_destroy, (pthread_cond_t *cond), (cond), 0)
+FORWARD (pthread_cond_init,
+	 (pthread_cond_t *cond, const pthread_condattr_t *cond_attr),
+	 (cond, cond_attr), 0)
+FORWARD (pthread_cond_signal, (pthread_cond_t *cond), (cond), 0)
+FORWARD (pthread_cond_wait, (pthread_cond_t *cond, pthread_mutex_t *mutex),
+	 (cond, mutex), 0)
+FORWARD (pthread_cond_timedwait,
+	 (pthread_cond_t *cond, pthread_mutex_t *mutex,
+	  const struct timespec *abstime), (cond, mutex, abstime), 0)
+
+FORWARD (pthread_equal, (pthread_t thread1, pthread_t thread2),
+	 (thread1, thread2), 1)
+
+
+/* Use an alias to avoid warning, as pthread_exit is declared noreturn.  */
+FORWARD_NORETURN (__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)
+strong_alias (__pthread_setcancelstate, pthread_setcancelstate);
+
+FORWARD (pthread_setcanceltype, (int type, int *oldtype), (type, oldtype), 0)
+
+struct __pthread_cancelation_handler *dummy_list;
+FORWARD2 (__pthread_get_cleanup_stack, struct __pthread_cancelation_handler **, (void), (), return &dummy_list);
+
+
+/* Fork interaction */
+
+struct atfork {
+  void (*prepare) (void);
+  void (*parent) (void);
+  void (*child) (void);
+  void *dso_handle;
+  struct atfork *prev;
+  struct atfork *next;
+};
+
+/* TODO: better locking */
+static struct mutex atfork_lock;
+static struct atfork *fork_handlers, *fork_last_handler;
+
+static void
+atfork_pthread_prepare (void)
+{
+  struct atfork *handlers, *last_handler;
+
+  __mutex_lock (&atfork_lock);
+  handlers = fork_handlers;
+  last_handler = fork_last_handler;
+  __mutex_unlock (&atfork_lock);
+
+  if (!last_handler)
+    return;
+
+  while(1)
+    {
+      if (last_handler->prepare != NULL)
+	last_handler->prepare ();
+      if (last_handler == handlers)
+	break;
+      last_handler = last_handler->prev;
+    }
+}
+text_set_element (_hurd_atfork_prepare_hook, atfork_pthread_prepare);
+
+static void
+atfork_pthread_parent (void)
+{
+  struct atfork *handlers;
+
+  __mutex_lock (&atfork_lock);
+  handlers = fork_handlers;
+  __mutex_unlock (&atfork_lock);
+
+  while (handlers)
+    {
+      if (handlers->parent != NULL)
+	handlers->parent ();
+      handlers = handlers->next;
+    }
+}
+text_set_element (_hurd_atfork_parent_hook, atfork_pthread_parent);
+
+static void
+atfork_pthread_child (void)
+{
+  struct atfork *handlers;
+
+  __mutex_lock (&atfork_lock);
+  handlers = fork_handlers;
+  __mutex_unlock (&atfork_lock);
+
+  while (handlers)
+    {
+      if (handlers->child != NULL)
+	handlers->child ();
+      handlers = handlers->next;
+    }
+}
+text_set_element (_hurd_atfork_child_hook, atfork_pthread_child);
+
+int
+__register_atfork (
+    void (*prepare) (void),
+    void (*parent) (void),
+    void (*child) (void),
+    void *dso_handle)
+{
+  struct atfork *new = malloc (sizeof (*new));
+  if (!new)
+    return errno;
+
+  new->prepare = prepare;
+  new->parent = parent;
+  new->child = child;
+  new->dso_handle = dso_handle;
+  new->prev = NULL;
+
+  __mutex_lock (&atfork_lock);
+  new->next = fork_handlers;
+  if (fork_handlers)
+    fork_handlers->prev = new;
+  fork_handlers = new;
+  if (!fork_last_handler)
+    fork_last_handler = new;
+  __mutex_unlock (&atfork_lock);
+
+  return 0;
+}
+libc_hidden_def (__register_atfork)
+
+void
+__unregister_atfork (void *dso_handle)
+{
+  struct atfork **handlers, *prev = NULL, *next;
+  __mutex_lock (&atfork_lock);
+  handlers = &fork_handlers;
+  while (*handlers)
+    {
+      if ((*handlers)->dso_handle == dso_handle)
+	{
+	  /* Drop this handler from the list.  */
+	  if (*handlers == fork_last_handler)
+	    {
+	      /* Was last, new last is prev, if any.  */
+	      fork_last_handler = prev;
+	    }
+
+	  next = (*handlers)->next;
+	  if (next)
+	    next->prev = prev;
+	  *handlers = next;
+	}
+      else
+	{
+	  /* Just proceed to next handler.  */
+	  prev = *handlers;
+	  handlers = &prev->next;
+	}
+    }
+  __mutex_unlock (&atfork_lock);
+}
diff --git a/htl/libc_pthread_init.c b/htl/libc_pthread_init.c
new file mode 100644
index 0000000..eb6f41b
--- /dev/null
+++ b/htl/libc_pthread_init.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 2002 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 <string.h>
+#include <pthread-functions.h>
+
+void
+__libc_pthread_init (const struct pthread_functions *functions)
+{
+#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));
+  __libc_pthread_functions_init = 1;
+#endif
+}
diff --git a/htl/libpthread.a b/htl/libpthread.a
new file mode 100644
index 0000000..e5bd2cc
--- /dev/null
+++ b/htl/libpthread.a
@@ -0,0 +1,22 @@
+/* pthread initializer is weak in glibc.  It must be included if glibc
+   is to start threading. */
+EXTERN(_cthread_init_routine)
+
+/* Weak references in glibc that must be filled if glibc is to be
+   thread safe.  */
+EXTERN(cthread_detach)
+EXTERN(cthread_fork)
+EXTERN(cthread_keycreate)
+EXTERN(cthread_getspecific)
+EXTERN(cthread_setspecific)
+EXTERN(__mutex_lock_solid)
+EXTERN(__mutex_unlock_solid)
+/* For libio stream locking.  */
+EXTERN(_cthreads_flockfile)
+EXTERN(_cthreads_funlockfile)
+EXTERN(_cthreads_ftrylockfile)
+/* To get the sigthread stack layout on fork */
+EXTERN(pthread_getattr_np)
+EXTERN(pthread_attr_getstack)
+
+GROUP(-lpthread2 -lrt)
diff --git a/htl/libpthread_pic.a b/htl/libpthread_pic.a
new file mode 100644
index 0000000..33346b4
--- /dev/null
+++ b/htl/libpthread_pic.a
@@ -0,0 +1,22 @@
+/* pthread initializer is weak in glibc.  It must be included if glibc
+   is to start threading. */
+EXTERN(_cthread_init_routine)
+
+/* Weak references in glibc that must be filled if glibc is to be
+   thread safe.  */
+EXTERN(cthread_detach)
+EXTERN(cthread_fork)
+EXTERN(cthread_keycreate)
+EXTERN(cthread_getspecific)
+EXTERN(cthread_setspecific)
+EXTERN(__mutex_lock_solid)
+EXTERN(__mutex_unlock_solid)
+/* For libio stream locking.  */
+EXTERN(_cthreads_flockfile)
+EXTERN(_cthreads_funlockfile)
+EXTERN(_cthreads_ftrylockfile)
+/* To get the sigthread stack layout on fork */
+EXTERN(pthread_getattr_np)
+EXTERN(pthread_attr_getstack)
+
+GROUP(-lpthread2_pic)
diff --git a/htl/lockfile.c b/htl/lockfile.c
new file mode 100644
index 0000000..040cbfb
--- /dev/null
+++ b/htl/lockfile.c
@@ -0,0 +1,65 @@
+/* lockfile - Handle locking and unlocking of streams.  Hurd cthreads version.
+   Copyright (C) 2000,01,02 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 <cthreads.h>
+#include <pthread.h>		/* Must come before <stdio.h>! */
+#include <stdio.h>
+
+#ifdef _STDIO_USES_IOSTREAM
+
+void
+_cthreads_flockfile (_IO_FILE *fp)
+{
+  _IO_lock_lock (*fp->_lock);
+}
+
+void
+_cthreads_funlockfile (_IO_FILE *fp)
+{
+  _IO_lock_unlock (*fp->_lock);
+}
+
+int
+_cthreads_ftrylockfile (_IO_FILE *fp)
+{
+  return __libc_lock_trylock_recursive (*fp->_lock);
+}
+
+# undef 	_IO_flockfile
+# undef 	_IO_funlockfile
+# undef 	_IO_ftrylockfile
+# undef		flockfile
+# undef		funlockfile
+# undef		ftrylockfile
+
+void _IO_flockfile (_IO_FILE *)
+     __attribute__ ((alias ("_cthreads_flockfile")));
+void _IO_funlockfile (_IO_FILE *)
+     __attribute__ ((alias ("_cthreads_funlockfile")));
+int _IO_ftrylockfile (_IO_FILE *)
+     __attribute__ ((alias ("_cthreads_ftrylockfile")));
+
+void flockfile (_IO_FILE *)
+     __attribute__ ((alias ("_cthreads_flockfile")));
+void funlockfile (_IO_FILE *)
+     __attribute__ ((alias ("_cthreads_funlockfile")));
+int ftrylockfile (_IO_FILE *)
+     __attribute__ ((alias ("_cthreads_ftrylockfile")));
+
+#endif /* _STDIO_USES_IOSTREAM */
diff --git a/htl/not-in-libc.h b/htl/not-in-libc.h
new file mode 100644
index 0000000..7c5f0bc
--- /dev/null
+++ b/htl/not-in-libc.h
@@ -0,0 +1,12 @@
+#define __mach_port_insert_right mach_port_insert_right
+#define __mach_port_allocate	mach_port_allocate
+#define __mig_init		mig_init
+#define __thread_create		thread_create
+#define __thread_get_state	thread_get_state
+#define __thread_resume		thread_resume
+#define __thread_set_state	thread_set_state
+#define __thread_terminate	thread_terminate
+#define __thread_terminate_release	thread_terminate_release
+#define __vm_allocate		vm_allocate
+#define __vm_deallocate		vm_deallocate
+#define __sched_yield           sched_yield
diff --git a/htl/pthread/alloca_cutoff.c b/htl/pthread/alloca_cutoff.c
new file mode 100644
index 0000000..ec54d8f
--- /dev/null
+++ b/htl/pthread/alloca_cutoff.c
@@ -0,0 +1,27 @@
+/* Allocate a new thread structure.
+   Copyright (C) 2015-2016 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 <alloca.h>
+
+int
+__libc_alloca_cutoff (size_t size)
+{
+	return size <= 65536;
+}
+libc_hidden_def (__libc_alloca_cutoff)
diff --git a/htl/pthread/cthreads-compat.c b/htl/pthread/cthreads-compat.c
new file mode 100644
index 0000000..cd845ed
--- /dev/null
+++ b/htl/pthread/cthreads-compat.c
@@ -0,0 +1,102 @@
+/* Compatibility routines for cthreads.
+   Copyright (C) 2000, 2002, 2008 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 <assert.h>
+#include <pthread.h>
+
+#define	CTHREAD_KEY_INVALID (__cthread_key_t) -1
+
+void
+__cthread_detach (__cthread_t thread)
+{
+  int err;
+
+  err = pthread_detach ((pthread_t) thread);
+  assert_perror (err);
+}
+weak_alias (__cthread_detach, cthread_detach)
+
+__cthread_t
+__cthread_fork (__cthread_fn_t func, void *arg)
+{
+  pthread_t thread;
+  int err;
+
+  err = pthread_create (&thread, NULL, func, arg);
+  assert_perror (err);
+
+  return (__cthread_t) thread;
+}
+weak_alias (__cthread_fork, cthread_fork)
+
+int
+__cthread_keycreate (__cthread_key_t *key)
+{
+  error_t err;
+
+  err = pthread_key_create (key, 0);
+  if (err)
+    {
+      errno = err;
+      *key = CTHREAD_KEY_INVALID;
+      err = -1;
+    }
+
+  return err;
+}
+weak_alias (__cthread_keycreate, cthread_keycreate)
+
+int
+__cthread_getspecific (__cthread_key_t key, void **val)
+{
+  *val = pthread_getspecific (key);
+  return 0;
+}
+weak_alias (__cthread_getspecific, cthread_getspecific)
+
+int
+__cthread_setspecific (__cthread_key_t key, void *val)
+{
+  error_t err;
+
+  err = pthread_setspecific (key, (const void *) val);
+  if (err)
+    {
+      errno = err;
+      err = -1;
+    }
+
+  return err;
+}
+weak_alias (__cthread_setspecific, cthread_setspecific)
+
+void
+__mutex_lock_solid (void *lock)
+{
+  __pthread_mutex_lock (lock);
+}
+
+void
+__mutex_unlock_solid (void *lock)
+{
+  if (__pthread_spin_trylock (lock) != 0)
+    /* Somebody already got the lock, that one will manage waking up others */
+    return;
+  __pthread_mutex_unlock (lock);
+}
diff --git a/htl/pthread/pt-alloc.c b/htl/pthread/pt-alloc.c
new file mode 100644
index 0000000..21063d5
--- /dev/null
+++ b/htl/pthread/pt-alloc.c
@@ -0,0 +1,219 @@
+/* Allocate a new thread structure.
+   Copyright (C) 2000, 2002, 2005, 2007, 2008 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 <assert.h>
+#include <errno.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <pt-internal.h>
+
+/* This braindamage is necessary because the standard says that some
+   of the threads functions "shall fail" if "No thread could be found
+   corresponding to that specified by the given thread ID."  */
+   
+/* Thread ID lookup table.  */
+struct __pthread **__pthread_threads;
+
+/* The size of the thread ID lookup table.  */
+int __pthread_max_threads;
+
+/* The total number of thread IDs currently in use, or on the list of
+   available thread IDs.  */
+int __pthread_num_threads;
+
+/* A lock for the table, and the other variables above.  */
+pthread_rwlock_t __pthread_threads_lock;
+
+/* List of thread structures corresponding to free thread IDs.  */
+struct __pthread *__pthread_free_threads;
+pthread_mutex_t __pthread_free_threads_lock;
+
+static inline error_t
+initialize_pthread (struct __pthread *new)
+{
+  error_t err;
+
+  err = __pthread_init_specific (new);
+  if (err)
+    return err;
+
+  new->nr_refs = 1;
+  new->cancel_lock = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER;
+  new->cancel_hook = NULL;
+  new->cancel_hook_arg = NULL;
+  new->cancel_state = PTHREAD_CANCEL_ENABLE;
+  new->cancel_type = PTHREAD_CANCEL_DEFERRED;
+  new->cancel_pending = 0;
+
+  new->state_lock = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER;
+  new->state_cond = (pthread_cond_t) PTHREAD_COND_INITIALIZER;
+
+  new->cancelation_handlers = 0;
+
+  memset (&new->res_state, '\0', sizeof (new->res_state));
+
+#ifdef ENABLE_TLS
+  new->tcb = NULL;
+#endif
+
+  new->next = 0;
+  new->prevp = 0;
+
+  return 0;
+}
+
+
+/* Allocate a new thread structure and its pthread thread ID (but not
+   a kernel thread).  */
+int
+__pthread_alloc (struct __pthread **pthread)
+{
+  error_t err;
+
+  struct __pthread *new;
+  struct __pthread **threads;
+  struct __pthread **old_threads;
+  int max_threads;
+  int new_max_threads;
+
+  pthread_mutex_lock (&__pthread_free_threads_lock);
+  for (new = __pthread_free_threads; new; new = new->next)
+    {
+      /* There is no need to take NEW->STATE_LOCK: if NEW is on this
+	 list, then it is protected by __PTHREAD_FREE_THREADS_LOCK
+	 except in __pthread_dealloc where after it is added to the
+	 list (with the lock held), it drops the lock and then sets
+	 NEW->STATE and immediately stops using NEW.  */
+      if (new->state == PTHREAD_TERMINATED)
+	{
+	  __pthread_dequeue (new);
+	  break;
+	}
+    }
+  pthread_mutex_unlock (&__pthread_free_threads_lock);
+
+  if (new)
+    {
+#ifdef ENABLE_TLS
+      if (new->tcb)
+	{
+	  /* Drop old values */
+	  _dl_deallocate_tls (new->tcb, 1);
+	}
+#endif /* ENABLE_TLS */
+
+      err = initialize_pthread (new);
+      if (! err)
+	*pthread = new;
+      return err;
+    }
+
+  /* Allocate a new thread structure.  */
+  new = malloc (sizeof (struct __pthread));
+  if (new == NULL)
+    return ENOMEM;
+
+  err = initialize_pthread (new);
+  if (err)
+    {
+      free (new);
+      return err;
+    }
+
+ retry:
+  __pthread_rwlock_wrlock (&__pthread_threads_lock);
+
+  if (__pthread_num_threads < __pthread_max_threads)
+    {
+      /* We have a free slot.  Use the slot number plus one as the
+         thread ID for the new thread.  */
+      new->thread = 1 + __pthread_num_threads++;
+      __pthread_threads[new->thread - 1] = NULL;
+
+      __pthread_rwlock_unlock (&__pthread_threads_lock);
+
+      *pthread = new;
+      return 0;
+    }
+#ifdef PTHREAD_THREADS_MAX
+  else if (__pthread_num_threads >= PTHREAD_THREADS_MAX)
+    {
+      /* We have reached the limit on the number of threads per process.  */
+      __pthread_rwlock_unlock (&__pthread_threads_lock);
+
+      free (new);
+      return EAGAIN;
+    }
+#endif
+
+  /* We are going to enlarge the threads table.  Save its current
+     size.  We're going to release the lock before doing the necessary
+     memory allocation, since that's a potentially blocking operation.  */
+  max_threads = __pthread_max_threads;
+
+  __pthread_rwlock_unlock (&__pthread_threads_lock);
+
+  /* Allocate a new lookup table that's twice as large.  */
+  new_max_threads
+    = max_threads > 0 ? max_threads * 2 : _POSIX_THREAD_THREADS_MAX;
+  threads = malloc (new_max_threads * sizeof (struct __pthread *));
+  if (threads == NULL)
+    {
+      free (new);
+      return ENOMEM;
+    }
+
+  __pthread_rwlock_wrlock (&__pthread_threads_lock);
+
+  /* Check if nobody else has already enlarged the table.  */
+  if (max_threads != __pthread_max_threads)
+    {
+      /* Yep, they did.  */
+      __pthread_rwlock_unlock (&__pthread_threads_lock);
+
+      /* Free the newly allocated table and try again to allocate a slot.  */
+      free (threads);
+      goto retry;
+    }
+
+  /* Copy over the contents of the old table.  */
+  memcpy (threads, __pthread_threads,
+	  __pthread_max_threads * sizeof (struct __pthread *));
+
+  /* Save the location of the old table.  We want to deallocate its
+     storage after we released the lock.  */
+  old_threads = __pthread_threads;
+
+  /* Replace the table with the new one.  */
+  __pthread_max_threads = new_max_threads;
+  __pthread_threads = threads;
+
+  /* And allocate ourselves one of the newly created slots.  */
+  new->thread = 1 + __pthread_num_threads++;
+  __pthread_threads[new->thread - 1] = NULL;
+
+  __pthread_rwlock_unlock (&__pthread_threads_lock);
+
+  free (old_threads);
+
+  *pthread = new;
+  return 0;
+}
diff --git a/htl/pthread/pt-cancel.c b/htl/pthread/pt-cancel.c
new file mode 100644
index 0000000..96c77f7
--- /dev/null
+++ b/htl/pthread/pt-cancel.c
@@ -0,0 +1,63 @@
+/* Cancel a thread.
+   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.  */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+int
+pthread_cancel (pthread_t t)
+{
+  int err = 0;
+  struct __pthread *p;
+
+  p = __pthread_getid (t);
+  if (! p)
+    return ESRCH;
+
+  __pthread_mutex_lock (&p->cancel_lock);
+  if (p->cancel_pending)
+    {
+      __pthread_mutex_unlock (&p->cancel_lock);
+      return 0;
+    }
+
+  p->cancel_pending = 1;
+
+  if (p->cancel_state != PTHREAD_CANCEL_ENABLE)
+    {
+      __pthread_mutex_unlock (&p->cancel_lock);
+      return 0;
+    }
+
+  if (p->cancel_type == PTHREAD_CANCEL_ASYNCHRONOUS)
+    /* CANCEL_LOCK is unlocked by this call.  */
+    err = __pthread_do_cancel (p);
+  else
+    {
+      if (p->cancel_hook != NULL)
+	/* Thread blocking on a cancellation point.  Invoke hook to unblock.
+	   See __pthread_cond_timedwait_internal.  */
+	p->cancel_hook (p->cancel_hook_arg);
+
+      __pthread_mutex_unlock (&p->cancel_lock);
+    }
+
+  return err;
+}
diff --git a/htl/pthread/pt-cleanup.c b/htl/pthread/pt-cleanup.c
new file mode 100644
index 0000000..58865aa
--- /dev/null
+++ b/htl/pthread/pt-cleanup.c
@@ -0,0 +1,28 @@
+/* Add a cancelation handler to the stack.
+   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.  */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+struct __pthread_cancelation_handler **
+__pthread_get_cleanup_stack (void)
+{
+  return &_pthread_self ()->cancelation_handlers;
+}
diff --git a/htl/pthread/pt-create.c b/htl/pthread/pt-create.c
new file mode 100644
index 0000000..c9e0730
--- /dev/null
+++ b/htl/pthread/pt-create.c
@@ -0,0 +1,254 @@
+/* Thread creation.
+   Copyright (C) 2000, 2002, 2005, 2007 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 <assert.h>
+#include <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <resolv.h>
+
+#include <bits/pt-atomic.h>
+#include <hurd/resource.h>
+
+#include <pt-internal.h>
+
+#if IS_IN (libpthread)
+# include <ctype.h>
+#endif
+#ifdef HAVE_USELOCALE
+# include <locale.h>
+#endif
+
+/* The total number of pthreads currently active.  This is defined
+   here since it would be really stupid to have a threads-using
+   program that doesn't call `pthread_create'.  */
+__atomic_t __pthread_total;
+
+
+/* The entry-point for new threads.  */
+static void
+entry_point (struct __pthread *self, void *(*start_routine)(void *), void *arg)
+{
+#ifdef ENABLE_TLS
+  ___pthread_self = self;
+  __resp = &self->res_state;
+#endif
+
+#if IS_IN (libpthread)
+  /* Initialize pointers to locale data.  */
+  __ctype_init ();
+#endif
+#ifdef HAVE_USELOCALE
+  /* A fresh thread needs to be bound to the global locale.  */
+  uselocale (LC_GLOBAL_LOCALE);
+#endif
+
+  __pthread_startup ();
+
+  pthread_exit (start_routine (arg));
+}
+
+/* Create a thread with attributes given by ATTR, executing
+   START_ROUTINE with argument ARG.  */
+int
+pthread_create (pthread_t *thread, const pthread_attr_t *attr,
+		void *(*start_routine)(void *), void *arg)
+{
+  int err;
+  struct __pthread *pthread;
+
+  err = __pthread_create_internal (&pthread, attr, start_routine, arg);
+  if (! err)
+    *thread = pthread->thread;
+  else if (err == ENOMEM)
+    err = EAGAIN;
+
+  return err;
+}
+
+/* Internal version of pthread_create.  See comment in
+   pt-internal.h.  */
+int
+__pthread_create_internal (struct __pthread **thread,
+			   const pthread_attr_t *attr,
+			   void *(*start_routine)(void *), void *arg)
+{
+  int err;
+  struct __pthread *pthread;
+  const struct __pthread_attr *setup;
+  sigset_t sigset;
+  size_t stacksize;
+
+  /* Allocate a new thread structure.  */
+  err = __pthread_alloc (&pthread);
+  if (err)
+    goto failed;
+
+  /* Use the default attributes if ATTR is NULL.  */
+  setup = attr ? attr : &__pthread_default_attr;
+
+  stacksize = setup->__stacksize;
+  if (!stacksize)
+    {
+      struct rlimit rlim;
+      __getrlimit(RLIMIT_STACK, &rlim);
+      if (rlim.rlim_cur != RLIM_INFINITY)
+	stacksize = rlim.rlim_cur;
+      if (!stacksize)
+	stacksize = PTHREAD_STACK_DEFAULT;
+    }
+
+  /* Initialize the thread state.  */
+  pthread->state = (setup->__detachstate == PTHREAD_CREATE_DETACHED
+		    ? PTHREAD_DETACHED : PTHREAD_JOINABLE);
+
+  if (setup->__stackaddr)
+    {
+      pthread->stackaddr = setup->__stackaddr;
+
+      /* If the user supplied a stack, it is not our responsibility to
+	 setup a stack guard.  */
+      pthread->guardsize = 0;
+      pthread->stack = 0;
+    }
+  else
+    {
+      /* Allocate a stack.  */
+      err = __pthread_stack_alloc (&pthread->stackaddr,
+				   ((setup->__guardsize + __vm_page_size-1)
+				    / __vm_page_size) * __vm_page_size
+				   + stacksize);
+      if (err)
+	goto failed_stack_alloc;
+
+      pthread->guardsize = setup->__guardsize;
+      pthread->stack = 1;
+    }
+
+  pthread->stacksize = stacksize;
+
+  /* Allocate the kernel thread and other required resources.  */
+  err = __pthread_thread_alloc (pthread);
+  if (err)
+    goto failed_thread_alloc;
+
+#ifdef ENABLE_TLS
+  pthread->tcb = _dl_allocate_tls (NULL);
+  if (!pthread->tcb)
+    {
+      err = ENOMEM;
+      goto failed_thread_tls_alloc;
+    }
+  pthread->tcb->tcb = pthread->tcb;
+#endif /* ENABLE_TLS */
+
+  /* And initialize the rest of the machine context.  This may include
+     additional machine- and system-specific initializations that
+     prove convenient.  */
+  err = __pthread_setup (pthread, entry_point, start_routine, arg);
+  if (err)
+    goto failed_setup;
+
+  /* Initialize the system-specific signal state for the new
+     thread.  */
+  err = __pthread_sigstate_init (pthread);
+  if (err)
+    goto failed_sigstate;
+
+  /* If the new thread is joinable, add a reference for the caller.  */
+  if (pthread->state == PTHREAD_JOINABLE)
+    pthread->nr_refs++;
+
+  /* Set the new thread's signal mask and set the pending signals to
+     empty.  POSIX says: "The signal mask shall be inherited from the
+     creating thread.  The set of signals pending for the new thread
+     shall be empty."  If the currnet thread is not a pthread then we
+     just inherit the process' sigmask.  */
+  if (__pthread_num_threads == 1)
+    err = sigprocmask (0, 0, &sigset);
+  else
+    err = __pthread_sigstate (_pthread_self (), 0, 0, &sigset, 0);
+  assert_perror (err);
+   
+  err = __pthread_sigstate (pthread, SIG_SETMASK, &sigset, 0, 1);
+  assert_perror (err);
+
+  /* Increase the total number of threads.  We do this before actually
+     starting the new thread, since the new thread might immediately
+     call `pthread_exit' which decreases the number of threads and
+     calls `exit' if the number of threads reaches zero.  Increasing
+     the number of threads from within the new thread isn't an option
+     since this thread might return and call `pthread_exit' before the
+     new thread runs.  */
+  __atomic_inc (&__pthread_total);
+
+  /* Store a pointer to this thread in the thread ID lookup table.  We
+     could use __thread_setid, however, we only lock for reading as no
+     other thread should be using this entry (we also assume that the
+     store is atomic).  */
+  __pthread_rwlock_rdlock (&__pthread_threads_lock);
+  __pthread_threads[pthread->thread - 1] = pthread;
+  __pthread_rwlock_unlock (&__pthread_threads_lock);
+
+  /* At this point it is possible to guess our pthread ID.  We have to
+     make sure that all functions taking a pthread_t argument can
+     handle the fact that this thread isn't really running yet.  Since
+     the new thread might be passed its ID through pthread_create (to
+     avoid calling pthread_self), read it before starting the thread.  */
+  *thread = pthread;
+
+  /* Schedule the new thread.  */
+  err = __pthread_thread_start (pthread);
+  if (err)
+    goto failed_starting;
+
+
+  return 0;
+
+ failed_starting:
+  /* If joinable, a reference was added for the caller.  */
+  if (pthread->state == PTHREAD_JOINABLE)
+    __pthread_dealloc (pthread);
+
+  __pthread_setid (pthread->thread, NULL);
+  __atomic_dec (&__pthread_total);
+ failed_sigstate:
+  __pthread_sigstate_destroy (pthread);
+ failed_setup:
+#ifdef ENABLE_TLS
+  _dl_deallocate_tls (pthread->tcb, 1);
+  pthread->tcb = NULL;
+ failed_thread_tls_alloc:
+#endif /* ENABLE_TLS */
+  __pthread_thread_terminate (pthread);
+
+  /* __pthread_thread_terminate has taken care of deallocating the stack and
+     the thread structure.  */
+  goto failed;
+ failed_thread_alloc:
+  if (pthread->stack)
+    __pthread_stack_dealloc (pthread->stackaddr,
+			     ((setup->__guardsize + __vm_page_size-1)
+			      / __vm_page_size) * __vm_page_size
+			     + stacksize);
+ failed_stack_alloc:
+  __pthread_dealloc (pthread);
+ failed:
+  return err;
+}
diff --git a/htl/pthread/pt-dealloc.c b/htl/pthread/pt-dealloc.c
new file mode 100644
index 0000000..f44aefa
--- /dev/null
+++ b/htl/pthread/pt-dealloc.c
@@ -0,0 +1,69 @@
+/* Deallocate a thread structure.
+   Copyright (C) 2000, 2008 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 <assert.h>
+#include <pthread.h>
+#include <stdlib.h>
+
+#include <pt-internal.h>
+
+#include <bits/pt-atomic.h>
+
+/* List of thread structures corresponding to free thread IDs.  */
+extern struct __pthread *__pthread_free_threads;
+extern pthread_mutex_t __pthread_free_threads_lock;
+
+
+/* Deallocate the thread structure for PTHREAD.  */
+void
+__pthread_dealloc (struct __pthread *pthread)
+{
+  assert (pthread->state != PTHREAD_TERMINATED);
+
+  if (! __atomic_dec_and_test (&pthread->nr_refs))
+    return;
+
+  /* Withdraw this thread from the thread ID lookup table.  */
+  __pthread_setid (pthread->thread, NULL);
+
+  /* Mark the thread as terminated.  We broadcast the condition
+     here to prevent pthread_join from waiting for this thread to
+     exit where it was never really started.  Such a call to
+     pthread_join is completely bogus, but unfortunately allowed
+     by the standards.  */
+  __pthread_mutex_lock (&pthread->state_lock);
+  if (pthread->state != PTHREAD_EXITED)
+    __pthread_cond_broadcast (&pthread->state_cond);
+  __pthread_mutex_unlock (&pthread->state_lock);
+
+  /* We do not actually deallocate the thread structure, but add it to
+     a list of re-usable thread structures.  */
+  __pthread_mutex_lock (&__pthread_free_threads_lock);
+  __pthread_enqueue (&__pthread_free_threads, pthread);
+  __pthread_mutex_unlock (&__pthread_free_threads_lock);
+
+  /* Setting PTHREAD->STATE to PTHREAD_TERMINATED makes this TCB
+     available for reuse.  After that point, we can no longer assume
+     that PTHREAD is valid.
+
+     Note that it is safe to not lock this update to PTHREAD->STATE:
+     the only way that it can now be accessed is in __pthread_alloc,
+     which reads this variable.  */
+  pthread->state = PTHREAD_TERMINATED;
+}
diff --git a/htl/pthread/pt-detach.c b/htl/pthread/pt-detach.c
new file mode 100644
index 0000000..3431f1b
--- /dev/null
+++ b/htl/pthread/pt-detach.c
@@ -0,0 +1,80 @@
+/* Detach a thread.
+   Copyright (C) 2000, 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 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 <pthread.h>
+#include <stddef.h>
+
+#include <pt-internal.h>
+
+/* Indicate that the storage for THREAD can be reclaimed when it
+   terminates.  */
+int
+pthread_detach (pthread_t thread)
+{
+  struct __pthread *pthread;
+  int err = 0;
+
+  /* Lookup the thread structure for THREAD.  */
+  pthread = __pthread_getid (thread);
+  if (pthread == NULL)
+    return ESRCH;
+
+  __pthread_mutex_lock (&pthread->state_lock);
+
+  switch (pthread->state)
+    {
+    case PTHREAD_JOINABLE:
+      /* THREAD still running.  Mark it as detached such that its
+         resources can be reclaimed as soon as the thread exits.  */
+      pthread->state = PTHREAD_DETACHED;
+
+      /* Broadcast the condition.  This will make threads that are
+	 waiting to join THREAD continue with hopefully disastrous
+	 consequences instead of blocking indefinitely.  */
+      pthread_cond_broadcast (&pthread->state_cond);
+      __pthread_mutex_unlock (&pthread->state_lock);
+
+      __pthread_dealloc (pthread);
+      break;
+
+    case PTHREAD_EXITED:
+      __pthread_mutex_unlock (&pthread->state_lock);
+
+      /* THREAD has already exited.  PTHREAD remained after the thread
+	 exited in order to provide the exit status, but it turns out
+	 it won't be needed.  */
+      __pthread_dealloc (pthread);
+      break;
+
+    case PTHREAD_TERMINATED:
+      /* Pretend THREAD wasn't there in the first place.  */
+      __pthread_mutex_unlock (&pthread->state_lock);
+      err = ESRCH;
+      break;
+
+    default:
+      /* Thou shalt not detach non-joinable threads!  */
+      __pthread_mutex_unlock (&pthread->state_lock);
+      err = EINVAL;
+      break;
+    }
+
+  return err;
+}
diff --git a/htl/pthread/pt-exit.c b/htl/pthread/pt-exit.c
new file mode 100644
index 0000000..af75937
--- /dev/null
+++ b/htl/pthread/pt-exit.c
@@ -0,0 +1,112 @@
+/* Thread termination.
+   Copyright (C) 2000, 2002, 2005, 2007, 2011 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 <assert.h>
+#include <errno.h>
+#include <pthread.h>
+#include <stdlib.h>
+
+#include <pt-internal.h>
+
+#include <bits/pt-atomic.h>
+
+
+/* Terminate the current thread and make STATUS available to any
+   thread that might join it.  */
+void
+__pthread_exit (void *status)
+{
+  struct __pthread *self = _pthread_self ();
+  struct __pthread_cancelation_handler **handlers;
+  int oldstate;
+
+  /* Run any cancelation handlers.  According to POSIX, the
+     cancellation cleanup handlers should be called with cancellation
+     disabled.  */
+  pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &oldstate);
+
+  for (handlers = __pthread_get_cleanup_stack ();
+       *handlers;
+       *handlers = (*handlers)->__next)
+    (*handlers)->__handler ((*handlers)->__arg);
+
+  pthread_setcancelstate (oldstate, &oldstate);
+
+  /* Decrease the number of threads.  We use an atomic operation to
+     make sure that only the last thread calls `exit'.  */
+  if (__atomic_dec_and_test (&__pthread_total))
+    /* We are the last thread.  */
+    exit (0);
+
+  /* Note that after this point the process can be terminated at any
+     point if another thread calls `pthread_exit' and happens to be
+     the last thread.  */
+
+  __pthread_mutex_lock (&self->state_lock);
+
+  if (self->cancel_state == PTHREAD_CANCEL_ENABLE && self->cancel_pending)
+    status = PTHREAD_CANCELED;
+
+  switch (self->state)
+    {
+    default:
+      assert (! "Consistency error: unexpected self->state");
+      abort ();
+      break;
+
+    case PTHREAD_DETACHED:
+      __pthread_mutex_unlock (&self->state_lock);
+
+      break;
+
+    case PTHREAD_JOINABLE:
+      /* We need to stay around for a while since another thread
+         might want to join us.  */
+      self->state = PTHREAD_EXITED;
+
+      /* We need to remember the exit status.  A thread joining us
+         might ask for it.  */
+      self->status = status;
+
+      /* Broadcast the condition.  This will wake up threads that are
+         waiting to join us.  */
+      __pthread_cond_broadcast (&self->state_cond);
+      __pthread_mutex_unlock (&self->state_lock);
+
+      break;
+    }
+
+  /* Destroy any thread specific data.  */
+  __pthread_destroy_specific (self);
+
+  /* Destroy any signal state.  */
+  __pthread_sigstate_destroy (self);
+
+  /* Self terminating requires TLS, so defer the release of the TCB until
+     the thread structure is reused.  */
+
+  /* Release kernel resources, including the kernel thread and the stack,
+     and drop the self reference.  */
+  __pthread_thread_terminate (self);
+
+  /* NOTREACHED */
+  abort ();
+}
+
+strong_alias (__pthread_exit, pthread_exit);
diff --git a/htl/pthread/pt-getattr.c b/htl/pthread/pt-getattr.c
new file mode 100644
index 0000000..0b86c66
--- /dev/null
+++ b/htl/pthread/pt-getattr.c
@@ -0,0 +1,52 @@
+/* Thread attributes retrieval.
+   Copyright (C) 2008 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 <assert.h>
+#include <errno.h>
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+/* Initialize thread attribute *ATTR with attributes corresponding to the
+   already running thread THREAD.  It shall be called on an uninitialized ATTR
+   and destroyed with pthread_attr_destroy when no longer needed.  */
+int
+__pthread_getattr_np (pthread_t thread, pthread_attr_t *attr)
+{
+  struct __pthread *pthread;
+
+  pthread = __pthread_getid(thread);
+  if (pthread == NULL)
+    return ESRCH;
+
+  /* Some attributes (schedparam, inheritsched, contentionscope and schedpolicy)
+     are not supported yet, so fill them with our default values.  */
+  *attr = __pthread_default_attr;
+
+  attr->__stackaddr = pthread->stackaddr +
+		      ((pthread->guardsize + __vm_page_size-1)
+		       / __vm_page_size * __vm_page_size);
+  attr->__stacksize = pthread->stacksize;
+  attr->__guardsize = pthread->guardsize;
+  attr->__detachstate = (pthread->state == PTHREAD_DETACHED
+		       ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE);
+
+  return 0;
+}
+weak_alias (__pthread_getattr_np, pthread_getattr_np)
diff --git a/htl/pthread/pt-initialize.c b/htl/pthread/pt-initialize.c
new file mode 100644
index 0000000..4435a36
--- /dev/null
+++ b/htl/pthread/pt-initialize.c
@@ -0,0 +1,88 @@
+/* Initialize pthreads library.
+   Copyright (C) 2000,02 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 <assert.h>
+#include <string.h>
+
+#include <pt-internal.h>
+#include <set-hooks.h>
+
+#include <pthread.h>
+#include <pthread-functions.h>
+
+DEFINE_HOOK (__pthread_init, (void));
+
+#if IS_IN (libpthread)
+static const struct pthread_functions pthread_functions =
+  {
+    .ptr_pthread_attr_destroy = __pthread_attr_destroy,
+    .ptr_pthread_attr_init = __pthread_attr_init,
+    .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,
+    .ptr_pthread_equal = __pthread_equal,
+    .ptr___pthread_exit = __pthread_exit,
+    .ptr_pthread_getschedparam = __pthread_getschedparam,
+    .ptr_pthread_setschedparam = __pthread_setschedparam,
+    .ptr_pthread_mutex_destroy = _pthread_mutex_destroy,
+    .ptr_pthread_mutex_init = _pthread_mutex_init,
+    .ptr_pthread_mutex_lock = __pthread_mutex_lock,
+    .ptr_pthread_mutex_trylock = __pthread_mutex_trylock,
+    .ptr_pthread_mutex_unlock = __pthread_mutex_unlock,
+    .ptr_pthread_self = __pthread_self,
+    .ptr___pthread_setcancelstate = __pthread_setcancelstate,
+    .ptr_pthread_setcanceltype = __pthread_setcanceltype,
+    .ptr___pthread_get_cleanup_stack = __pthread_get_cleanup_stack,
+    .ptr_pthread_once = __pthread_once,
+    .ptr_pthread_rwlock_rdlock = __pthread_rwlock_rdlock,
+    .ptr_pthread_rwlock_wrlock = __pthread_rwlock_wrlock,
+    .ptr_pthread_rwlock_unlock = __pthread_rwlock_unlock,
+    .ptr_pthread_key_create = __pthread_key_create,
+    .ptr_pthread_getspecific = __pthread_getspecific,
+    .ptr_pthread_setspecific = __pthread_setspecific,
+    .ptr__IO_flockfile = _cthreads_flockfile,
+    .ptr__IO_funlockfile = _cthreads_funlockfile,
+    .ptr__IO_ftrylockfile = _cthreads_ftrylockfile,
+  };
+#endif /* IS_IN (libpthread) */
+
+/* Initialize the pthreads library.  */
+void
+___pthread_init (void)
+{
+#if IS_IN (libpthread)
+  __libc_pthread_init(&pthread_functions);
+#endif
+  RUN_HOOK (__pthread_init, ());
+}
diff --git a/htl/pthread/pt-internal.h b/htl/pthread/pt-internal.h
new file mode 100644
index 0000000..0793046
--- /dev/null
+++ b/htl/pthread/pt-internal.h
@@ -0,0 +1,330 @@
+/* Internal defenitions for pthreads library.
+   Copyright (C) 2000, 2005, 2006, 2007, 2008 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.  */
+
+#ifndef _PT_INTERNAL_H
+#define _PT_INTERNAL_H	1
+
+#include <pthread.h>
+#include <stddef.h>
+#include <sched.h>
+#include <signal.h>
+#include <assert.h>
+#define __need_res_state
+#include <resolv.h>
+
+#include <bits/pt-atomic.h>
+
+#include <pt-key.h>
+
+#include <pt-sysdep.h>
+#include <pt-machdep.h>
+
+#if IS_IN (libpthread)
+# include <ldsodefs.h>
+#endif
+
+/* Thread state.  */
+enum pthread_state
+{
+  /* The thread is running and joinable.  */
+  PTHREAD_JOINABLE = 0,
+  /* The thread is running and detached.  */
+  PTHREAD_DETACHED,
+  /* A joinable thread exited and its return code is available.  */
+  PTHREAD_EXITED,
+  /* The thread structure is unallocated and available for reuse.  */
+  PTHREAD_TERMINATED
+};
+
+#ifndef PTHREAD_KEY_MEMBERS
+# define PTHREAD_KEY_MEMBERS
+#endif
+
+#ifndef PTHREAD_SYSDEP_MEMBERS
+# define PTHREAD_SYSDEP_MEMBERS
+#endif
+
+#if !(IS_IN (libpthread))
+#ifdef ENABLE_TLS
+/* Type of the TCB.  */
+typedef struct
+{
+  void *tcb;			/* Points to this structure.  */
+  void *dtv;			/* Vector of pointers to TLS data.  */
+  thread_t self;		/* This thread's control port.  */
+} tcbhead_t;
+#endif /* ENABLE_TLS */
+#endif /* ! IS_IN (libpthread) */
+
+/* This structure describes a POSIX thread.  */
+struct __pthread
+{
+  /* Thread ID.  */
+  pthread_t thread;
+
+  __atomic_t nr_refs;   /* Detached threads have a self reference only,
+			   while joinable threads have two references.
+			   These are used to keep the structure valid at
+			   thread destruction.  Detaching/joining a thread
+			   drops a reference.  */
+
+  /* Cancellation.  */
+  pthread_mutex_t cancel_lock;  /* Protect cancel_xxx members.  */
+  void (*cancel_hook)(void *);	/* Called to unblock a thread blocking
+				   in a cancellation point (namely,
+				   __pthread_cond_timedwait_internal).  */
+  void *cancel_hook_arg;
+  int cancel_state;
+  int cancel_type;
+  int cancel_pending;
+  struct __pthread_cancelation_handler *cancelation_handlers;
+
+  /* Thread stack.  */
+  void *stackaddr;
+  size_t stacksize;
+  size_t guardsize;
+  int stack;			/* Nonzero if the stack was allocated.  */
+
+  /* Exit status.  */
+  void *status;
+
+  /* Thread state.  */
+  enum pthread_state state;
+  pthread_mutex_t state_lock;	/* Locks the state.  */
+  pthread_cond_t state_cond;	/* Signalled when the state changes.  */
+
+  /* Resolver state.  */
+  struct __res_state res_state;
+
+  /* Thread context.  */
+  struct pthread_mcontext mcontext;
+
+  PTHREAD_KEY_MEMBERS
+
+  PTHREAD_SYSDEP_MEMBERS
+
+#ifdef ENABLE_TLS
+  tcbhead_t *tcb;
+#endif /* ENABLE_TLS */
+
+  /* Queue links.  Since PREVP is used to determine if a thread has been
+     awaken, it must be protected by the queue lock.  */
+  struct __pthread *next, **prevp;
+};
+
+/* Enqueue an element THREAD on the queue *HEAD.  */
+static inline void
+__pthread_enqueue (struct __pthread **head, struct __pthread *thread)
+{
+  assert (thread->prevp == 0);
+
+  thread->next = *head;
+  thread->prevp = head;
+  if (*head)
+    (*head)->prevp = &thread->next;
+  *head = thread;
+}
+
+/* Dequeue the element THREAD from the queue it is connected to.  */
+static inline void
+__pthread_dequeue (struct __pthread *thread)
+{
+  assert (thread);
+  assert (thread->prevp);
+
+  if (thread->next)
+    thread->next->prevp = thread->prevp;
+  *thread->prevp = thread->next;
+  thread->prevp = 0;
+}
+
+/* Iterate over QUEUE storing each element in ELEMENT.  */
+#define __pthread_queue_iterate(queue, element)				\
+  for (struct __pthread *__pdi_next = (queue);				\
+       ((element) = __pdi_next)						\
+	 && ((__pdi_next = __pdi_next->next),				\
+	     1);							\
+       )
+
+/* Iterate over QUEUE dequeuing each element, storing it in
+   ELEMENT.  */
+#define __pthread_dequeuing_iterate(queue, element)			\
+  for (struct __pthread *__pdi_next = (queue);				\
+       ((element) = __pdi_next)						\
+	 && ((__pdi_next = __pdi_next->next),				\
+	     ((element)->prevp = 0),					\
+	     1);							\
+       )
+
+/* The total number of threads currently active.  */
+extern __atomic_t __pthread_total;
+
+/* The total number of thread IDs currently in use, or on the list of
+   available thread IDs.  */
+extern int __pthread_num_threads;
+
+/* Concurrency hint.  */
+extern int __pthread_concurrency;
+
+/* Array of __pthread structures and its lock.  Indexed by the pthread
+   id minus one.  (Why not just use the pthread id?  Because some
+   brain-dead users of the pthread interface incorrectly assume that 0
+   is an invalid pthread id.)  */
+extern struct __pthread **__pthread_threads;
+extern pthread_rwlock_t __pthread_threads_lock;
+
+#define __pthread_getid(thread) \
+  ({ struct __pthread *__t;                                                  \
+     __pthread_rwlock_rdlock (&__pthread_threads_lock);                      \
+     __t = __pthread_threads[thread - 1];                                    \
+     __pthread_rwlock_unlock (&__pthread_threads_lock);                      \
+     __t; })
+
+#define __pthread_setid(thread, pthread) \
+  __pthread_rwlock_wrlock (&__pthread_threads_lock);                         \
+  __pthread_threads[thread - 1] = pthread;                                   \
+  __pthread_rwlock_unlock (&__pthread_threads_lock);
+
+/* Similar to pthread_self, but returns the thread descriptor instead
+   of the thread ID.  */
+#ifndef _pthread_self
+extern struct __pthread *_pthread_self (void);
+#endif
+
+
+/* Initialize the pthreads library.  */
+extern void ___pthread_init (void);
+
+/* Internal version of pthread_create.  Rather than return the new
+   tid, we return the whole __pthread structure in *PTHREAD.  */
+extern int __pthread_create_internal (struct __pthread **__restrict pthread,
+				      const pthread_attr_t *__restrict attr,
+				      void *(*start_routine)(void *),
+				      void *__restrict arg);
+
+/* Allocate a new thread structure and a pthread thread ID (but not a
+   kernel thread or a stack).  THREAD has one reference.  */
+extern int __pthread_alloc (struct __pthread **thread);
+
+/* Deallocate the thread structure.  This is the dual of
+   __pthread_alloc (N.B. it does not call __pthread_stack_dealloc nor
+   __pthread_thread_terminate).  THREAD loses one reference and is
+   released if the reference counter drops to 0.  */
+extern void __pthread_dealloc (struct __pthread *thread);
+
+
+/* Allocate a stack of size STACKSIZE.  The stack base shall be
+   returned in *STACKADDR.  */
+extern int __pthread_stack_alloc (void **stackaddr, size_t stacksize);
+
+/* Deallocate the stack STACKADDR of size STACKSIZE.  */
+extern void __pthread_stack_dealloc (void *stackaddr, size_t stacksize);
+
+
+/* Setup thread THREAD's context.  */
+extern int __pthread_setup (struct __pthread *__restrict thread,
+				  void (*entry_point)(struct __pthread *,
+						      void *(*)(void *),
+						      void *),
+				  void *(*start_routine)(void *),
+				  void *__restrict arg);
+
+
+/* Allocate a kernel thread (and any miscellaneous system dependent
+   resources) for THREAD; it must not be placed on the run queue.  */
+extern int __pthread_thread_alloc (struct __pthread *thread);
+
+/* Start THREAD making it eligible to run.  */
+extern int __pthread_thread_start (struct __pthread *thread);
+
+/* Terminate the kernel thread associated with THREAD, and deallocate its
+   stack as well as any other kernel resource associated with it.
+   In addition, THREAD looses one reference.
+
+   This function can be called by any thread, including the target thread.
+   Since some resources that are destroyed along the kernel thread are
+   stored in thread-local variables, the conditions required for this
+   function to behave correctly are a bit unusual : as long as the target
+   thread hasn't been started, any thread can terminate it, but once it
+   has started, no other thread can terminate it, so that thread-local
+   variables created by that thread are correctly released.  */
+extern void __pthread_thread_terminate (struct __pthread *thread);
+
+
+/* Called by a thread just before it calls the provided start
+   routine.  */
+extern void __pthread_startup (void);
+
+/* Block THREAD.  */
+extern void __pthread_block (struct __pthread *thread);
+
+/* Block THREAD until *ABSTIME is reached.  */
+extern error_t __pthread_timedblock (struct __pthread *__restrict thread,
+				     const struct timespec *__restrict abstime,
+				     clockid_t clock_id);
+
+/* Wakeup THREAD.  */
+extern void __pthread_wakeup (struct __pthread *thread);
+
+
+/* Perform a cancelation.  The CANCEL_LOCK member of the given thread must
+   be locked before calling this function, which must unlock it.  */
+extern int __pthread_do_cancel (struct __pthread *thread);
+
+
+/* Initialize the thread specific data structures.  THREAD must be the
+   calling thread.  */
+extern error_t __pthread_init_specific (struct __pthread *thread);
+
+/* Call the destructors on all of the thread specific data in THREAD.
+   THREAD must be the calling thread.  */
+extern void __pthread_destroy_specific (struct __pthread *thread);
+
+
+/* Initialize newly create thread *THREAD's signal state data
+   structures.  */
+extern error_t __pthread_sigstate_init (struct __pthread *thread);
+
+/* Destroy the signal state data structures associcated with thread
+   *THREAD.  */
+extern void __pthread_sigstate_destroy (struct __pthread *thread);
+
+/* Modify thread *THREAD's signal state.  */
+extern error_t __pthread_sigstate (struct __pthread *__restrict thread, int how,
+				   const sigset_t *__restrict set,
+				   sigset_t *__restrict oset,
+				   int clear_pending);
+
+
+/* Default thread attributes.  */
+extern const struct __pthread_attr __pthread_default_attr;
+
+/* Default barrier attributes.  */
+extern const struct __pthread_barrierattr __pthread_default_barrierattr;
+
+/* Default mutex attributes.  */
+extern const struct __pthread_mutexattr __pthread_default_mutexattr;
+
+/* Default rdlock attributes.  */
+extern const struct __pthread_rwlockattr __pthread_default_rwlockattr;
+
+/* Default condition attributes.  */
+extern const struct __pthread_condattr __pthread_default_condattr;
+
+#endif /* pt-internal.h */
diff --git a/htl/pthread/pt-join.c b/htl/pthread/pt-join.c
new file mode 100644
index 0000000..9730afc
--- /dev/null
+++ b/htl/pthread/pt-join.c
@@ -0,0 +1,76 @@
+/* Wait for thread termination.
+   Copyright (C) 2000 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 <pthread.h>
+#include <stddef.h>
+
+#include <pt-internal.h>
+
+/* Make calling thread wait for termination of thread THREAD.  Return
+   the exit status of the thread in *STATUS.  */
+int
+pthread_join (pthread_t thread, void **status)
+{
+  struct __pthread *pthread;
+  int err = 0;
+
+  /* Lookup the thread structure for THREAD.  */
+  pthread = __pthread_getid (thread);
+  if (pthread == NULL)
+    return ESRCH;
+
+  __pthread_mutex_lock (&pthread->state_lock);
+  pthread_cleanup_push ((void (*)(void *)) __pthread_mutex_unlock,
+			&pthread->state_lock);
+
+  /* Rely on pthread_cond_wait being a cancellation point to make
+     pthread_join one too.  */
+  while (pthread->state == PTHREAD_JOINABLE)
+    __pthread_cond_wait (&pthread->state_cond, &pthread->state_lock);
+
+  pthread_cleanup_pop (0);
+
+  switch (pthread->state)
+    {
+    case PTHREAD_EXITED:
+      /* THREAD has already exited.  Salvage its exit status.  */
+      if (status)
+	*status = pthread->status;
+
+      __pthread_mutex_unlock (&pthread->state_lock);
+
+      __pthread_dealloc (pthread);
+      break;
+
+    case PTHREAD_TERMINATED:
+      /* Pretend THREAD wasn't there in the first place.  */
+      __pthread_mutex_unlock (&pthread->state_lock);
+      err = ESRCH;
+      break;
+
+    default:
+      /* Thou shalt not join non-joinable threads!  */
+      __pthread_mutex_unlock (&pthread->state_lock);
+      err = EINVAL;
+      break;
+    }
+
+  return err;
+}
diff --git a/htl/pthread/pt-self.c b/htl/pthread/pt-self.c
new file mode 100644
index 0000000..deb57c0
--- /dev/null
+++ b/htl/pthread/pt-self.c
@@ -0,0 +1,34 @@
+/* Get calling thread's ID.
+   Copyright (C) 2000, 2008 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 <pthread.h>
+
+#include <pt-internal.h>
+
+/* Return the thread ID of the calling thread.  */
+pthread_t
+__pthread_self (void)
+{
+  struct __pthread *self = _pthread_self ();
+  assert (self);
+
+  return self->thread;
+}
+
+strong_alias (__pthread_self, pthread_self);
diff --git a/htl/pthread/pt-setcancelstate.c b/htl/pthread/pt-setcancelstate.c
new file mode 100644
index 0000000..7b60015
--- /dev/null
+++ b/htl/pthread/pt-setcancelstate.c
@@ -0,0 +1,47 @@
+/* Set the cancel state for the calling thread.
+   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.  */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+int
+__pthread_setcancelstate (int state, int *oldstate)
+{
+  struct __pthread *p = _pthread_self ();
+
+  switch (state)
+    {
+    default:
+      return EINVAL;
+    case PTHREAD_CANCEL_ENABLE:
+    case PTHREAD_CANCEL_DISABLE:
+      break;
+    }
+
+  __pthread_mutex_lock (&p->cancel_lock);
+  if (oldstate)
+    *oldstate = p->cancel_state;
+  p->cancel_state = state;
+  __pthread_mutex_unlock (&p->cancel_lock);
+
+  return 0;
+}
+
+strong_alias (__pthread_setcancelstate, pthread_setcancelstate);
diff --git a/htl/pthread/pt-setcanceltype.c b/htl/pthread/pt-setcanceltype.c
new file mode 100644
index 0000000..3cfbe9c
--- /dev/null
+++ b/htl/pthread/pt-setcanceltype.c
@@ -0,0 +1,47 @@
+/* Set the cancel type for the calling thread.
+   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.  */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+int
+__pthread_setcanceltype (int type, int *oldtype)
+{
+  struct __pthread *p = _pthread_self ();
+
+  switch (type)
+    {
+    default:
+      return EINVAL;
+    case PTHREAD_CANCEL_DEFERRED:
+    case PTHREAD_CANCEL_ASYNCHRONOUS:
+      break;
+    }
+
+  __pthread_mutex_lock (&p->cancel_lock);
+  if (oldtype)
+    *oldtype = p->cancel_type;
+  p->cancel_type = type;
+  __pthread_mutex_unlock (&p->cancel_lock);
+
+  return 0;
+}
+
+strong_alias (__pthread_setcanceltype, pthread_setcanceltype);
diff --git a/htl/pthread/pt-sigmask.c b/htl/pthread/pt-sigmask.c
new file mode 100644
index 0000000..1b53873
--- /dev/null
+++ b/htl/pthread/pt-sigmask.c
@@ -0,0 +1,33 @@
+/* Get or set a thread's signal mask.
+   Copyright (C) 2000 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 <pthread.h>
+#include <signal.h>
+
+#include <pt-internal.h>
+
+int
+pthread_sigmask (int how, const sigset_t *set,
+		 sigset_t *oset)
+{
+  struct __pthread *self = _pthread_self ();
+
+  /* Do not clear SELF's pending signals.  */
+  return __pthread_sigstate (self, how, set, oset, 0);
+}
diff --git a/htl/pthread/pt-spin-inlines.c b/htl/pthread/pt-spin-inlines.c
new file mode 100644
index 0000000..97afb4d
--- /dev/null
+++ b/htl/pthread/pt-spin-inlines.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 2000 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.  */
+
+/* <bits/spin-lock.h> declares some extern inline functions.  These
+   functions are declared additionally here for use when inlining is
+   not possible.  */
+
+#define _FORCE_INLINES
+#define __PT_SPIN_INLINE /* empty */
+
+#include <pthread.h>
+
+/* Weak aliases for the spin lock functions.  */
+weak_alias (__pthread_spin_destroy, pthread_spin_destroy);
+weak_alias (__pthread_spin_init, pthread_spin_init);
+weak_alias (__pthread_spin_trylock, pthread_spin_trylock);
+weak_alias (__pthread_spin_lock, pthread_spin_lock);
+weak_alias (__pthread_spin_unlock, pthread_spin_unlock);
diff --git a/htl/pthread/pt-testcancel.c b/htl/pthread/pt-testcancel.c
new file mode 100644
index 0000000..3ba07b6
--- /dev/null
+++ b/htl/pthread/pt-testcancel.c
@@ -0,0 +1,36 @@
+/* Add an explicit cancelation point.
+   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.  */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+void
+pthread_testcancel (void)
+{
+  struct __pthread *p = _pthread_self ();
+  int cancelled;
+
+  __pthread_mutex_lock (&p->cancel_lock);
+  cancelled = (p->cancel_state == PTHREAD_CANCEL_ENABLE) && p->cancel_pending;
+  __pthread_mutex_unlock (&p->cancel_lock);
+
+  if (cancelled)
+    pthread_exit (PTHREAD_CANCELED);
+}
diff --git a/htl/pthread/pt-yield.c b/htl/pthread/pt-yield.c
new file mode 100644
index 0000000..27848bb
--- /dev/null
+++ b/htl/pthread/pt-yield.c
@@ -0,0 +1,26 @@
+/* Yield the processor to another thread or process.
+   Copyright (C) 2010 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 <pthread.h>
+#include <sched.h>
+
+int pthread_yield(void)
+{
+  return sched_yield ();
+}
diff --git a/htl/shlib-versions b/htl/shlib-versions
new file mode 100644
index 0000000..98e07a6
--- /dev/null
+++ b/htl/shlib-versions
@@ -0,0 +1 @@
+libpthread=0.3
diff --git a/htl/sysdeps/generic/fork.h b/htl/sysdeps/generic/fork.h
new file mode 100644
index 0000000..c6ac15e
--- /dev/null
+++ b/htl/sysdeps/generic/fork.h
@@ -0,0 +1,29 @@
+/* Copyright (C) 2002-2015 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* 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/htl/sysdeps/generic/old_pt-atfork.c b/htl/sysdeps/generic/old_pt-atfork.c
new file mode 100644
index 0000000..5366eaa
--- /dev/null
+++ b/htl/sysdeps/generic/old_pt-atfork.c
@@ -0,0 +1,27 @@
+/* Register fork handlers.  Generic 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.  */
+
+#include <shlib-compat.h>
+
+#if SHLIB_COMPAT(libpthread, GLIBC_2_12, GLIBC_2_23)
+# define pthread_atfork __dyn_pthread_atfork
+# include "pt-atfork.c"
+# undef pthread_atfork
+compat_symbol (libpthread, __dyn_pthread_atfork, pthread_atfork, GLIBC_2_12);
+#endif
diff --git a/htl/sysdeps/generic/pt-atfork.c b/htl/sysdeps/generic/pt-atfork.c
new file mode 100644
index 0000000..df12fc8
--- /dev/null
+++ b/htl/sysdeps/generic/pt-atfork.c
@@ -0,0 +1,34 @@
+/* Register fork handlers.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+#include <fork.h>
+
+/* This is defined by newer gcc version unique for each module.  */
+extern void *__dso_handle __attribute__ ((__weak__,
+					  __visibility__ ("hidden")));
+
+int
+pthread_atfork (void (*prepare) (void),
+		void (*parent) (void),
+		void (*child) (void))
+{
+  return __register_atfork (prepare, parent, child, &__dso_handle == NULL ? NULL : __dso_handle);
+}
diff --git a/htl/sysdeps/generic/pt-attr-destroy.c b/htl/sysdeps/generic/pt-attr-destroy.c
new file mode 100644
index 0000000..b9bd374
--- /dev/null
+++ b/htl/sysdeps/generic/pt-attr-destroy.c
@@ -0,0 +1,28 @@
+/* pthread_attr_destroy.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+__pthread_attr_destroy (pthread_attr_t *attr)
+{
+  return 0;
+}
+strong_alias (__pthread_attr_destroy, pthread_attr_destroy);
diff --git a/htl/sysdeps/generic/pt-attr-getdetachstate.c b/htl/sysdeps/generic/pt-attr-getdetachstate.c
new file mode 100644
index 0000000..6a1de67
--- /dev/null
+++ b/htl/sysdeps/generic/pt-attr-getdetachstate.c
@@ -0,0 +1,31 @@
+/* pthread_attr_getdetachstate.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+__pthread_attr_getdetachstate (const pthread_attr_t *attr,
+			     int *detachstate)
+{
+  *detachstate = attr->__detachstate;
+  return 0;
+}
+
+strong_alias (__pthread_attr_getdetachstate, pthread_attr_getdetachstate);
diff --git a/htl/sysdeps/generic/pt-attr-getguardsize.c b/htl/sysdeps/generic/pt-attr-getguardsize.c
new file mode 100644
index 0000000..909f301
--- /dev/null
+++ b/htl/sysdeps/generic/pt-attr-getguardsize.c
@@ -0,0 +1,29 @@
+/* pthread_attr_getguardsize.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_getguardsize (const pthread_attr_t *attr,
+			   size_t *guardsize)
+{
+  *guardsize = attr->__guardsize;
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-attr-getinheritsched.c b/htl/sysdeps/generic/pt-attr-getinheritsched.c
new file mode 100644
index 0000000..5d5fc84
--- /dev/null
+++ b/htl/sysdeps/generic/pt-attr-getinheritsched.c
@@ -0,0 +1,31 @@
+/* pthread_attr_getinheritsched.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+__pthread_attr_getinheritsched (const pthread_attr_t *attr,
+			      int *inheritsched)
+{
+  *inheritsched = attr->__inheritsched;
+  return 0;
+}
+
+strong_alias (__pthread_attr_getinheritsched, pthread_attr_getinheritsched);
diff --git a/htl/sysdeps/generic/pt-attr-getschedparam.c b/htl/sysdeps/generic/pt-attr-getschedparam.c
new file mode 100644
index 0000000..85e07a1
--- /dev/null
+++ b/htl/sysdeps/generic/pt-attr-getschedparam.c
@@ -0,0 +1,34 @@
+/* pthread_attr_getschedparam.  Generic 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.  */
+
+#include <pthread.h>
+#include <sched.h>
+#include <string.h>
+
+#include <pt-internal.h>
+
+int
+__pthread_attr_getschedparam (const pthread_attr_t *attr,
+			    struct sched_param *param)
+{
+  memcpy (param, &attr->__schedparam, sizeof *param);
+  return 0;
+}
+
+strong_alias (__pthread_attr_getschedparam, pthread_attr_getschedparam);
diff --git a/htl/sysdeps/generic/pt-attr-getschedpolicy.c b/htl/sysdeps/generic/pt-attr-getschedpolicy.c
new file mode 100644
index 0000000..caf8a7b
--- /dev/null
+++ b/htl/sysdeps/generic/pt-attr-getschedpolicy.c
@@ -0,0 +1,31 @@
+/* pthread_attr_getschedpolicy.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+__pthread_attr_getschedpolicy (const pthread_attr_t *attr,
+			     int *policy)
+{
+  *policy = attr->__schedpolicy;
+  return 0;
+}
+
+strong_alias (__pthread_attr_getschedpolicy, pthread_attr_getschedpolicy);
diff --git a/htl/sysdeps/generic/pt-attr-getscope.c b/htl/sysdeps/generic/pt-attr-getscope.c
new file mode 100644
index 0000000..5e0c1a0
--- /dev/null
+++ b/htl/sysdeps/generic/pt-attr-getscope.c
@@ -0,0 +1,31 @@
+/* pthread_attr_getscope.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+__pthread_attr_getscope (const pthread_attr_t *attr,
+		       int *contentionscope)
+{
+  *contentionscope = attr->__contentionscope;
+  return 0;
+}
+
+strong_alias (__pthread_attr_getscope, pthread_attr_getscope);
diff --git a/htl/sysdeps/generic/pt-attr-getstack.c b/htl/sysdeps/generic/pt-attr-getstack.c
new file mode 100644
index 0000000..5ab821e
--- /dev/null
+++ b/htl/sysdeps/generic/pt-attr-getstack.c
@@ -0,0 +1,32 @@
+/* pthread_attr_getstack.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+__pthread_attr_getstack (const pthread_attr_t *attr,
+		       void **stackaddr,
+		       size_t *stacksize)
+{
+  pthread_attr_getstackaddr (attr, stackaddr);
+  pthread_attr_getstacksize (attr, stacksize);
+  return 0;
+}
+weak_alias (__pthread_attr_getstack, pthread_attr_getstack)
diff --git a/htl/sysdeps/generic/pt-attr-getstackaddr.c b/htl/sysdeps/generic/pt-attr-getstackaddr.c
new file mode 100644
index 0000000..0360701
--- /dev/null
+++ b/htl/sysdeps/generic/pt-attr-getstackaddr.c
@@ -0,0 +1,29 @@
+/* pthread_attr_getstackaddr.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_getstackaddr (const pthread_attr_t *attr,
+			   void **stackaddr)
+{
+  *stackaddr = attr->__stackaddr;
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-attr-getstacksize.c b/htl/sysdeps/generic/pt-attr-getstacksize.c
new file mode 100644
index 0000000..428aaa3
--- /dev/null
+++ b/htl/sysdeps/generic/pt-attr-getstacksize.c
@@ -0,0 +1,29 @@
+/* pthread_attr_getstacksize.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_getstacksize (const pthread_attr_t *attr,
+			   size_t *stacksize)
+{
+  *stacksize = attr->__stacksize;
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-attr-init.c b/htl/sysdeps/generic/pt-attr-init.c
new file mode 100644
index 0000000..f9eb361
--- /dev/null
+++ b/htl/sysdeps/generic/pt-attr-init.c
@@ -0,0 +1,29 @@
+/* pthread_attr_init.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+__pthread_attr_init (pthread_attr_t *attr)
+{
+  *attr = __pthread_default_attr;
+  return 0;
+}
+strong_alias (__pthread_attr_init, pthread_attr_init);
diff --git a/htl/sysdeps/generic/pt-attr-setdetachstate.c b/htl/sysdeps/generic/pt-attr-setdetachstate.c
new file mode 100644
index 0000000..cf3ebea
--- /dev/null
+++ b/htl/sysdeps/generic/pt-attr-setdetachstate.c
@@ -0,0 +1,40 @@
+/* pthread_attr_setdetachstate.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+__pthread_attr_setdetachstate (pthread_attr_t *attr,
+			     int detachstate)
+{
+  switch (detachstate)
+    {
+    case PTHREAD_CREATE_DETACHED:
+    case PTHREAD_CREATE_JOINABLE:
+      attr->__detachstate = detachstate;
+      break;
+    default:
+      return EINVAL;
+    }
+
+  return 0;
+}
+
+strong_alias (__pthread_attr_setdetachstate, pthread_attr_setdetachstate);
diff --git a/htl/sysdeps/generic/pt-attr-setguardsize.c b/htl/sysdeps/generic/pt-attr-setguardsize.c
new file mode 100644
index 0000000..ab68dba
--- /dev/null
+++ b/htl/sysdeps/generic/pt-attr-setguardsize.c
@@ -0,0 +1,29 @@
+/* pthread_attr_setguardsize.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_setguardsize (pthread_attr_t *attr,
+			   size_t guardsize)
+{
+  attr->__guardsize = guardsize;
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-attr-setinheritsched.c b/htl/sysdeps/generic/pt-attr-setinheritsched.c
new file mode 100644
index 0000000..e4a7368
--- /dev/null
+++ b/htl/sysdeps/generic/pt-attr-setinheritsched.c
@@ -0,0 +1,40 @@
+/* pthread_attr_setinheritsched.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+__pthread_attr_setinheritsched (pthread_attr_t *attr,
+			      int inheritsched)
+{
+  switch (inheritsched)
+    {
+    case PTHREAD_INHERIT_SCHED:
+    case PTHREAD_EXPLICIT_SCHED:
+      attr->__inheritsched = inheritsched;
+      break;
+    default:
+      return EINVAL;
+    }
+
+  return 0;
+}
+
+strong_alias (__pthread_attr_setinheritsched, pthread_attr_setinheritsched);
diff --git a/htl/sysdeps/generic/pt-attr-setschedparam.c b/htl/sysdeps/generic/pt-attr-setschedparam.c
new file mode 100644
index 0000000..201729e
--- /dev/null
+++ b/htl/sysdeps/generic/pt-attr-setschedparam.c
@@ -0,0 +1,40 @@
+/* pthread_attr_getschedparam.  Generic 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.  */
+
+#include <pthread.h>
+#include <sched.h>
+#include <string.h>
+
+#include <pt-internal.h>
+
+int
+__pthread_attr_setschedparam (pthread_attr_t *attr,
+			    const struct sched_param *param)
+{
+  if (memcmp (param, &__pthread_default_attr.__schedparam,
+	      sizeof *param) == 0)
+    {
+      memcpy (&attr->__schedparam, param, sizeof *param);
+      return 0;
+    }
+
+  return ENOTSUP;
+}
+
+strong_alias (__pthread_attr_setschedparam, pthread_attr_setschedparam);
diff --git a/htl/sysdeps/generic/pt-attr-setschedpolicy.c b/htl/sysdeps/generic/pt-attr-setschedpolicy.c
new file mode 100644
index 0000000..070948c
--- /dev/null
+++ b/htl/sysdeps/generic/pt-attr-setschedpolicy.c
@@ -0,0 +1,44 @@
+/* pthread_attr_getschedpolicy.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+__pthread_attr_setschedpolicy (pthread_attr_t *attr,
+			     int policy)
+{
+  switch (policy)
+    {
+    case SCHED_OTHER:
+      attr->__schedpolicy = policy;
+      break;
+
+    case SCHED_FIFO:
+    case SCHED_RR:
+      return ENOTSUP;
+
+    default:
+      return EINVAL;
+    }
+
+  return 0;
+}
+
+strong_alias (__pthread_attr_setschedpolicy, pthread_attr_setschedpolicy);
diff --git a/htl/sysdeps/generic/pt-attr-setscope.c b/htl/sysdeps/generic/pt-attr-setscope.c
new file mode 100644
index 0000000..09c5d84
--- /dev/null
+++ b/htl/sysdeps/generic/pt-attr-setscope.c
@@ -0,0 +1,43 @@
+/* pthread_attr_setscope.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+__pthread_attr_setscope (pthread_attr_t *attr,
+		       int contentionscope)
+{
+  if (contentionscope == __pthread_default_attr.__contentionscope)
+    {
+      attr->__contentionscope = contentionscope;
+      return 0;
+    }
+
+  switch (contentionscope)
+    {
+    case PTHREAD_SCOPE_PROCESS:
+    case PTHREAD_SCOPE_SYSTEM:
+      return ENOTSUP;
+    default:
+      return EINVAL;
+    }
+}
+
+strong_alias (__pthread_attr_setscope, pthread_attr_setscope);
diff --git a/htl/sysdeps/generic/pt-attr-setstack.c b/htl/sysdeps/generic/pt-attr-setstack.c
new file mode 100644
index 0000000..360d27a
--- /dev/null
+++ b/htl/sysdeps/generic/pt-attr-setstack.c
@@ -0,0 +1,51 @@
+/* pthread_attr_setstack.  Generic 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.  */
+
+#include <pthread.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+int
+pthread_attr_setstack (pthread_attr_t *attr,
+		       void *stackaddr,
+		       size_t stacksize)
+{
+  int err;
+  size_t s;
+
+  /* pthread_attr_setstack should always succeed, thus we set the size
+     first as it is more discriminating.  */
+  pthread_attr_getstacksize (attr, &s);
+
+  err = pthread_attr_setstacksize (attr, stacksize);
+  if (err)
+    return err;
+
+  err = pthread_attr_setstackaddr (attr, stackaddr);
+  if (err)
+    {
+      int e = pthread_attr_setstacksize (attr, s);
+      assert_perror (e);
+
+      return err;
+    }
+      
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-attr-setstackaddr.c b/htl/sysdeps/generic/pt-attr-setstackaddr.c
new file mode 100644
index 0000000..2e292e5
--- /dev/null
+++ b/htl/sysdeps/generic/pt-attr-setstackaddr.c
@@ -0,0 +1,29 @@
+/* pthread_attr_setstackaddr.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_setstackaddr (pthread_attr_t *attr,
+			   void *stackaddr)
+{
+  attr->__stackaddr = stackaddr;
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-attr-setstacksize.c b/htl/sysdeps/generic/pt-attr-setstacksize.c
new file mode 100644
index 0000000..da754d7
--- /dev/null
+++ b/htl/sysdeps/generic/pt-attr-setstacksize.c
@@ -0,0 +1,30 @@
+/* pthread_attr_setstacksize.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_setstacksize (pthread_attr_t *attr,
+			   size_t stacksize)
+{
+  attr->__stacksize = stacksize;
+
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-attr.c b/htl/sysdeps/generic/pt-attr.c
new file mode 100644
index 0000000..48d8323
--- /dev/null
+++ b/htl/sysdeps/generic/pt-attr.c
@@ -0,0 +1,41 @@
+/* Default attributes.  Generic version.
+   Copyright (C) 2000,02 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 <pthread.h>
+#include <sched.h>
+#include <stddef.h>
+#include <limits.h>
+
+#include <pt-internal.h>
+
+const struct __pthread_attr __pthread_default_attr =
+{
+  __schedparam: { __sched_priority: 0 },
+  __stacksize: 0,
+  __stackaddr: NULL,
+#ifdef PAGESIZE
+  __guardsize: PAGESIZE,
+#else
+  __guardsize: 1,
+#endif /* PAGESIZE */
+  __detachstate: PTHREAD_CREATE_JOINABLE,
+  __inheritsched: PTHREAD_EXPLICIT_SCHED,
+  __contentionscope: PTHREAD_SCOPE_SYSTEM,
+  __schedpolicy: SCHED_OTHER
+};
diff --git a/htl/sysdeps/generic/pt-barrier-destroy.c b/htl/sysdeps/generic/pt-barrier-destroy.c
new file mode 100644
index 0000000..01b938b
--- /dev/null
+++ b/htl/sysdeps/generic/pt-barrier-destroy.c
@@ -0,0 +1,27 @@
+/* pthread_barrier_destroy.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_barrier_destroy (pthread_barrier_t *barrier)
+{
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-barrier-init.c b/htl/sysdeps/generic/pt-barrier-init.c
new file mode 100644
index 0000000..056dd1f
--- /dev/null
+++ b/htl/sysdeps/generic/pt-barrier-init.c
@@ -0,0 +1,53 @@
+/* pthread_barrier_init.  Generic version.
+   Copyright (C) 2002, 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 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 <pthread.h>
+#include <string.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+int
+pthread_barrier_init (pthread_barrier_t *barrier,
+		      const pthread_barrierattr_t *attr,
+		      unsigned count)
+{
+  if (count == 0)
+    return EINVAL;
+
+  memset (barrier, 0, sizeof *barrier);
+
+  barrier->__lock = PTHREAD_SPINLOCK_INITIALIZER;
+  barrier->__pending = count;
+  barrier->__count = count;
+
+  if (! attr
+      || memcmp (attr, &__pthread_default_barrierattr, sizeof (*attr) == 0))
+    /* Use the default attributes.  */
+    return 0;
+
+  /* Non-default attributes.  */
+
+  barrier->__attr = malloc (sizeof *attr);
+  if (! barrier->__attr)
+    return ENOMEM;
+
+  *barrier->__attr = *attr;
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-barrier-wait.c b/htl/sysdeps/generic/pt-barrier-wait.c
new file mode 100644
index 0000000..2dd1cc3
--- /dev/null
+++ b/htl/sysdeps/generic/pt-barrier-wait.c
@@ -0,0 +1,69 @@
+/* pthread_barrier_wait.  Generic 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.  */
+
+#include <pthread.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+int
+pthread_barrier_wait (pthread_barrier_t *barrier)
+{
+  __pthread_spin_lock (&barrier->__lock);
+  if (-- barrier->__pending == 0)
+    {
+      barrier->__pending = barrier->__count;
+
+      if (barrier->__count > 1)
+	{
+	  struct __pthread *wakeup;
+	  unsigned n = 0;
+
+	  __pthread_queue_iterate (barrier->__queue, wakeup)
+	    n ++;
+
+	  {
+	    struct __pthread *wakeups[n];
+	    unsigned i = 0;
+
+	    __pthread_dequeuing_iterate (barrier->__queue, wakeup)
+	      wakeups[i ++] = wakeup;
+
+	    barrier->__queue = NULL;
+	    __pthread_spin_unlock (&barrier->__lock);
+
+	    for (i = 0; i < n; i ++)
+	      __pthread_wakeup (wakeups[i]);
+	  }
+	}
+
+      return PTHREAD_BARRIER_SERIAL_THREAD;
+    }
+  else
+    {
+      struct __pthread *self = _pthread_self ();
+
+      /* Add ourselves to the list of waiters.  */
+      __pthread_enqueue (&barrier->__queue, self);
+      __pthread_spin_unlock (&barrier->__lock);
+
+      __pthread_block (self);
+      return 0;
+    }
+}
diff --git a/htl/sysdeps/generic/pt-barrier.c b/htl/sysdeps/generic/pt-barrier.c
new file mode 100644
index 0000000..28a2ef1
--- /dev/null
+++ b/htl/sysdeps/generic/pt-barrier.c
@@ -0,0 +1,26 @@
+/* Default barrier attributes.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+const struct __pthread_barrierattr __pthread_default_barrierattr =
+{
+  __pshared: PTHREAD_PROCESS_PRIVATE
+};
diff --git a/htl/sysdeps/generic/pt-barrierattr-destroy.c b/htl/sysdeps/generic/pt-barrierattr-destroy.c
new file mode 100644
index 0000000..eb39634
--- /dev/null
+++ b/htl/sysdeps/generic/pt-barrierattr-destroy.c
@@ -0,0 +1,27 @@
+/* pthread_barrierattr_destroy.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_barrierattr_destroy (pthread_barrierattr_t *attr)
+{
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-barrierattr-getpshared.c b/htl/sysdeps/generic/pt-barrierattr-getpshared.c
new file mode 100644
index 0000000..f87f2ae
--- /dev/null
+++ b/htl/sysdeps/generic/pt-barrierattr-getpshared.c
@@ -0,0 +1,29 @@
+/* pthread_barrierattr_getpshared.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_barrierattr_getpshared (const pthread_barrierattr_t *attr,
+				int *pshared)
+{
+  *pshared = attr->__pshared;
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-barrierattr-init.c b/htl/sysdeps/generic/pt-barrierattr-init.c
new file mode 100644
index 0000000..45f16cc
--- /dev/null
+++ b/htl/sysdeps/generic/pt-barrierattr-init.c
@@ -0,0 +1,28 @@
+/* pthread_barrierattr_init.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_barrierattr_init (pthread_barrierattr_t *attr)
+{
+  *attr = __pthread_default_barrierattr;
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-barrierattr-setpshared.c b/htl/sysdeps/generic/pt-barrierattr-setpshared.c
new file mode 100644
index 0000000..ecad630
--- /dev/null
+++ b/htl/sysdeps/generic/pt-barrierattr-setpshared.c
@@ -0,0 +1,39 @@
+/* pthread_barrierattr_setpshared.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_barrierattr_setpshared (pthread_barrierattr_t *attr,
+				int pshared)
+{
+  switch (pshared)
+    {
+    case PTHREAD_PROCESS_PRIVATE:
+      attr->__pshared = pshared;
+      return 0;
+
+    case PTHREAD_PROCESS_SHARED:
+      return ENOTSUP;
+
+    default:
+      return EINVAL;
+    }
+}
diff --git a/htl/sysdeps/generic/pt-cond-brdcast.c b/htl/sysdeps/generic/pt-cond-brdcast.c
new file mode 100644
index 0000000..f2a2987
--- /dev/null
+++ b/htl/sysdeps/generic/pt-cond-brdcast.c
@@ -0,0 +1,45 @@
+/* Broadcast a condition.  Generic version.
+   Copyright (C) 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 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 <pthread.h>
+
+#include <pt-internal.h>
+
+/* Unblock all threads that are blocked on condition variable COND.  */
+int
+__pthread_cond_broadcast (pthread_cond_t *cond)
+{
+  struct __pthread *wakeup;
+
+  __pthread_spin_lock (&cond->__lock);
+  while ((wakeup = cond->__queue))
+    {
+      __pthread_dequeue (wakeup);
+      __pthread_spin_unlock (&cond->__lock);
+      /* Wake it up without spin held, so it may have a chance to really
+        preempt us */
+      __pthread_wakeup (wakeup);
+      __pthread_spin_lock (&cond->__lock);
+    }
+  __pthread_spin_unlock (&cond->__lock);
+
+  return 0;
+}
+
+strong_alias (__pthread_cond_broadcast, pthread_cond_broadcast);
diff --git a/htl/sysdeps/generic/pt-cond-destroy.c b/htl/sysdeps/generic/pt-cond-destroy.c
new file mode 100644
index 0000000..d72ea75
--- /dev/null
+++ b/htl/sysdeps/generic/pt-cond-destroy.c
@@ -0,0 +1,29 @@
+/* pthread_cond_destroy.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+__pthread_cond_destroy (pthread_cond_t *cond)
+{
+  return 0;
+}
+
+strong_alias (__pthread_cond_destroy, pthread_cond_destroy);
diff --git a/htl/sysdeps/generic/pt-cond-init.c b/htl/sysdeps/generic/pt-cond-init.c
new file mode 100644
index 0000000..350f2eb
--- /dev/null
+++ b/htl/sysdeps/generic/pt-cond-init.c
@@ -0,0 +1,47 @@
+/* pthread_cond_init.  Generic 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.  */
+
+#include <pthread.h>
+#include <assert.h>
+#include <string.h>
+
+#include <pt-internal.h>
+
+int
+__pthread_cond_init (pthread_cond_t *cond,
+		   const pthread_condattr_t *attr)
+{
+  *cond = (pthread_cond_t) __PTHREAD_COND_INITIALIZER;
+
+  if (! attr
+      || memcmp (attr, &__pthread_default_condattr, sizeof (*attr) == 0))
+    /* Use the default attributes.  */
+    return 0;
+
+  /* Non-default attributes.  */
+
+  cond->__attr = malloc (sizeof *attr);
+  if (! cond->__attr)
+    return ENOMEM;
+
+  *cond->__attr = *attr;
+  return 0;
+}
+
+strong_alias (__pthread_cond_init, pthread_cond_init);
diff --git a/htl/sysdeps/generic/pt-cond-signal.c b/htl/sysdeps/generic/pt-cond-signal.c
new file mode 100644
index 0000000..4b5450c
--- /dev/null
+++ b/htl/sysdeps/generic/pt-cond-signal.c
@@ -0,0 +1,43 @@
+/* Signal a condition.  Generic version.
+   Copyright (C) 2000 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 <pthread.h>
+
+#include <pt-internal.h>
+
+/* Unblock at least one of the threads that are blocked on condition
+   variable COND.  */
+int
+__pthread_cond_signal (pthread_cond_t *cond)
+{
+  struct __pthread *wakeup;
+  
+  __pthread_spin_lock (&cond->__lock);
+  wakeup = cond->__queue;
+  if (wakeup)
+    __pthread_dequeue (wakeup);
+  __pthread_spin_unlock (&cond->__lock);
+
+  if (wakeup)
+    __pthread_wakeup (wakeup);
+
+  return 0;
+}
+
+strong_alias (__pthread_cond_signal, pthread_cond_signal);
diff --git a/htl/sysdeps/generic/pt-cond-timedwait.c b/htl/sysdeps/generic/pt-cond-timedwait.c
new file mode 100644
index 0000000..e44d9ad
--- /dev/null
+++ b/htl/sysdeps/generic/pt-cond-timedwait.c
@@ -0,0 +1,178 @@
+/* Wait on a condition.  Generic version.
+   Copyright (C) 2000, 2002, 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 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 <pthread.h>
+
+#include <pt-internal.h>
+
+extern int __pthread_cond_timedwait_internal (pthread_cond_t *cond,
+					      pthread_mutex_t *mutex,
+					      const struct timespec *abstime);
+
+int
+__pthread_cond_timedwait (pthread_cond_t *cond,
+			pthread_mutex_t *mutex,
+			const struct timespec *abstime)
+{
+  return __pthread_cond_timedwait_internal (cond, mutex, abstime);
+}
+
+strong_alias (__pthread_cond_timedwait, pthread_cond_timedwait);
+
+struct cancel_ctx
+  {
+    struct __pthread *wakeup;
+    pthread_cond_t *cond;
+  };
+
+static void
+cancel_hook (void *arg)
+{
+  struct cancel_ctx *ctx = arg;
+  struct __pthread *wakeup = ctx->wakeup;
+  pthread_cond_t *cond = ctx->cond;
+  int unblock;
+
+  __pthread_spin_lock (&cond->__lock);
+  /* The thread only needs to be awaken if it's blocking or about to block.
+     If it was already unblocked, it's not queued any more.  */
+  unblock = wakeup->prevp != NULL;
+  if (unblock)
+    __pthread_dequeue (wakeup);
+  __pthread_spin_unlock (&cond->__lock);
+
+  if (unblock)
+    __pthread_wakeup (wakeup);
+}
+
+/* Block on condition variable COND until ABSTIME.  As a GNU
+   extension, if ABSTIME is NULL, then wait forever.  MUTEX should be
+   held by the calling thread.  On return, MUTEX will be held by the
+   calling thread.  */
+int
+__pthread_cond_timedwait_internal (pthread_cond_t *cond,
+				   pthread_mutex_t *mutex,
+				   const struct timespec *abstime)
+{
+  error_t err;
+  int cancelled, oldtype, drain;
+  clockid_t clock_id = __pthread_default_condattr.__clock;
+
+  if (abstime && (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000))
+    return EINVAL;
+
+  struct __pthread *self = _pthread_self ();
+  struct cancel_ctx ctx;
+  ctx.wakeup= self;
+  ctx.cond = cond;
+
+  /* Test for a pending cancellation request, switch to deferred mode for
+     safer resource handling, and prepare the hook to call in case we're
+     cancelled while blocking.  Once CANCEL_LOCK is released, the cancellation
+     hook can be called by another thread at any time.  Whatever happens,
+     this function must exit with MUTEX locked.
+
+     This function contains inline implementations of pthread_testcancel and
+     pthread_setcanceltype to reduce locking overhead.  */
+  __pthread_mutex_lock (&self->cancel_lock);
+  cancelled = (self->cancel_state == PTHREAD_CANCEL_ENABLE)
+	      && self->cancel_pending;
+
+  if (! cancelled)
+    {
+      self->cancel_hook = cancel_hook;
+      self->cancel_hook_arg = &ctx;
+      oldtype = self->cancel_type;
+
+      if (oldtype != PTHREAD_CANCEL_DEFERRED)
+	self->cancel_type = PTHREAD_CANCEL_DEFERRED;
+
+      /* Add ourselves to the list of waiters.  This is done while setting
+	 the cancellation hook to simplify the cancellation procedure, i.e.
+	 if the thread is queued, it can be cancelled, otherwise it is
+	 already unblocked, progressing on the return path.  */
+      __pthread_spin_lock (&cond->__lock);
+      __pthread_enqueue (&cond->__queue, self);
+      if (cond->__attr)
+	clock_id = cond->__attr->__clock;
+      __pthread_spin_unlock (&cond->__lock);
+    }
+  __pthread_mutex_unlock (&self->cancel_lock);
+
+  if (cancelled)
+    pthread_exit (PTHREAD_CANCELED);
+
+  /* Release MUTEX before blocking.  */
+  __pthread_mutex_unlock (mutex);
+
+  /* Block the thread.  */
+  if (abstime)
+    err = __pthread_timedblock (self, abstime, clock_id);
+  else
+    {
+      err = 0;
+      __pthread_block (self);
+    }
+
+  __pthread_spin_lock (&cond->__lock);
+  if (! self->prevp)
+    {
+      /* Another thread removed us from the list of waiters, which means a
+	 wakeup message has been sent.  It was either consumed while we were
+	 blocking, or queued after we timed out and before we acquired the
+	 condition lock, in which case the message queue must be drained.  */
+      if (! err)
+	drain = 0;
+      else
+	{
+	  assert (err == ETIMEDOUT);
+	  drain = 1;
+	}
+    }
+  else
+    {
+      /* We're still in the list of waiters.  Noone attempted to wake us up,
+	 i.e. we timed out.  */
+      assert (err == ETIMEDOUT);
+      __pthread_dequeue (self);
+      drain = 0;
+    }
+  __pthread_spin_unlock (&cond->__lock);
+
+  if (drain)
+    __pthread_block (self);
+
+  /* We're almost done.  Remove the unblock hook, restore the previous
+     cancellation type, and check for a pending cancellation request.  */
+  __pthread_mutex_lock (&self->cancel_lock);
+  self->cancel_hook = NULL;
+  self->cancel_hook_arg = NULL;
+  self->cancel_type = oldtype;
+  cancelled = (self->cancel_state == PTHREAD_CANCEL_ENABLE)
+	      && self->cancel_pending;
+  __pthread_mutex_unlock (&self->cancel_lock);
+
+  /* Reacquire MUTEX before returning/cancelling.  */
+  __pthread_mutex_lock (mutex);
+
+  if (cancelled)
+    pthread_exit (PTHREAD_CANCELED);
+
+  return err;
+}
diff --git a/htl/sysdeps/generic/pt-cond-wait.c b/htl/sysdeps/generic/pt-cond-wait.c
new file mode 100644
index 0000000..38a2ae6
--- /dev/null
+++ b/htl/sysdeps/generic/pt-cond-wait.c
@@ -0,0 +1,39 @@
+/* Wait on a condition.  Generic version.
+   Copyright (C) 2000,02 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 <pthread.h>
+
+#include <pt-internal.h>
+
+/* Implemented in pt-cond-timedwait.c.  */
+extern int __pthread_cond_timedwait_internal (pthread_cond_t *cond,
+					      pthread_mutex_t *mutex,
+					      const struct timespec *abstime);
+
+
+/* Block on condition variable COND.  MUTEX should be held by the
+   calling thread.  On return, MUTEX will be held by the calling
+   thread.  */
+int
+__pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex)
+{
+  return __pthread_cond_timedwait_internal (cond, mutex, 0);
+}
+
+strong_alias (__pthread_cond_wait, pthread_cond_wait);
diff --git a/htl/sysdeps/generic/pt-cond.c b/htl/sysdeps/generic/pt-cond.c
new file mode 100644
index 0000000..05f0520
--- /dev/null
+++ b/htl/sysdeps/generic/pt-cond.c
@@ -0,0 +1,29 @@
+/* Default condition attributes.  Generic 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.  */
+
+#include <pthread.h>
+#include <time.h>
+
+#include <pt-internal.h>
+
+const struct __pthread_condattr __pthread_default_condattr =
+{
+  __pshared: PTHREAD_PROCESS_PRIVATE,
+  __clock: CLOCK_REALTIME
+};
diff --git a/htl/sysdeps/generic/pt-condattr-destroy.c b/htl/sysdeps/generic/pt-condattr-destroy.c
new file mode 100644
index 0000000..9fd55b1
--- /dev/null
+++ b/htl/sysdeps/generic/pt-condattr-destroy.c
@@ -0,0 +1,29 @@
+/* pthread_condattr_destroy.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+__pthread_condattr_destroy (pthread_condattr_t *cond)
+{
+  return 0;
+}
+
+strong_alias (__pthread_condattr_destroy, pthread_condattr_destroy);
diff --git a/htl/sysdeps/generic/pt-condattr-getclock.c b/htl/sysdeps/generic/pt-condattr-getclock.c
new file mode 100644
index 0000000..4885b13
--- /dev/null
+++ b/htl/sysdeps/generic/pt-condattr-getclock.c
@@ -0,0 +1,31 @@
+/* pthread_condattr_getclock.  Generic 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.  */
+
+#include <pthread.h>
+#include <time.h>
+
+#include <pt-internal.h>
+
+int
+pthread_condattr_getclock (const pthread_condattr_t *attr,
+			   clockid_t *clock)
+{
+  *clock = attr->__clock;
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-condattr-getpshared.c b/htl/sysdeps/generic/pt-condattr-getpshared.c
new file mode 100644
index 0000000..a27dbc4
--- /dev/null
+++ b/htl/sysdeps/generic/pt-condattr-getpshared.c
@@ -0,0 +1,29 @@
+/* pthread_condattr_getpshared.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_condattr_getpshared (const pthread_condattr_t *attr,
+			     int *pshared)
+{
+  *pshared = attr->__pshared;
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-condattr-init.c b/htl/sysdeps/generic/pt-condattr-init.c
new file mode 100644
index 0000000..8570fd1
--- /dev/null
+++ b/htl/sysdeps/generic/pt-condattr-init.c
@@ -0,0 +1,30 @@
+/* pthread_condattr_init.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+__pthread_condattr_init (pthread_condattr_t *attr)
+{
+  *attr = __pthread_default_condattr;
+  return 0;
+}
+
+strong_alias (__pthread_condattr_init, pthread_condattr_init);
diff --git a/htl/sysdeps/generic/pt-condattr-setclock.c b/htl/sysdeps/generic/pt-condattr-setclock.c
new file mode 100644
index 0000000..ad28834
--- /dev/null
+++ b/htl/sysdeps/generic/pt-condattr-setclock.c
@@ -0,0 +1,52 @@
+/* pthread_condattr_setclock.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_condattr_setclock (pthread_condattr_t *attr, clockid_t clock)
+{
+  /* Only a few clocks are allowed.  CLOCK_REALTIME is always allowed.
+     CLOCK_MONOTONIC only if the kernel has the necessary support.  */
+  if (clock == CLOCK_MONOTONIC)
+    {
+      /* Check whether the clock is available.  */
+      static int avail;
+
+      if (avail == 0)
+	{
+	  struct timespec ts;
+	  int res;
+
+	  res = clock_gettime (CLOCK_MONOTONIC, &ts);
+	  avail = res < 0 ? -1 : 1;
+	}
+
+      if (avail < 0)
+	/* Not available.  */
+	return EINVAL;
+    }
+  else if (clock != CLOCK_REALTIME)
+    return EINVAL;
+
+  attr->__clock = clock;
+
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-condattr-setpshared.c b/htl/sysdeps/generic/pt-condattr-setpshared.c
new file mode 100644
index 0000000..0316b4d
--- /dev/null
+++ b/htl/sysdeps/generic/pt-condattr-setpshared.c
@@ -0,0 +1,39 @@
+/* pthread_condattr_setpshared.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_condattr_setpshared (pthread_condattr_t *attr,
+			     int pshared)
+{
+  switch (pshared)
+    {
+    case PTHREAD_PROCESS_PRIVATE:
+      attr->__pshared = pshared;
+      return 0;
+
+    case PTHREAD_PROCESS_SHARED:
+      return ENOTSUP;
+
+    default:
+      return EINVAL;
+    }
+}
diff --git a/htl/sysdeps/generic/pt-destroy-specific.c b/htl/sysdeps/generic/pt-destroy-specific.c
new file mode 100644
index 0000000..642c61c
--- /dev/null
+++ b/htl/sysdeps/generic/pt-destroy-specific.c
@@ -0,0 +1,77 @@
+/* __pthread_destory_specific.  Hurd 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.  */
+
+#include <pthread.h>
+#include <stdlib.h>
+
+#include <pt-internal.h>
+
+void
+__pthread_destroy_specific (struct __pthread *thread)
+{
+  int i;
+  int seen_one;
+
+  /* Check if there is any thread specific data.  */
+  if (! thread->thread_specifics)
+    return;
+
+  __pthread_key_lock_ready ();
+
+  /* Iterate and call the destructors on any thread specific data.  */
+  for (;;)
+    {
+      seen_one = 0;
+
+      __pthread_mutex_lock (&__pthread_key_lock);
+
+      for (i = 0; i < __pthread_key_count && i < thread->thread_specifics_size; i ++)
+	{
+	  void *value;
+
+	  if (__pthread_key_destructors[i] == PTHREAD_KEY_INVALID)
+	    continue;
+
+	  value = thread->thread_specifics[i];
+	  if (value)
+	    {
+	      thread->thread_specifics[i] = 0;
+
+	      if (__pthread_key_destructors[i])
+		{
+		  seen_one = 1;
+		  __pthread_key_destructors[i] (value);
+		}
+	    }
+	}
+
+      __pthread_mutex_unlock (&__pthread_key_lock);
+
+      if (! seen_one)
+	break;
+
+      /* This may take a very long time.  Let those blocking on
+	 pthread_key_create or pthread_key_delete make progress.  */
+      sched_yield ();
+    }
+
+  free (thread->thread_specifics);
+  thread->thread_specifics = 0;
+  thread->thread_specifics_size = 0;
+}
diff --git a/htl/sysdeps/generic/pt-equal.c b/htl/sysdeps/generic/pt-equal.c
new file mode 100644
index 0000000..72fc7e6
--- /dev/null
+++ b/htl/sysdeps/generic/pt-equal.c
@@ -0,0 +1,31 @@
+/* Default attributes.  Generic version.
+   Copyright (C) 2000,02 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 <pthread.h>
+#include <pt-internal.h>
+
+/* Return true if __T1 and __T2 both name the same thread.  Otherwise,
+   false.  */
+int
+__pthread_equal (pthread_t __t1, pthread_t __t2)
+{
+  return __t1 == __t2;
+}
+
+strong_alias (__pthread_equal, pthread_equal);
diff --git a/htl/sysdeps/generic/pt-getconcurrency.c b/htl/sysdeps/generic/pt-getconcurrency.c
new file mode 100644
index 0000000..b55c8ee
--- /dev/null
+++ b/htl/sysdeps/generic/pt-getconcurrency.c
@@ -0,0 +1,27 @@
+/* Get the current level of desired concurrency.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_getconcurrency (void)
+{
+  return __pthread_concurrency;
+}
diff --git a/htl/sysdeps/generic/pt-getcpuclockid.c b/htl/sysdeps/generic/pt-getcpuclockid.c
new file mode 100644
index 0000000..03868d3
--- /dev/null
+++ b/htl/sysdeps/generic/pt-getcpuclockid.c
@@ -0,0 +1,35 @@
+/* Return a thread's cpu clockid.  Generic 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.  */
+
+#include <pthread.h>
+#include <time.h>
+
+#include <pt-internal.h>
+
+int
+pthread_getcpuclockid (pthread_t thread, clockid_t *clock)
+{
+#ifdef CLOCK_THREAD_CPUTIME_ID
+  *clock = CLOCK_THREAD_CPUTIME_ID;
+  return 0;
+#else
+  return ENOSYS;
+stub_warning (pthread_getcpuclockid)
+#endif
+}
diff --git a/htl/sysdeps/generic/pt-getschedparam.c b/htl/sysdeps/generic/pt-getschedparam.c
new file mode 100644
index 0000000..5b20421
--- /dev/null
+++ b/htl/sysdeps/generic/pt-getschedparam.c
@@ -0,0 +1,32 @@
+/* Get the scheduling parameters for a thread.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+__pthread_getschedparam (pthread_t thread, int *policy,
+		       struct sched_param *param)
+{
+  *policy = SCHED_OTHER;
+  param->__sched_priority = 0;
+  return 0;
+}
+
+strong_alias (__pthread_getschedparam, pthread_getschedparam);
diff --git a/htl/sysdeps/generic/pt-getspecific.c b/htl/sysdeps/generic/pt-getspecific.c
new file mode 100644
index 0000000..1f49c03
--- /dev/null
+++ b/htl/sysdeps/generic/pt-getspecific.c
@@ -0,0 +1,39 @@
+/* pthread_getspecific.  Hurd 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.  */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+void *
+__pthread_getspecific (pthread_key_t key)
+{
+  struct __pthread *self;
+
+  if (key < 0 || key >= __pthread_key_count
+      || __pthread_key_destructors[key] == PTHREAD_KEY_INVALID)
+    return NULL;
+
+  self = _pthread_self ();
+  if (key >= self->thread_specifics_size)
+    return 0;
+
+  return self->thread_specifics[key];
+}
+strong_alias (__pthread_getspecific, pthread_getspecific);
diff --git a/htl/sysdeps/generic/pt-init-specific.c b/htl/sysdeps/generic/pt-init-specific.c
new file mode 100644
index 0000000..78958cb
--- /dev/null
+++ b/htl/sysdeps/generic/pt-init-specific.c
@@ -0,0 +1,31 @@
+/* __pthread_init_specific.  Hurd 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.  */
+
+#include <pthread.h>
+#include <stdlib.h>
+
+#include <pt-internal.h>
+
+error_t
+__pthread_init_specific (struct __pthread *thread)
+{
+  thread->thread_specifics = 0;
+  thread->thread_specifics_size = 0;
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-key-create.c b/htl/sysdeps/generic/pt-key-create.c
new file mode 100644
index 0000000..f26ec36
--- /dev/null
+++ b/htl/sysdeps/generic/pt-key-create.c
@@ -0,0 +1,110 @@
+/* pthread_key_create.  Hurd 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.  */
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+pthread_mutex_t __pthread_key_lock;
+
+void (**__pthread_key_destructors) (void *arg);
+int __pthread_key_size;
+int __pthread_key_count;
+int __pthread_key_invalid_count;
+
+int
+__pthread_key_create (pthread_key_t *key, void (*destructor) (void *))
+{
+  /* Where to look for the next key slot.  */
+  static int index;
+
+  __pthread_key_lock_ready ();
+
+  __pthread_mutex_lock (&__pthread_key_lock);
+
+ do_search:
+  /* Use the search hint and try to find a free slot.  */
+  for (; index < __pthread_key_count
+	 && __pthread_key_destructors[index] != PTHREAD_KEY_INVALID;
+       index ++)
+    ;
+
+  /* See if we actually found a free element.  */
+  if (index < __pthread_key_count)
+    {
+      assert (__pthread_key_destructors[index] == PTHREAD_KEY_INVALID);
+      assert (__pthread_key_invalid_count > 0);
+
+      __pthread_key_invalid_count --;
+      __pthread_key_destructors[index] = destructor;
+      *key = index ++;
+
+      __pthread_mutex_unlock (&__pthread_key_lock);
+      return 0;
+    }
+
+  assert (index == __pthread_key_count);
+
+  /* No space at the end.  */
+  if (__pthread_key_size == __pthread_key_count)
+    {
+      /* See if it is worth looking for a free element.  */
+      if (__pthread_key_invalid_count > 4
+	  && __pthread_key_invalid_count > __pthread_key_size / 8)
+	{
+	  index = 0;
+	  goto do_search;
+	}
+
+
+      /* Resize the array.  */
+      {
+	void *t;
+	int newsize;
+
+	if (__pthread_key_size == 0)
+	  newsize = 8;
+	else
+	  newsize = __pthread_key_size * 2;
+
+	t = realloc (__pthread_key_destructors,
+		     newsize * sizeof (*__pthread_key_destructors));
+	if (! t)
+	  {
+	    __pthread_mutex_unlock (&__pthread_key_lock);
+	    return ENOMEM;
+	  }
+
+	__pthread_key_size = newsize;
+	__pthread_key_destructors = t;
+      }
+    }
+
+  __pthread_key_destructors[index] = destructor;
+  *key = index;
+
+  index ++;
+  __pthread_key_count ++;
+
+  __pthread_mutex_unlock (&__pthread_key_lock);
+  return 0;
+}
+strong_alias (__pthread_key_create, pthread_key_create)
diff --git a/htl/sysdeps/generic/pt-key-delete.c b/htl/sysdeps/generic/pt-key-delete.c
new file mode 100644
index 0000000..499e9f3
--- /dev/null
+++ b/htl/sysdeps/generic/pt-key-delete.c
@@ -0,0 +1,64 @@
+/* pthread_key_delete.  Hurd 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.  */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+int
+pthread_key_delete (pthread_key_t key)
+{
+  error_t err = 0;
+
+  __pthread_key_lock_ready ();
+
+  __pthread_mutex_lock (&__pthread_key_lock);
+
+  if (key < 0 || key >= __pthread_key_count
+      || __pthread_key_destructors[key] == PTHREAD_KEY_INVALID)
+    err = EINVAL;
+  else
+    {
+      int i;
+
+      __pthread_key_destructors[key] = PTHREAD_KEY_INVALID;
+      __pthread_key_invalid_count ++;
+
+      __pthread_rwlock_rdlock (&__pthread_threads_lock);
+      for (i = 0; i < __pthread_num_threads; ++i)
+	{
+	  struct __pthread *t;
+
+	  t = __pthread_threads[i];
+
+	  if (t == NULL)
+	    continue;
+
+	  /* Just remove the key, no need to care whether it was
+	     already there. */
+	  if (key < t->thread_specifics_size)
+	    t->thread_specifics[key] = 0;
+	}
+      __pthread_rwlock_unlock (&__pthread_threads_lock);
+    }
+
+  __pthread_mutex_unlock (&__pthread_key_lock);
+
+  return err;
+}
diff --git a/htl/sysdeps/generic/pt-key.h b/htl/sysdeps/generic/pt-key.h
new file mode 100644
index 0000000..46830d7
--- /dev/null
+++ b/htl/sysdeps/generic/pt-key.h
@@ -0,0 +1,77 @@
+/* pthread_key internal declatations for the Hurd 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.  */
+
+#include <pthread.h>
+#include <libc-lockP.h>
+
+#define PTHREAD_KEY_MEMBERS \
+  void **thread_specifics;		/* This is only resized by the thread, and always growing */ \
+  unsigned thread_specifics_size;	/* Number of entries in thread_specifics */
+
+#define PTHREAD_KEY_INVALID (void *) (-1)
+
+
+/* __PTHREAD_KEY_DESTRUCTORS is an array of destructors with
+   __PTHREAD_KEY_SIZE elements.  If an element with index less than
+   __PTHREAD_KEY_COUNT is invalid, it shall contain the value
+   PTHREAD_KEY_INVALID which shall be distinct from NULL.  
+
+   Normally, we just add new keys to the end of the array and realloc
+   it as necessary.  The pthread_key_create routine may decide to
+   rescan the array if __PTHREAD_KEY_FREE is large.  */
+extern void (**__pthread_key_destructors) (void *arg);
+extern int __pthread_key_size;
+extern int __pthread_key_count;
+/* Number of invalid elements in the array.  Does not include elements
+   for which memory has been allocated but which have not yet been
+   used (i.e. those elements with indexes greater than
+   __PTHREAD_KEY_COUNT).  */
+extern int __pthread_key_invalid_count;
+
+/* Protects the above variables.  This must be a recursive lock: the
+   destructors may call pthread_key_delete.  */
+extern pthread_mutex_t __pthread_key_lock;
+
+#include <assert.h>
+
+static inline void
+__pthread_key_lock_ready (void)
+{
+  static pthread_once_t o = PTHREAD_ONCE_INIT;
+
+  void do_init (void)
+    {
+      int err;
+      pthread_mutexattr_t attr;
+
+      err = __pthread_mutexattr_init (&attr);
+      assert_perror (err);
+
+      err = __pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
+      assert_perror (err);
+
+      err = _pthread_mutex_init (&__pthread_key_lock, &attr);
+      assert_perror (err);
+
+      err = __pthread_mutexattr_destroy (&attr);
+      assert_perror (err);
+    }
+
+  __pthread_once (&o, do_init);
+}
diff --git a/htl/sysdeps/generic/pt-kill.c b/htl/sysdeps/generic/pt-kill.c
new file mode 100644
index 0000000..fc83f93
--- /dev/null
+++ b/htl/sysdeps/generic/pt-kill.c
@@ -0,0 +1,33 @@
+/* pthread-kill.c - Generic pthread-kill implementation.
+   Copyright (C) 2008 Free Software Foundation, Inc.
+   Written by Neal H. Walfield <neal@gnu.org>.
+
+   This file is part of the GNU Hurd.
+
+   The GNU Hurd is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License
+   as published by the Free Software Foundation; either version 3 of
+   the License, or (at your option) any later version.
+
+   The GNU Hurd is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this program.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <pthreadP.h>
+#include "sig-internal.h"
+
+int
+__pthread_kill (pthread_t tid, int signo)
+{
+  siginfo_t si;
+  memset (&si, 0, sizeof (si));
+  si.si_signo = signo;
+
+  return pthread_kill_siginfo_np (tid, si);
+}
+strong_alias (__pthread_kill, pthread_kill)
diff --git a/htl/sysdeps/generic/pt-mutex-destroy.c b/htl/sysdeps/generic/pt-mutex-destroy.c
new file mode 100644
index 0000000..3a3cb89
--- /dev/null
+++ b/htl/sysdeps/generic/pt-mutex-destroy.c
@@ -0,0 +1,39 @@
+/* Destroy a mutex.  Generic version.
+   Copyright (C) 2000, 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 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 <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+int
+_pthread_mutex_destroy (pthread_mutex_t *mutex)
+{
+  if (mutex->__attr == __PTHREAD_ERRORCHECK_MUTEXATTR
+   || mutex->__attr == __PTHREAD_RECURSIVE_MUTEXATTR)
+    /* Static attributes.  */
+    ;
+  else
+    free (mutex->__attr);
+
+  return 0;
+}
+
+strong_alias (_pthread_mutex_destroy, pthread_mutex_destroy);
diff --git a/htl/sysdeps/generic/pt-mutex-getprioceiling.c b/htl/sysdeps/generic/pt-mutex-getprioceiling.c
new file mode 100644
index 0000000..ac886a8
--- /dev/null
+++ b/htl/sysdeps/generic/pt-mutex-getprioceiling.c
@@ -0,0 +1,30 @@
+/* Get a mutex' priority ceiling.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_mutex_getprioceiling (const pthread_mutex_t *mutex,
+			      int *prioceiling)
+{
+  return ENOSYS;
+}
+
+stub_warning (pthread_mutex_getprioceiling)
diff --git a/htl/sysdeps/generic/pt-mutex-init.c b/htl/sysdeps/generic/pt-mutex-init.c
new file mode 100644
index 0000000..7f21511
--- /dev/null
+++ b/htl/sysdeps/generic/pt-mutex-init.c
@@ -0,0 +1,50 @@
+/* Initialize a mutex.  Generic version.
+   Copyright (C) 2000, 2002, 2005, 2006, 2008 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 <pthread.h>
+#include <string.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+int
+_pthread_mutex_init (pthread_mutex_t *mutex,
+		     const pthread_mutexattr_t *attr)
+{
+  *mutex = (pthread_mutex_t) __PTHREAD_MUTEX_INITIALIZER;
+
+  if (! attr
+      || memcmp (attr, &__pthread_default_mutexattr, sizeof (*attr) == 0))
+    /* The default attributes.  */
+    return 0;
+
+  if (! mutex->__attr
+      || mutex->__attr == __PTHREAD_ERRORCHECK_MUTEXATTR
+      || mutex->__attr == __PTHREAD_RECURSIVE_MUTEXATTR)
+    mutex->__attr = malloc (sizeof *attr);
+
+  if (! mutex->__attr)
+    return ENOMEM;
+
+  *mutex->__attr = *attr;
+  return 0;
+}
+
+strong_alias (_pthread_mutex_init, pthread_mutex_init);
diff --git a/htl/sysdeps/generic/pt-mutex-lock.c b/htl/sysdeps/generic/pt-mutex-lock.c
new file mode 100644
index 0000000..528e593
--- /dev/null
+++ b/htl/sysdeps/generic/pt-mutex-lock.c
@@ -0,0 +1,37 @@
+/* Lock a mutex.  Generic version.
+   Copyright (C) 2000, 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 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 <pthread.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+/* Implemented in pt-mutex-timedlock.c.  */
+extern int __pthread_mutex_timedlock_internal (struct __pthread_mutex *mutex,
+					       const struct timespec *abstime);
+
+/* Lock MUTEX, block if we can't get it.  */
+int
+__pthread_mutex_lock (struct __pthread_mutex *mutex)
+{
+  return __pthread_mutex_timedlock_internal (mutex, 0);
+}
+
+strong_alias (__pthread_mutex_lock, _pthread_mutex_lock);
+strong_alias (__pthread_mutex_lock, pthread_mutex_lock);
diff --git a/htl/sysdeps/generic/pt-mutex-setprioceiling.c b/htl/sysdeps/generic/pt-mutex-setprioceiling.c
new file mode 100644
index 0000000..1358b37
--- /dev/null
+++ b/htl/sysdeps/generic/pt-mutex-setprioceiling.c
@@ -0,0 +1,30 @@
+/* Set a mutex' priority ceiling.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_mutex_setprioceiling (pthread_mutex_t *mutex, int prio,
+			      int *oldprio)
+{
+  return ENOSYS;
+}
+
+stub_warning (pthread_mutex_setprioceiling)
diff --git a/htl/sysdeps/generic/pt-mutex-timedlock.c b/htl/sysdeps/generic/pt-mutex-timedlock.c
new file mode 100644
index 0000000..0f8d447
--- /dev/null
+++ b/htl/sysdeps/generic/pt-mutex-timedlock.c
@@ -0,0 +1,196 @@
+/* Lock a mutex with a timeout.  Generic version.
+   Copyright (C) 2000, 2002, 2005, 2008 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 <pthread.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+#define LOSE do { * (int *) 0 = 0; } while (1)
+
+/* Try to lock MUTEX, block until *ABSTIME if it is already held.  As
+   a GNU extension, if TIMESPEC is NULL then wait forever.  */
+int
+__pthread_mutex_timedlock_internal (struct __pthread_mutex *mutex,
+				    const struct timespec *abstime)
+{
+  error_t err;
+  int drain;
+  struct __pthread *self;
+  const struct __pthread_mutexattr *attr = mutex->__attr;
+
+  if (attr == __PTHREAD_ERRORCHECK_MUTEXATTR)
+    attr = &__pthread_errorcheck_mutexattr;
+  if (attr == __PTHREAD_RECURSIVE_MUTEXATTR)
+    attr = &__pthread_recursive_mutexattr;
+
+  __pthread_spin_lock (&mutex->__lock);
+  if (__pthread_spin_trylock (&mutex->__held) == 0)
+    /* Successfully acquired the lock.  */
+    {
+#ifdef ALWAYS_TRACK_MUTEX_OWNER
+#ifndef NDEBUG
+      self = _pthread_self ();
+      if (self)
+	/* The main thread may take a lock before the library is fully
+	   initialized, in particular, before the main thread has a
+	   TCB.  */
+	{
+	  assert (! mutex->__owner);
+	  mutex->__owner = _pthread_self ();
+	}
+#endif
+#endif
+
+      if (attr)
+	switch (attr->__mutex_type)
+	  {
+	  case PTHREAD_MUTEX_NORMAL:
+	    break;
+
+	  case PTHREAD_MUTEX_RECURSIVE:
+	    mutex->__locks = 1;
+	  case PTHREAD_MUTEX_ERRORCHECK:
+	    mutex->__owner = _pthread_self ();
+	    break;
+
+	  default:
+	    LOSE;
+	  }
+
+      __pthread_spin_unlock (&mutex->__lock);
+      return 0;
+    }
+
+  /* The lock is busy.  */
+
+  self = _pthread_self ();
+  assert (self);
+
+  if (! attr || attr->__mutex_type == PTHREAD_MUTEX_NORMAL)
+    {
+#if defined(ALWAYS_TRACK_MUTEX_OWNER)
+      assert (mutex->__owner != self);
+#endif
+    }
+  else
+    {
+      switch (attr->__mutex_type)
+	{
+	case PTHREAD_MUTEX_ERRORCHECK:
+	  if (mutex->__owner == self)
+	    {
+	      __pthread_spin_unlock (&mutex->__lock);
+	      return EDEADLK;
+	    }
+	  break;
+
+	case PTHREAD_MUTEX_RECURSIVE:
+	  if (mutex->__owner == self)
+	    {
+	      mutex->__locks ++;
+	      __pthread_spin_unlock (&mutex->__lock);
+	      return 0;
+	    }
+	  break;
+
+	default:
+	  LOSE;
+	}
+    }
+
+#if !defined(ALWAYS_TRACK_MUTEX_OWNER)
+  if (attr && attr->__mutex_type != PTHREAD_MUTEX_NORMAL)
+#endif
+    assert (mutex->__owner);
+
+  if (abstime && (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000))
+    return EINVAL;
+
+  /* Add ourselves to the queue.  */
+  __pthread_enqueue (&mutex->__queue, self);
+  __pthread_spin_unlock (&mutex->__lock);
+
+  /* Block the thread.  */
+  if (abstime)
+    err = __pthread_timedblock (self, abstime, CLOCK_REALTIME);
+  else
+    {
+      err = 0;
+      __pthread_block (self);
+    }
+
+  __pthread_spin_lock (&mutex->__lock);
+  if (! self->prevp)
+    /* Another thread removed us from the queue, which means a wakeup message
+       has been sent.  It was either consumed while we were blocking, or
+       queued after we timed out and before we acquired the mutex lock, in
+       which case the message queue must be drained.  */
+    drain = err ? 1 : 0;
+  else
+    {
+      /* We're still in the queue.  Noone attempted to wake us up, i.e. we
+	 timed out.  */
+      __pthread_dequeue (self);
+      drain = 0;
+    }
+  __pthread_spin_unlock (&mutex->__lock);
+
+  if (drain)
+    __pthread_block (self);
+
+  if (err)
+    {
+      assert (err == ETIMEDOUT);
+      return err;
+    }
+
+#if !defined(ALWAYS_TRACK_MUTEX_OWNER)
+  if (attr && attr->__mutex_type != PTHREAD_MUTEX_NORMAL)
+#endif
+    {
+      assert (mutex->__owner == self);
+    }
+
+  if (attr)
+    switch (attr->__mutex_type)
+      {
+      case PTHREAD_MUTEX_NORMAL:
+	break;
+
+      case PTHREAD_MUTEX_RECURSIVE:
+	assert (mutex->__locks == 0);
+	mutex->__locks = 1;
+      case PTHREAD_MUTEX_ERRORCHECK:
+	mutex->__owner = self;
+	break;
+
+      default:
+	LOSE;
+      }
+
+  return 0;
+}
+
+int
+pthread_mutex_timedlock (struct __pthread_mutex *mutex,
+			 const struct timespec *abstime)
+{
+  return __pthread_mutex_timedlock_internal (mutex, abstime);
+}
diff --git a/htl/sysdeps/generic/pt-mutex-transfer-np.c b/htl/sysdeps/generic/pt-mutex-transfer-np.c
new file mode 100644
index 0000000..21fc040
--- /dev/null
+++ b/htl/sysdeps/generic/pt-mutex-transfer-np.c
@@ -0,0 +1,66 @@
+/* Transfer ownership of a mutex.  Generic version.
+   Copyright (C) 2008 Free Software Foundation, Inc.
+   Written by Neal H. Walfield <neal@gnu.org>.
+
+   This file is part of the GNU Hurd.
+
+   The GNU Hurd is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License
+   as published by the Free Software Foundation; either version 3 of
+   the License, or (at your option) any later version.
+
+   The GNU Hurd is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this program.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <pthread.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+int
+__pthread_mutex_transfer_np (struct __pthread_mutex *mutex, pthread_t tid)
+{
+  assert (mutex->__owner == _pthread_self ());
+
+  struct __pthread *thread = __pthread_getid (tid);
+  const struct __pthread_mutexattr *attr = mutex->__attr;
+
+  if (! thread)
+    return ESRCH;
+
+  if (thread == _pthread_self ())
+    return 0;
+
+  if (attr == __PTHREAD_ERRORCHECK_MUTEXATTR)
+    attr = &__pthread_errorcheck_mutexattr;
+  if (attr == __PTHREAD_RECURSIVE_MUTEXATTR)
+    attr = &__pthread_recursive_mutexattr;
+
+  if (attr && attr->__mutex_type == PTHREAD_MUTEX_ERRORCHECK)
+    {
+
+      if (mutex->__owner != _pthread_self ())
+	return EPERM;
+
+      mutex->__owner = thread;
+    }
+
+#ifndef NDEBUG
+# if !defined(ALWAYS_TRACK_MUTEX_OWNER)
+  if (attr && attr->__mutex_type != PTHREAD_MUTEX_NORMAL)
+# endif
+    {
+      mutex->__owner = thread;
+    }
+#endif
+
+  return 0;
+}
+
+strong_alias (__pthread_mutex_transfer_np, pthread_mutex_transfer_np)
diff --git a/htl/sysdeps/generic/pt-mutex-trylock.c b/htl/sysdeps/generic/pt-mutex-trylock.c
new file mode 100644
index 0000000..0d5ce7d
--- /dev/null
+++ b/htl/sysdeps/generic/pt-mutex-trylock.c
@@ -0,0 +1,112 @@
+/* Try to Lock a mutex.  Generic version.
+   Copyright (C) 2002, 2005, 2008 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 <pthread.h>
+
+#include <pt-internal.h>
+
+#define LOSE do { * (int *) 0 = 0; } while (1)
+
+/* Lock MUTEX, return EBUSY if we can't get it.  */
+int
+__pthread_mutex_trylock (struct __pthread_mutex *mutex)
+{
+  int err;
+  struct __pthread *self;
+  const struct __pthread_mutexattr *attr = mutex->__attr;
+
+  if (attr == __PTHREAD_ERRORCHECK_MUTEXATTR)
+    attr = &__pthread_errorcheck_mutexattr;
+  if (attr == __PTHREAD_RECURSIVE_MUTEXATTR)
+    attr = &__pthread_recursive_mutexattr;
+
+  __pthread_spin_lock (&mutex->__lock);
+  if (__pthread_spin_trylock (&mutex->__held) == 0)
+    /* Acquired the lock.  */
+    {
+#if defined(ALWAYS_TRACK_MUTEX_OWNER)
+#ifndef NDEBUG
+      self = _pthread_self ();
+      if (self)
+	/* The main thread may take a lock before the library is fully
+	   initialized, in particular, before the main thread has a
+	   TCB.  */
+	{
+	  assert (! mutex->__owner);
+	  mutex->__owner = _pthread_self ();
+	}
+#endif
+#endif
+
+      if (attr)
+	switch (attr->__mutex_type)
+	  {
+	  case PTHREAD_MUTEX_NORMAL:
+	    break;
+
+	  case PTHREAD_MUTEX_RECURSIVE:
+	    mutex->__locks = 1;
+	  case PTHREAD_MUTEX_ERRORCHECK:
+	    mutex->__owner = _pthread_self ();
+	    break;
+
+	  default:
+	    LOSE;
+	  }
+
+      __pthread_spin_unlock (&mutex->__lock);
+      return 0;
+    }
+
+  err = EBUSY;
+
+  if (attr)
+    {
+      self = _pthread_self ();
+      switch (attr->__mutex_type)
+	{
+	case PTHREAD_MUTEX_NORMAL:
+	  break;
+
+	case PTHREAD_MUTEX_ERRORCHECK:
+	  /* We could check if MUTEX->OWNER is SELF, however, POSIX
+	     does not permit pthread_mutex_trylock to return EDEADLK
+	     instead of EBUSY, only pthread_mutex_lock.  */
+	  break;
+
+	case PTHREAD_MUTEX_RECURSIVE:
+	  if (mutex->__owner == self)
+	    {
+	      mutex->__locks ++;
+	      err = 0;
+	    }
+	  break;
+
+	default:
+	  LOSE;
+	}
+    }
+
+  __pthread_spin_unlock (&mutex->__lock);
+
+  return err;
+}
+
+strong_alias (__pthread_mutex_trylock, _pthread_mutex_trylock);
+strong_alias (__pthread_mutex_trylock, pthread_mutex_trylock);
diff --git a/htl/sysdeps/generic/pt-mutex-unlock.c b/htl/sysdeps/generic/pt-mutex-unlock.c
new file mode 100644
index 0000000..08f5975
--- /dev/null
+++ b/htl/sysdeps/generic/pt-mutex-unlock.c
@@ -0,0 +1,108 @@
+/* Unlock a mutex.  Generic version.
+   Copyright (C) 2000, 2002, 2008 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 <pthread.h>
+
+#include <pt-internal.h>
+
+#define LOSE do { * (int *) 0 = 0; } while (1)
+
+/* Unlock MUTEX, rescheduling a waiting thread.  */
+int
+__pthread_mutex_unlock (pthread_mutex_t *mutex)
+{
+  struct __pthread *wakeup;
+  const struct __pthread_mutexattr *attr = mutex->__attr;
+
+  if (attr == __PTHREAD_ERRORCHECK_MUTEXATTR)
+    attr = &__pthread_errorcheck_mutexattr;
+  if (attr == __PTHREAD_RECURSIVE_MUTEXATTR)
+    attr = &__pthread_recursive_mutexattr;
+
+  __pthread_spin_lock (&mutex->__lock);
+
+  if (! attr || attr->__mutex_type == PTHREAD_MUTEX_NORMAL)
+    {
+#if defined(ALWAYS_TRACK_MUTEX_OWNER)
+# ifndef NDEBUG
+      if (_pthread_self ())
+	{
+	  assert (mutex->__owner);
+	  assert (mutex->__owner == _pthread_self ());
+	  mutex->__owner = NULL;
+	}
+# endif
+#endif
+    }
+  else
+    switch (attr->__mutex_type)
+      {
+      case PTHREAD_MUTEX_ERRORCHECK:
+      case PTHREAD_MUTEX_RECURSIVE:
+	if (mutex->__owner != _pthread_self ())
+	  {
+	    __pthread_spin_unlock (&mutex->__lock);
+	    return EPERM;
+	  }
+
+	if (attr->__mutex_type == PTHREAD_MUTEX_RECURSIVE)
+	  if (--mutex->__locks > 0)
+	    {
+	      __pthread_spin_unlock (&mutex->__lock);
+	      return 0;
+	    }
+
+	mutex->__owner = 0;
+	break;
+
+      default:
+	LOSE;
+      }
+
+
+  if (mutex->__queue == NULL)
+    {
+      __pthread_spin_unlock (&mutex->__held);
+      __pthread_spin_unlock (&mutex->__lock);
+      return 0;
+    }
+
+  wakeup = mutex->__queue;
+  __pthread_dequeue (wakeup);
+
+#ifndef NDEBUG
+# if !defined (ALWAYS_TRACK_MUTEX_OWNER)
+  if (attr && attr->__mutex_type != PTHREAD_MUTEX_NORMAL)
+# endif
+    {
+      mutex->__owner = wakeup;
+    }
+#endif
+
+  /* We do not unlock MUTEX->held: we are transferring the ownership
+     to the thread that we are waking up.  */
+
+  __pthread_spin_unlock (&mutex->__lock);
+  __pthread_wakeup (wakeup);
+
+  return 0;
+}
+
+strong_alias (__pthread_mutex_unlock, _pthread_mutex_unlock);
+strong_alias (__pthread_mutex_unlock, pthread_mutex_unlock);
diff --git a/htl/sysdeps/generic/pt-mutexattr-destroy.c b/htl/sysdeps/generic/pt-mutexattr-destroy.c
new file mode 100644
index 0000000..fc0479b
--- /dev/null
+++ b/htl/sysdeps/generic/pt-mutexattr-destroy.c
@@ -0,0 +1,28 @@
+/* pthread_mutexattr_destroy.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+__pthread_mutexattr_destroy (pthread_mutexattr_t *attr)
+{
+  return 0;
+}
+weak_alias (__pthread_mutexattr_destroy, pthread_mutexattr_destroy)
diff --git a/htl/sysdeps/generic/pt-mutexattr-getprioceiling.c b/htl/sysdeps/generic/pt-mutexattr-getprioceiling.c
new file mode 100644
index 0000000..4865676
--- /dev/null
+++ b/htl/sysdeps/generic/pt-mutexattr-getprioceiling.c
@@ -0,0 +1,30 @@
+/* pthread_mutexattr_getprioceiling.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_mutexattr_getprioceiling (const pthread_mutexattr_t *attr,
+				  int *prioceiling)
+{
+  return ENOSYS;
+}
+
+stub_warning (pthread_mutexattr_getprioceiling)
diff --git a/htl/sysdeps/generic/pt-mutexattr-getprotocol.c b/htl/sysdeps/generic/pt-mutexattr-getprotocol.c
new file mode 100644
index 0000000..c53d755
--- /dev/null
+++ b/htl/sysdeps/generic/pt-mutexattr-getprotocol.c
@@ -0,0 +1,29 @@
+/* pthread_mutexattr_getprotocol.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_mutexattr_getprotocol (const pthread_mutexattr_t *attr,
+			       int *protocol)
+{
+  *protocol = attr->__protocol;
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-mutexattr-getpshared.c b/htl/sysdeps/generic/pt-mutexattr-getpshared.c
new file mode 100644
index 0000000..494b2de
--- /dev/null
+++ b/htl/sysdeps/generic/pt-mutexattr-getpshared.c
@@ -0,0 +1,29 @@
+/* pthread_mutexattr_getpshared.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_mutexattr_getpshared (const pthread_mutexattr_t *attr,
+			      int *pshared)
+{
+  *pshared = attr->__pshared;
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-mutexattr-gettype.c b/htl/sysdeps/generic/pt-mutexattr-gettype.c
new file mode 100644
index 0000000..28fee9a
--- /dev/null
+++ b/htl/sysdeps/generic/pt-mutexattr-gettype.c
@@ -0,0 +1,28 @@
+/* pthread_mutexattr_gettype.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_mutexattr_gettype (const pthread_mutexattr_t *attr, int *type)
+{
+  *type = attr->__mutex_type;
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-mutexattr-init.c b/htl/sysdeps/generic/pt-mutexattr-init.c
new file mode 100644
index 0000000..82f5da2
--- /dev/null
+++ b/htl/sysdeps/generic/pt-mutexattr-init.c
@@ -0,0 +1,29 @@
+/* pthread_mutexattr_init.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+__pthread_mutexattr_init (pthread_mutexattr_t *attr)
+{
+  *attr = __pthread_default_mutexattr;
+  return 0;
+}
+weak_alias (__pthread_mutexattr_init, pthread_mutexattr_init)
diff --git a/htl/sysdeps/generic/pt-mutexattr-setprioceiling.c b/htl/sysdeps/generic/pt-mutexattr-setprioceiling.c
new file mode 100644
index 0000000..bb8a3d6
--- /dev/null
+++ b/htl/sysdeps/generic/pt-mutexattr-setprioceiling.c
@@ -0,0 +1,30 @@
+/* pthread_mutexattr_setprioceiling.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_mutexattr_setprioceiling (pthread_mutexattr_t *attr,
+				  int prioceiling)
+{
+  return ENOSYS;
+}
+
+stub_warning (pthread_mutexattr_setprioceiling)
diff --git a/htl/sysdeps/generic/pt-mutexattr-setprotocol.c b/htl/sysdeps/generic/pt-mutexattr-setprotocol.c
new file mode 100644
index 0000000..e11dc35
--- /dev/null
+++ b/htl/sysdeps/generic/pt-mutexattr-setprotocol.c
@@ -0,0 +1,42 @@
+/* pthread_mutexattr_setprotocol.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_mutexattr_setprotocol (pthread_mutexattr_t *attr,
+			       int protocol)
+{
+  if (protocol == __pthread_default_mutexattr.__protocol)
+    {
+      attr->__protocol = protocol;
+      return 0;
+    }
+
+  switch (protocol)
+    {
+    case PTHREAD_PRIO_NONE:
+    case PTHREAD_PRIO_INHERIT:
+    case PTHREAD_PRIO_PROTECT:
+      return ENOTSUP;
+    default:
+      return EINVAL;
+    }
+}
diff --git a/htl/sysdeps/generic/pt-mutexattr-setpshared.c b/htl/sysdeps/generic/pt-mutexattr-setpshared.c
new file mode 100644
index 0000000..b7dc1f0
--- /dev/null
+++ b/htl/sysdeps/generic/pt-mutexattr-setpshared.c
@@ -0,0 +1,39 @@
+/* pthread_mutexattr_setpshared.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_mutexattr_setpshared (pthread_mutexattr_t *attr,
+			      int pshared)
+{
+  switch (pshared)
+    {
+    case PTHREAD_PROCESS_PRIVATE:
+      attr->__pshared = pshared;
+      return 0;
+
+    case PTHREAD_PROCESS_SHARED:
+      return ENOTSUP;
+
+    default:
+      return EINVAL;
+    }
+}
diff --git a/htl/sysdeps/generic/pt-mutexattr-settype.c b/htl/sysdeps/generic/pt-mutexattr-settype.c
new file mode 100644
index 0000000..7a7ce35
--- /dev/null
+++ b/htl/sysdeps/generic/pt-mutexattr-settype.c
@@ -0,0 +1,38 @@
+/* pthread_mutexattr_settype.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+__pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type)
+{
+  switch (type)
+    {
+    case PTHREAD_MUTEX_NORMAL:
+    case PTHREAD_MUTEX_ERRORCHECK:
+    case PTHREAD_MUTEX_RECURSIVE:
+      attr->__mutex_type = type;
+      return 0;
+
+    default:
+      return EINVAL;
+    }
+}
+weak_alias (__pthread_mutexattr_settype, pthread_mutexattr_settype)
diff --git a/htl/sysdeps/generic/pt-mutexattr.c b/htl/sysdeps/generic/pt-mutexattr.c
new file mode 100644
index 0000000..f9282af
--- /dev/null
+++ b/htl/sysdeps/generic/pt-mutexattr.c
@@ -0,0 +1,45 @@
+/* Default mutex attributes.  Generic version.
+   Copyright (C) 2000, 2002, 2008 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 <pthread.h>
+#include <pt-internal.h>
+
+const struct __pthread_mutexattr __pthread_default_mutexattr =
+{
+  __prioceiling: 0,
+  __protocol: PTHREAD_PRIO_NONE,
+  __pshared: PTHREAD_PROCESS_PRIVATE,
+  __mutex_type: PTHREAD_MUTEX_DEFAULT
+};
+
+const struct __pthread_mutexattr __pthread_errorcheck_mutexattr =
+{
+  __prioceiling: 0,
+  __protocol: PTHREAD_PRIO_NONE,
+  __pshared: PTHREAD_PROCESS_PRIVATE,
+  __mutex_type: PTHREAD_MUTEX_ERRORCHECK
+};
+
+const struct __pthread_mutexattr __pthread_recursive_mutexattr =
+{
+  __prioceiling: 0,
+  __protocol: PTHREAD_PRIO_NONE,
+  __pshared: PTHREAD_PROCESS_PRIVATE,
+  __mutex_type: PTHREAD_MUTEX_RECURSIVE
+};
diff --git a/htl/sysdeps/generic/pt-once.c b/htl/sysdeps/generic/pt-once.c
new file mode 100644
index 0000000..cfa45d5
--- /dev/null
+++ b/htl/sysdeps/generic/pt-once.c
@@ -0,0 +1,45 @@
+/* pthread_once.  Generic 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.  */
+
+#include <pthread.h>
+#include <bits/memory.h>
+
+#include <pt-internal.h>
+
+int
+__pthread_once (pthread_once_t *once_control, void (*init_routine) (void))
+{
+  __memory_barrier ();
+  if (once_control->__run == 0)
+    {
+      __pthread_spin_lock (&once_control->__lock);
+
+      if (once_control->__run == 0)
+	{
+	  init_routine ();
+	  __memory_barrier ();
+	  once_control->__run = 1;
+	}
+
+      __pthread_spin_unlock (&once_control->__lock);
+    }
+
+  return 0;
+}
+strong_alias (__pthread_once, pthread_once);
diff --git a/htl/sysdeps/generic/pt-rwlock-attr.c b/htl/sysdeps/generic/pt-rwlock-attr.c
new file mode 100644
index 0000000..8de96f1
--- /dev/null
+++ b/htl/sysdeps/generic/pt-rwlock-attr.c
@@ -0,0 +1,26 @@
+/* Default rwlock attributes.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+const struct __pthread_rwlockattr __pthread_default_rwlockattr =
+{
+  __pshared: PTHREAD_PROCESS_PRIVATE
+};
diff --git a/htl/sysdeps/generic/pt-rwlock-destroy.c b/htl/sysdeps/generic/pt-rwlock-destroy.c
new file mode 100644
index 0000000..045eebd
--- /dev/null
+++ b/htl/sysdeps/generic/pt-rwlock-destroy.c
@@ -0,0 +1,29 @@
+/* Destroy a rwlock.  Generic version.
+   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 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 <pthread.h>
+#include <pt-internal.h>
+
+int
+_pthread_rwlock_destroy (pthread_rwlock_t *rwlock)
+{
+  return 0;
+}
+
+strong_alias (_pthread_rwlock_destroy, pthread_rwlock_destroy);
diff --git a/htl/sysdeps/generic/pt-rwlock-init.c b/htl/sysdeps/generic/pt-rwlock-init.c
new file mode 100644
index 0000000..c9ff9b2
--- /dev/null
+++ b/htl/sysdeps/generic/pt-rwlock-init.c
@@ -0,0 +1,45 @@
+/* Initialize a rwlock.  Generic version.
+   Copyright (C) 2002, 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 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 <pthread.h>
+#include <string.h>
+#include <pt-internal.h>
+
+int
+_pthread_rwlock_init (pthread_rwlock_t *rwlock,
+		      const pthread_rwlockattr_t *attr)
+{
+  *rwlock = (pthread_rwlock_t) __PTHREAD_RWLOCK_INITIALIZER;
+
+  if (! attr
+      || memcmp (attr, &__pthread_default_rwlockattr, sizeof (*attr) == 0))
+    /* Use the default attributes.  */
+    return 0;
+
+  /* Non-default attributes.  */
+
+  rwlock->__attr = malloc (sizeof *attr);
+  if (! rwlock->__attr)
+    return ENOMEM;
+
+  *rwlock->__attr = *attr;
+  return 0;
+}
+
+strong_alias (_pthread_rwlock_init, pthread_rwlock_init);
diff --git a/htl/sysdeps/generic/pt-rwlock-rdlock.c b/htl/sysdeps/generic/pt-rwlock-rdlock.c
new file mode 100644
index 0000000..708e3e1
--- /dev/null
+++ b/htl/sysdeps/generic/pt-rwlock-rdlock.c
@@ -0,0 +1,33 @@
+/* Acquire a rwlock for reading.  Generic version.
+   Copyright (C) 2002, 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 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 <pthread.h>
+#include <pt-internal.h>
+
+/* Implemented in pt-rwlock-timedrdlock.c.  */
+extern int __pthread_rwlock_timedrdlock_internal (struct __pthread_rwlock *rwlock,
+						  const struct timespec *abstime);
+
+/* Acquire RWLOCK for reading, block if we can't get it.  */
+int
+__pthread_rwlock_rdlock (struct __pthread_rwlock *rwlock)
+{
+  return __pthread_rwlock_timedrdlock_internal (rwlock, 0);
+}
+weak_alias (__pthread_rwlock_rdlock, pthread_rwlock_rdlock);
diff --git a/htl/sysdeps/generic/pt-rwlock-timedrdlock.c b/htl/sysdeps/generic/pt-rwlock-timedrdlock.c
new file mode 100644
index 0000000..4cfba43
--- /dev/null
+++ b/htl/sysdeps/generic/pt-rwlock-timedrdlock.c
@@ -0,0 +1,121 @@
+/* Acquire a rwlock for reading.  Generic version.
+   Copyright (C) 2002, 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 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 <pthread.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+/* Acquire the rwlock *RWLOCK for reading blocking until *ABSTIME if
+   it is already held.  As a GNU extension, if TIMESPEC is NULL then
+   wait forever.  */
+int
+__pthread_rwlock_timedrdlock_internal (struct __pthread_rwlock *rwlock,
+				       const struct timespec *abstime)
+{
+  error_t err;
+  int drain;
+  struct __pthread *self;
+
+  __pthread_spin_lock (&rwlock->__lock);
+  if (__pthread_spin_trylock (&rwlock->__held) == 0)
+    /* Successfully acquired the lock.  */
+    {
+      assert (rwlock->__readerqueue == 0);
+      assert (rwlock->__writerqueue == 0);
+      assert (rwlock->__readers == 0);
+
+      rwlock->__readers = 1;
+      __pthread_spin_unlock (&rwlock->__lock);
+      return 0;
+    }
+  else
+    /* Lock is held, but is held by a reader?  */
+    if (rwlock->__readers > 0)
+      /* Just add ourself to number of readers.  */
+      {
+	assert (rwlock->__readerqueue == 0);
+	rwlock->__readers ++;
+	__pthread_spin_unlock (&rwlock->__lock);
+	return 0;
+      }
+
+  /* The lock is busy.  */
+
+  /* Better be blocked by a writer.  */
+  assert (rwlock->__readers == 0);
+
+  if (abstime && (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000))
+    return EINVAL;
+
+  self = _pthread_self ();
+
+  /* Add ourself to the queue.  */
+  __pthread_enqueue (&rwlock->__readerqueue, self);
+  __pthread_spin_unlock (&rwlock->__lock);
+
+  /* Block the thread.  */
+  if (abstime)
+    err = __pthread_timedblock (self, abstime, CLOCK_REALTIME);
+  else
+    {
+      err = 0;
+      __pthread_block (self);
+    }
+
+  __pthread_spin_lock (&rwlock->__lock);
+  if (! self->prevp)
+    /* Another thread removed us from the queue, which means a wakeup message
+       has been sent.  It was either consumed while we were blocking, or
+       queued after we timed out and before we acquired the rwlock lock, in
+       which case the message queue must be drained.  */
+    drain = err ? 1 : 0;
+  else
+    {
+      /* We're still in the queue.  Noone attempted to wake us up, i.e. we
+	 timed out.  */
+      __pthread_dequeue (self);
+      drain = 0;
+    }
+  __pthread_spin_unlock (&rwlock->__lock);
+
+  if (drain)
+    __pthread_block (self);
+
+  if (err)
+    {
+      assert (err == ETIMEDOUT);
+      return err;
+    }
+
+  /* The reader count has already been increment by whoever woke us
+     up.  */
+
+  assert (rwlock->__readers > 0);
+
+  return 0;
+}
+
+int
+__pthread_rwlock_timedrdlock (struct __pthread_rwlock *rwlock,
+			    const struct timespec *abstime)
+{
+  return __pthread_rwlock_timedrdlock_internal (rwlock, abstime);
+}
+weak_alias (__pthread_rwlock_timedrdlock, pthread_rwlock_timedrdlock)
diff --git a/htl/sysdeps/generic/pt-rwlock-timedwrlock.c b/htl/sysdeps/generic/pt-rwlock-timedwrlock.c
new file mode 100644
index 0000000..2adaf03
--- /dev/null
+++ b/htl/sysdeps/generic/pt-rwlock-timedwrlock.c
@@ -0,0 +1,104 @@
+/* Acquire a rwlock for writing.  Generic version.
+   Copyright (C) 2002, 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 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 <pthread.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+/* Acquire RWLOCK for writing blocking until *ABSTIME if we cannot get
+   it.  As a special GNU extension, if ABSTIME is NULL then the wait
+   shall not time out.  */
+int
+__pthread_rwlock_timedwrlock_internal (struct __pthread_rwlock *rwlock,
+				       const struct timespec *abstime)
+{
+  error_t err;
+  int drain;
+  struct __pthread *self;
+
+  __pthread_spin_lock (&rwlock->__lock);
+  if (__pthread_spin_trylock (&rwlock->__held) == 0)
+    /* Successfully acquired the lock.  */
+    {
+      assert (rwlock->__readerqueue == 0);
+      assert (rwlock->__writerqueue == 0);
+      assert (rwlock->__readers == 0);
+
+      __pthread_spin_unlock (&rwlock->__lock);
+      return 0;
+    }
+
+  /* The lock is busy.  */
+
+  if (abstime && (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000))
+    return EINVAL;
+
+  self = _pthread_self ();
+
+  /* Add ourselves to the queue.  */
+  __pthread_enqueue (&rwlock->__writerqueue, self);
+  __pthread_spin_unlock (&rwlock->__lock);
+
+  /* Block the thread.  */
+  if (abstime)
+    err = __pthread_timedblock (self, abstime, CLOCK_REALTIME);
+  else
+    {
+      err = 0;
+      __pthread_block (self);
+    }
+
+  __pthread_spin_lock (&rwlock->__lock);
+  if (! self->prevp)
+    /* Another thread removed us from the queue, which means a wakeup message
+       has been sent.  It was either consumed while we were blocking, or
+       queued after we timed out and before we acquired the rwlock lock, in
+       which case the message queue must be drained.  */
+    drain = err ? 1 : 0;
+  else
+    {
+      /* We're still in the queue.  Noone attempted to wake us up, i.e. we
+	 timed out.  */
+      __pthread_dequeue (self);
+      drain = 0;
+    }
+  __pthread_spin_unlock (&rwlock->__lock);
+
+  if (drain)
+    __pthread_block (self);
+
+  if (err)
+    {
+      assert (err == ETIMEDOUT);
+      return err;
+    }
+
+  assert (rwlock->__readers == 0);
+
+  return 0;
+}
+
+int
+__pthread_rwlock_timedwrlock (struct __pthread_rwlock *rwlock,
+			    const struct timespec *abstime)
+{
+  return __pthread_rwlock_timedwrlock_internal (rwlock, abstime);
+}
+weak_alias (__pthread_rwlock_timedwrlock, pthread_rwlock_timedwrlock)
diff --git a/htl/sysdeps/generic/pt-rwlock-tryrdlock.c b/htl/sysdeps/generic/pt-rwlock-tryrdlock.c
new file mode 100644
index 0000000..30cb6cf
--- /dev/null
+++ b/htl/sysdeps/generic/pt-rwlock-tryrdlock.c
@@ -0,0 +1,56 @@
+/* Try to acquire a rwlock for reading.  Generic 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.  */
+
+#include <pthread.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+/* Try to acquire RWLOCK.  */
+int
+pthread_rwlock_tryrdlock (struct __pthread_rwlock *rwlock)
+{
+  __pthread_spin_lock (&rwlock->__lock);
+  if (__pthread_spin_trylock (&rwlock->__held) == 0)
+    /* Successfully acquired the lock.  */
+    {
+      assert (rwlock->__readerqueue == 0);
+      assert (rwlock->__writerqueue == 0);
+      assert (rwlock->__readers == 0);
+
+      rwlock->__readers = 1;
+      __pthread_spin_unlock (&rwlock->__lock);
+      return 0;
+    }
+  else
+    /* Lock is held, but is held by a reader?  */
+    if (rwlock->__readers > 0)
+      {
+	assert (rwlock->__readerqueue == 0);
+	rwlock->__readers ++;
+	__pthread_spin_unlock (&rwlock->__lock);
+	return 0;
+      }
+
+  /* The lock is busy.  */
+
+  __pthread_spin_unlock (&rwlock->__lock);
+
+  return EBUSY;
+}
diff --git a/htl/sysdeps/generic/pt-rwlock-trywrlock.c b/htl/sysdeps/generic/pt-rwlock-trywrlock.c
new file mode 100644
index 0000000..af8f911
--- /dev/null
+++ b/htl/sysdeps/generic/pt-rwlock-trywrlock.c
@@ -0,0 +1,46 @@
+/* Try to acquire a rwlock for writing.  Generic 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.  */
+
+#include <pthread.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+/* Try to acquire RWLOCK for writing.  */
+int
+pthread_rwlock_trywrlock (struct __pthread_rwlock *rwlock)
+{
+  __pthread_spin_lock (&rwlock->__lock);
+  if (__pthread_spin_trylock (&rwlock->__held) == 0)
+    /* Successfully acquired the lock.  */
+    {
+      assert (rwlock->__readerqueue == 0);
+      assert (rwlock->__writerqueue == 0);
+      assert (rwlock->__readers == 0);
+
+      __pthread_spin_unlock (&rwlock->__lock);
+      return 0;
+    }
+
+  /* The lock is busy.  */
+
+  __pthread_spin_unlock (&rwlock->__lock);
+
+  return EBUSY;
+}
diff --git a/htl/sysdeps/generic/pt-rwlock-unlock.c b/htl/sysdeps/generic/pt-rwlock-unlock.c
new file mode 100644
index 0000000..0506ae6
--- /dev/null
+++ b/htl/sysdeps/generic/pt-rwlock-unlock.c
@@ -0,0 +1,99 @@
+/* Unlock a rwlock.  Generic version.
+   Copyright (C) 2000,02 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 <pthread.h>
+
+#include <pt-internal.h>
+
+/* Unlock *RWLOCK, rescheduling a waiting writer thread or, if there
+   are no threads waiting for a write lock, rescheduling the reader
+   threads.  */
+int
+__pthread_rwlock_unlock (pthread_rwlock_t *rwlock)
+{
+  struct __pthread *wakeup;
+  
+  __pthread_spin_lock (&rwlock->__lock);
+
+  assert (__pthread_spin_trylock (&rwlock->__held) == EBUSY);
+
+  if (rwlock->__readers > 1)
+    /* There are other readers.  */
+    {
+      rwlock->__readers --;
+      __pthread_spin_unlock (&rwlock->__lock);
+      return 0;
+    }
+
+  if (rwlock->__readers == 1)
+    /* Last reader.  */
+    rwlock->__readers = 0;
+      
+
+  /* Wake someone else up.  Try the writer queue first, then the
+     reader queue if that is empty.  */
+
+  if (rwlock->__writerqueue)
+    {
+      wakeup = rwlock->__writerqueue;
+      __pthread_dequeue (wakeup);
+
+      /* We do not unlock RWLOCK->held: we are transferring the ownership
+	 to the thread that we are waking up.  */
+
+      __pthread_spin_unlock (&rwlock->__lock);
+      __pthread_wakeup (wakeup);
+
+      return 0;
+    }
+
+  if (rwlock->__readerqueue)
+    {
+      unsigned n = 0;
+
+      __pthread_queue_iterate (rwlock->__readerqueue, wakeup)
+        n ++;
+
+      {
+	struct __pthread *wakeups[n];
+	unsigned i = 0;
+
+	__pthread_dequeuing_iterate (rwlock->__readerqueue, wakeup)
+	    wakeups[i ++] = wakeup;
+
+	rwlock->__readers += n;
+	rwlock->__readerqueue = 0;
+
+	__pthread_spin_unlock (&rwlock->__lock);
+
+	for (i = 0; i < n; i ++)
+	  __pthread_wakeup (wakeups[i]);
+      }
+
+      return 0;
+    }
+
+
+  /* Noone is waiting.  Just unlock it.  */
+
+  __pthread_spin_unlock (&rwlock->__held);
+  __pthread_spin_unlock (&rwlock->__lock);
+  return 0;
+}
+weak_alias (__pthread_rwlock_unlock, pthread_rwlock_unlock);
diff --git a/htl/sysdeps/generic/pt-rwlock-wrlock.c b/htl/sysdeps/generic/pt-rwlock-wrlock.c
new file mode 100644
index 0000000..c769bc6
--- /dev/null
+++ b/htl/sysdeps/generic/pt-rwlock-wrlock.c
@@ -0,0 +1,35 @@
+/* Acquire a rwlock for writing.  Generic 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.  */
+
+#include <pthread.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+/* Implemented in pt-rwlock-timedwrlock.c.  */
+extern int __pthread_rwlock_timedwrlock_internal (struct __pthread_rwlock *rwlock,
+						  const struct timespec *abstime);
+
+/* Acquire RWLOCK for writing.  */
+int
+__pthread_rwlock_wrlock (struct __pthread_rwlock *rwlock)
+{
+  return __pthread_rwlock_timedwrlock_internal (rwlock, 0);
+}
+weak_alias (__pthread_rwlock_wrlock, pthread_rwlock_wrlock);
diff --git a/htl/sysdeps/generic/pt-rwlockattr-destroy.c b/htl/sysdeps/generic/pt-rwlockattr-destroy.c
new file mode 100644
index 0000000..eabfcbe
--- /dev/null
+++ b/htl/sysdeps/generic/pt-rwlockattr-destroy.c
@@ -0,0 +1,27 @@
+/* pthread_rwlockattr_destroy.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_rwlockattr_destroy (pthread_rwlockattr_t *attr)
+{
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-rwlockattr-getpshared.c b/htl/sysdeps/generic/pt-rwlockattr-getpshared.c
new file mode 100644
index 0000000..1565cf1
--- /dev/null
+++ b/htl/sysdeps/generic/pt-rwlockattr-getpshared.c
@@ -0,0 +1,29 @@
+/* pthread_rwlockattr_getpshared.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_rwlockattr_getpshared (const pthread_rwlockattr_t *attr,
+			       int *pshared)
+{
+  *pshared = attr->__pshared;
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-rwlockattr-init.c b/htl/sysdeps/generic/pt-rwlockattr-init.c
new file mode 100644
index 0000000..34da6bf
--- /dev/null
+++ b/htl/sysdeps/generic/pt-rwlockattr-init.c
@@ -0,0 +1,28 @@
+/* pthread_rwlockattr_init.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_rwlockattr_init (pthread_rwlockattr_t *attr)
+{
+  *attr = __pthread_default_rwlockattr;
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-rwlockattr-setpshared.c b/htl/sysdeps/generic/pt-rwlockattr-setpshared.c
new file mode 100644
index 0000000..71f5c68
--- /dev/null
+++ b/htl/sysdeps/generic/pt-rwlockattr-setpshared.c
@@ -0,0 +1,39 @@
+/* pthread_rwlockattr_setpshared.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_rwlockattr_setpshared (pthread_rwlockattr_t *attr,
+			       int pshared)
+{
+  switch (pshared)
+    {
+    case PTHREAD_PROCESS_PRIVATE:
+      attr->__pshared = pshared;
+      return 0;
+
+    case PTHREAD_PROCESS_SHARED:
+      return ENOTSUP;
+
+    default:
+      return EINVAL;
+    }
+}
diff --git a/htl/sysdeps/generic/pt-setconcurrency.c b/htl/sysdeps/generic/pt-setconcurrency.c
new file mode 100644
index 0000000..cd55b1b
--- /dev/null
+++ b/htl/sysdeps/generic/pt-setconcurrency.c
@@ -0,0 +1,34 @@
+/* Set the desired level of concurrency.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int __pthread_concurrency;
+
+int
+pthread_setconcurrency (int new_level)
+{
+  if (new_level < 0)
+    return EINVAL;
+
+  __pthread_concurrency = new_level;
+
+  return 0;
+}
diff --git a/htl/sysdeps/generic/pt-setschedparam.c b/htl/sysdeps/generic/pt-setschedparam.c
new file mode 100644
index 0000000..29e2a4e
--- /dev/null
+++ b/htl/sysdeps/generic/pt-setschedparam.c
@@ -0,0 +1,31 @@
+/* Set the scheduling parameters for a thread.  Generic version.
+   Copyright (C) 2002, 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 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 <pthread.h>
+#include <pt-internal.h>
+
+int
+__pthread_setschedparam (pthread_t thread, int policy,
+		       const struct sched_param *param)
+{
+  return ENOSYS;
+}
+
+strong_alias (__pthread_setschedparam, pthread_setschedparam);
+stub_warning (pthread_setschedparam)
diff --git a/htl/sysdeps/generic/pt-setschedprio.c b/htl/sysdeps/generic/pt-setschedprio.c
new file mode 100644
index 0000000..d79690e
--- /dev/null
+++ b/htl/sysdeps/generic/pt-setschedprio.c
@@ -0,0 +1,29 @@
+/* Set the scheduling priority of a thread.  Generic 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_setschedprio (pthread_t thread, int prio)
+{
+  return ENOSYS;
+}
+
+stub_warning (pthread_setschedprio)
diff --git a/htl/sysdeps/generic/pt-setspecific.c b/htl/sysdeps/generic/pt-setspecific.c
new file mode 100644
index 0000000..871560c
--- /dev/null
+++ b/htl/sysdeps/generic/pt-setspecific.c
@@ -0,0 +1,51 @@
+/* pthread_setspecific.  Generic 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.  */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+int
+__pthread_setspecific (pthread_key_t key, const void *value)
+{
+  struct __pthread *self = _pthread_self ();
+
+  if (key < 0 || key >= __pthread_key_count
+      || __pthread_key_destructors[key] == PTHREAD_KEY_INVALID)
+    return EINVAL;
+
+  if (key >= self->thread_specifics_size)
+    {
+      /* Amortize reallocation cost.  */
+      int newsize = 2 * key + 1;
+      void **new = realloc (self->thread_specifics,
+			    newsize * sizeof (new[0]));
+      if (! new )
+	return ENOMEM;
+
+      memset (&new[self->thread_specifics_size], 0,
+	      (newsize - self->thread_specifics_size) * sizeof (new[0]));
+      self->thread_specifics = new;
+      self->thread_specifics_size = newsize;
+    }
+
+  self->thread_specifics[key] = (void*) value;
+  return 0;
+}
+strong_alias (__pthread_setspecific, pthread_setspecific);
diff --git a/htl/sysdeps/generic/pt-startup.c b/htl/sysdeps/generic/pt-startup.c
new file mode 100644
index 0000000..c21a181
--- /dev/null
+++ b/htl/sysdeps/generic/pt-startup.c
@@ -0,0 +1,25 @@
+/* Thread initialization.  Generic version.
+   Copyright (C) 2008 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 <pt-internal.h>
+
+void
+__pthread_startup (void)
+{
+}
diff --git a/htl/sysdeps/generic/pthread/pthread.h b/htl/sysdeps/generic/pthread/pthread.h
new file mode 100644
index 0000000..ad34e5d
--- /dev/null
+++ b/htl/sysdeps/generic/pthread/pthread.h
@@ -0,0 +1,852 @@
+/* Copyright (C) 2000, 2002, 2005, 2006, 2007, 2008, 2009, 2010
+     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.  */
+
+/*
+ *	POSIX Threads Extension: ???			<pthread.h>
+ */
+
+#ifndef _PTHREAD_H
+#define _PTHREAD_H	1
+
+#include <features.h>
+
+#include <sys/cdefs.h>
+#ifndef __extern_inline
+/* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
+   inline semantics, unless -fgnu89-inline is used.  */
+# if !defined __cplusplus || __GNUC_PREREQ (4,3)
+#  if defined __GNUC_STDC_INLINE__ || defined __cplusplus
+#   define __extern_inline extern __inline __attribute__ ((__gnu_inline__))
+#   if __GNUC_PREREQ (4,3)
+#    define __extern_always_inline \
+   extern __always_inline __attribute__ ((__gnu_inline__, __artificial__))
+#   else
+#    define __extern_always_inline \
+   extern __always_inline __attribute__ ((__gnu_inline__))
+#   endif
+#  else
+#   define __extern_inline extern __inline
+#   define __extern_always_inline extern __always_inline
+#  endif
+# endif
+#endif
+
+#include <sched.h>
+#include <time.h>
+
+__BEGIN_DECLS
+
+#include <pthread/pthreadtypes.h>
+
+#include <bits/pthread.h>
+
+/* Possible values for the process shared attribute.  */
+#define PTHREAD_PROCESS_PRIVATE __PTHREAD_PROCESS_PRIVATE
+#define PTHREAD_PROCESS_SHARED __PTHREAD_PROCESS_SHARED
+
+
+/* Thread attributes.  */
+
+/* Possible values for the inheritsched attribute.  */
+#define PTHREAD_EXPLICIT_SCHED __PTHREAD_EXPLICIT_SCHED
+#define PTHREAD_INHERIT_SCHED __PTHREAD_INHERIT_SCHED
+
+/* Possible values for the `contentionscope' attribute.  */
+#define PTHREAD_SCOPE_SYSTEM __PTHREAD_SCOPE_SYSTEM
+#define PTHREAD_SCOPE_PROCESS __PTHREAD_SCOPE_PROCESS
+
+/* Possible values for the `detachstate' attribute.  */
+#define PTHREAD_CREATE_JOINABLE __PTHREAD_CREATE_JOINABLE
+#define PTHREAD_CREATE_DETACHED __PTHREAD_CREATE_DETACHED
+
+#include <bits/thread-attr.h>
+
+/* Initialize the thread attribute object in *ATTR to the default
+   values.  */
+extern int pthread_attr_init (pthread_attr_t *__attr) __THROW __nonnull ((1));
+
+/* Destroy the thread attribute object in *ATTR.  */
+extern int pthread_attr_destroy (pthread_attr_t *__attr)
+	__THROW __nonnull ((1));
+
+
+/* Return the value of the inheritsched attribute in *ATTR in
+   *INHERITSCHED.  */
+extern int pthread_attr_getinheritsched (const pthread_attr_t *__restrict __attr,
+					 int *__restrict __inheritsched)
+	__THROW __nonnull ((1, 2));
+
+/* Set the value of the inheritsched attribute in *ATTR to
+   INHERITSCHED.  */
+extern int pthread_attr_setinheritsched (pthread_attr_t *__attr,
+					 int __inheritsched)
+	__THROW __nonnull ((1));
+
+
+/* Return the value of the schedparam attribute in *ATTR in *PARAM.  */
+extern int pthread_attr_getschedparam (const pthread_attr_t *__restrict __attr,
+				       struct sched_param *__restrict __param)
+	__THROW __nonnull ((1, 2));
+
+/* Set the value of the schedparam attribute in *ATTR to PARAM.  */
+extern int pthread_attr_setschedparam (pthread_attr_t *__restrict __attr,
+				       const struct sched_param *__restrict
+				       __param) __THROW __nonnull ((1, 2));
+
+
+/* Return the value of the schedpolicy attribute in *ATTR to *POLICY.  */
+extern int pthread_attr_getschedpolicy (const pthread_attr_t *__restrict __attr,
+					int *__restrict __policy)
+	__THROW __nonnull ((1, 2));
+
+/* Set the value of the schedpolicy attribute in *ATTR to POLICY.  */
+extern int pthread_attr_setschedpolicy (pthread_attr_t *__attr,
+					int __policy)
+	__THROW __nonnull ((1));
+
+
+/* Return the value of the contentionscope attribute in *ATTR in
+   *CONTENTIONSCOPE.  */
+extern int pthread_attr_getscope (const pthread_attr_t *__restrict __attr,
+				  int *__restrict __contentionscope)
+	__THROW __nonnull ((1, 2));
+
+/* Set the value of the contentionscope attribute in *ATTR to
+   CONTENTIONSCOPE.  */
+extern int pthread_attr_setscope (pthread_attr_t *__attr,
+				  int __contentionscope)
+	__THROW __nonnull ((1));
+
+
+/* Return the value of the stackaddr attribute in *ATTR in
+   *STACKADDR.  */
+extern int pthread_attr_getstackaddr (const pthread_attr_t *__restrict __attr,
+				      void **__restrict __stackaddr)
+	__THROW __nonnull ((1, 2));
+
+/* Set the value of the stackaddr attribute in *ATTR to STACKADDR.  */
+extern int pthread_attr_setstackaddr (pthread_attr_t *__attr,
+				      void *__stackaddr)
+	__THROW __nonnull ((1));
+
+
+#ifdef __USE_XOPEN2K
+/* Return the value of the stackaddr and stacksize attributes in *ATTR
+   in *STACKADDR and *STACKSIZE respectively.  */
+extern int pthread_attr_getstack (const pthread_attr_t *__restrict __attr,
+				  void **__restrict __stackaddr,
+				  size_t *__restrict __stacksize)
+	__THROW __nonnull ((1, 2, 3));
+
+/* Set the value of the stackaddr and stacksize attributes in *ATTR to
+   STACKADDR and STACKSIZE respectively.  */
+extern int pthread_attr_setstack (pthread_attr_t *__attr,
+				  void *__stackaddr,
+				  size_t __stacksize)
+	__THROW __nonnull ((1));
+#endif
+
+
+/* Return the value of the detachstate attribute in *ATTR in
+   *DETACHSTATE.  */
+extern int pthread_attr_getdetachstate (const pthread_attr_t *__attr,
+					int *__detachstate)
+	__THROW __nonnull ((1, 2));
+
+/* Set the value of the detachstate attribute in *ATTR to
+   DETACHSTATE.  */
+extern int pthread_attr_setdetachstate (pthread_attr_t *__attr,
+					int __detachstate)
+	__THROW __nonnull ((1));
+
+
+/* Return the value of the guardsize attribute in *ATTR in
+   *GUARDSIZE.  */
+extern int pthread_attr_getguardsize (const pthread_attr_t *__restrict __attr,
+				      size_t *__restrict __guardsize)
+	__THROW __nonnull ((1, 2));
+
+/* Set the value of the guardsize attribute in *ATTR to GUARDSIZE.  */
+extern int pthread_attr_setguardsize (pthread_attr_t *__attr,
+				      size_t __guardsize)
+	__THROW __nonnull ((1));
+
+
+/* Return the value of the stacksize attribute in *ATTR in
+   *STACKSIZE.  */
+extern int pthread_attr_getstacksize (const pthread_attr_t *__restrict __attr,
+				      size_t *__restrict __stacksize)
+	__THROW __nonnull ((1, 2));
+
+/* Set the value of the stacksize attribute in *ATTR to STACKSIZE.  */
+extern int pthread_attr_setstacksize (pthread_attr_t *__attr,
+				      size_t __stacksize)
+	__THROW __nonnull ((1));
+
+#ifdef __USE_GNU
+/* Initialize thread attribute *ATTR with attributes corresponding to the
+   already running thread THREAD.  It shall be called on an uninitialized ATTR
+   and destroyed with pthread_attr_destroy when no longer needed.  */
+extern int pthread_getattr_np (pthread_t __thr, pthread_attr_t *__attr)
+	__THROW __nonnull ((2));
+#endif
+
+
+/* Create a thread with attributes given by ATTR, executing
+   START_ROUTINE with argument ARG.  */
+extern int pthread_create (pthread_t *__restrict __threadp,
+			   __const pthread_attr_t *__restrict __attr,
+			   void *(*__start_routine)(void *),
+			   void *__restrict __arg) __THROWNL __nonnull ((1, 3));
+
+/* Terminate the current thread and make STATUS available to any
+   thread that might join us.  */
+extern void pthread_exit (void *__status) __attribute__ ((__noreturn__));
+
+/* Make calling thread wait for termination of thread THREAD.  Return
+   the exit status of the thread in *STATUS.  */
+extern int pthread_join (pthread_t __threadp, void **__status);
+
+/* Indicate that the storage for THREAD can be reclaimed when it
+   terminates.  */
+extern int pthread_detach (pthread_t __threadp);
+
+/* Compare thread IDs T1 and T2.  Return nonzero if they are equal, 0
+   if they are not.  */
+extern int pthread_equal (pthread_t __t1, pthread_t __t2);
+
+# ifdef __USE_EXTERN_INLINES
+
+__extern_inline int
+pthread_equal (pthread_t __t1, pthread_t __t2)
+{
+  return __pthread_equal (__t1, __t2);
+}
+
+# endif /* Use extern inlines.  */
+
+
+/* Return the thread ID of the calling thread.  */
+extern pthread_t pthread_self (void) __THROW;
+
+
+/* Mutex attributes.  */
+
+#define PTHREAD_PRIO_NONE_NP __PTHREAD_PRIO_NONE
+#define PTHREAD_PRIO_INHERIT_NP __PTHREAD_PRIO_INHERIT
+#define PTHREAD_PRIO_PROTECT_NP __PTHREAD_PRIO_PROTECT
+#ifdef __USE_UNIX98
+#define PTHREAD_PRIO_NONE PTHREAD_PRIO_NONE_NP
+#define PTHREAD_PRIO_INHERIT PTHREAD_PRIO_INHERIT_NP
+#define PTHREAD_PRIO_PROTECT PTHREAD_PRIO_PROTECT_NP
+#endif
+
+#define PTHREAD_MUTEX_TIMED_NP __PTHREAD_MUTEX_TIMED
+#define PTHREAD_MUTEX_ERRORCHECK_NP __PTHREAD_MUTEX_ERRORCHECK
+#define PTHREAD_MUTEX_RECURSIVE_NP __PTHREAD_MUTEX_RECURSIVE
+#if defined __USE_UNIX98 || defined __USE_XOPEN2K8
+#define PTHREAD_MUTEX_NORMAL PTHREAD_MUTEX_TIMED_NP
+#define PTHREAD_MUTEX_ERRORCHECK PTHREAD_MUTEX_ERRORCHECK_NP
+#define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP
+#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL
+#endif
+#ifdef __USE_GNU
+/* For compatibility.  */
+#define PTHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_TIMED_NP
+#endif
+
+#ifdef __USE_XOPEN2K
+#define PTHREAD_MUTEX_STALLED __PTHREAD_MUTEX_STALLED
+#define PTHREAD_MUTEX_ROBUST __PTHREAD_MUTEX_ROBUST
+#endif
+
+#include <bits/mutex-attr.h>
+
+/* Initialize the mutex attribute object in *ATTR to the default
+   values.  */
+extern int pthread_mutexattr_init(pthread_mutexattr_t *__attr)
+	__THROW __nonnull ((1));
+
+/* Destroy the mutex attribute structure in *ATTR.  */
+extern int pthread_mutexattr_destroy(pthread_mutexattr_t *__attr)
+	__THROW __nonnull ((1));
+
+
+#ifdef __USE_UNIX98
+/* Return the value of the prioceiling attribute in *ATTR in
+   *PRIOCEILING.  */
+extern int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *__restrict __attr,
+					    int *__restrict __prioceiling)
+	__THROW __nonnull ((1, 2));
+
+/* Set the value of the prioceiling attribute in *ATTR to
+   PRIOCEILING.  */
+extern int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *__attr,
+					    int __prioceiling)
+	__THROW __nonnull ((1));
+
+
+/* Return the value of the protocol attribute in *ATTR in
+   *PROTOCOL.  */
+extern int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *__restrict __attr,
+					 int *__restrict __protocol)
+	__THROW __nonnull ((1, 2));
+
+/* Set the value of the protocol attribute in *ATTR to PROTOCOL.  */
+extern int pthread_mutexattr_setprotocol(pthread_mutexattr_t *__attr,
+					 int __protocol)
+	__THROW __nonnull ((1));
+#endif
+
+
+/* Return the value of the process shared attribute in *ATTR in
+   *PSHARED.  */
+extern int pthread_mutexattr_getpshared(const pthread_mutexattr_t *__restrict __attr,
+					int *__restrict __pshared)
+	__THROW __nonnull ((1, 2));
+
+/* Set the value of the process shared attribute in *ATTR to
+   PSHARED.  */
+extern int pthread_mutexattr_setpshared(pthread_mutexattr_t *__attr,
+					int __pshared)
+	__THROW __nonnull ((1));
+
+
+#if defined __USE_UNIX98 || defined __USE_XOPEN2K8
+/* Return the value of the type attribute in *ATTR in *TYPE.  */
+extern int pthread_mutexattr_gettype(const pthread_mutexattr_t *__restrict __attr,
+				     int *__restrict __type)
+	__THROW __nonnull ((1, 2));
+
+/* Set the value of the type attribute in *ATTR to TYPE.  */
+extern int pthread_mutexattr_settype(pthread_mutexattr_t *__attr,
+				     int __type)
+	__THROW __nonnull ((1));
+#endif
+
+
+/* Mutexes.  */
+
+#include <bits/mutex.h>
+
+#define PTHREAD_MUTEX_INITIALIZER __PTHREAD_MUTEX_INITIALIZER
+/* Static initializer for recursive mutexes.  */
+
+#ifdef __USE_GNU
+# define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
+  __PTHREAD_ERRORCHECK_MUTEX_INITIALIZER
+# define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
+  __PTHREAD_RECURSIVE_MUTEX_INITIALIZER
+#endif
+
+/* Create a mutex with attributes given by ATTR and store it in
+   *__MUTEX.  */
+extern int pthread_mutex_init (struct __pthread_mutex *__restrict __mutex,
+			       const pthread_mutexattr_t *__restrict __attr)
+	__THROW __nonnull ((1));
+
+/* Destroy the mutex __MUTEX.  */
+extern int pthread_mutex_destroy (struct __pthread_mutex *__mutex)
+	__THROW __nonnull ((1));
+
+/* Wait until lock for MUTEX becomes available and lock it.  */
+extern int pthread_mutex_lock (pthread_mutex_t *__mutex);
+
+/* Try to lock MUTEX.  */
+extern int pthread_mutex_trylock (pthread_mutex_t *__mutex)
+	__THROWNL __nonnull ((1));
+
+#ifdef __USE_XOPEN2K
+/* Try to lock MUTEX, block until *ABSTIME if it is already held.  */
+extern int pthread_mutex_timedlock (struct __pthread_mutex *__restrict __mutex,
+				    const struct timespec *__restrict __abstime)
+	__THROWNL __nonnull ((1, 2));
+#endif
+
+/* Unlock MUTEX.  */
+extern int pthread_mutex_unlock (pthread_mutex_t *__mutex)
+	__THROWNL __nonnull ((1));
+
+/* Transfer ownership of the mutex MUTEX to the thread TID.  The
+   caller must own the lock.  */
+extern int __pthread_mutex_transfer_np (struct __pthread_mutex *__mutex,
+					pthread_t __tid)
+	__THROWNL __nonnull ((1));
+
+
+#ifdef __USE_UNIX98
+/* Return the priority ceiling of mutex *MUTEX in *PRIOCEILING.  */
+extern int pthread_mutex_getprioceiling (const pthread_mutex_t *__restrict __mutex,
+					 int *__restrict __prioceiling)
+	__THROW __nonnull ((1, 2));
+
+/* After acquiring the mutex *MUTEX, set its priority ceiling to PRIO
+   and return the old priority ceiling in *OLDPRIO.  Before returning,
+   release the mutex.  */
+extern int pthread_mutex_setprioceiling (pthread_mutex_t *__restrict __mutex,
+					 int __prio, int *__restrict __oldprio)
+	__THROW __nonnull ((1, 3));
+#endif
+
+#ifdef __USE_XOPEN2K8
+
+/* Declare the state protected by robust mutex MTXP as consistent. */
+extern int pthread_mutex_consistent (pthread_mutex_t *__mtxp)
+  __THROW __nonnull ((1));
+
+#  ifdef __USE_GNU
+extern int pthread_mutex_consistent_np (pthread_mutex_t *__mtxp)
+  __THROW __nonnull ((1));
+#  endif
+#endif
+
+
+
+/* Condition attributes.  */
+
+#include <bits/condition-attr.h>
+
+/* Initialize the condition attribute in *ATTR to the default
+   values.  */
+extern int pthread_condattr_init (pthread_condattr_t *__attr)
+	__THROW __nonnull ((1));
+
+/* Destroy the condition attribute structure in *ATTR.  */
+extern int pthread_condattr_destroy (pthread_condattr_t *__attr)
+	__THROW __nonnull ((1));
+
+
+#ifdef __USE_XOPEN2K
+/* Return the value of the clock attribute in *ATTR in *CLOCK_ID.  */
+extern int pthread_condattr_getclock (const pthread_condattr_t *__restrict __attr,
+				      __clockid_t *__restrict __clock_id)
+	__THROW __nonnull ((1, 2));
+
+/* Set the value of the clock attribute in *ATTR to CLOCK_ID.  */
+extern int pthread_condattr_setclock (pthread_condattr_t *__attr,
+				      __clockid_t __clock_id)
+	__THROW __nonnull ((1));
+#endif
+
+
+/* Return the value of the process shared attribute in *ATTR in
+   *PSHARED.  */
+extern int pthread_condattr_getpshared (const pthread_condattr_t *__restrict __attr,
+					int *__restrict __pshared)
+	__THROW __nonnull ((1, 2));
+
+/* Set the value of the process shared attribute in *ATTR to
+   PSHARED.  */
+extern int pthread_condattr_setpshared (pthread_condattr_t *__attr,
+					int __pshared)
+	__THROW __nonnull ((1));
+
+
+/* Condition variables.  */
+
+#include <bits/condition.h>
+
+#define PTHREAD_COND_INITIALIZER __PTHREAD_COND_INITIALIZER
+
+extern int pthread_cond_init (pthread_cond_t *__restrict __cond,
+			      const pthread_condattr_t *__restrict __attr)
+	__THROW __nonnull ((1));
+
+extern int pthread_cond_destroy (pthread_cond_t *__cond)
+	__THROW __nonnull ((1));
+
+/* Unblock at least one of the threads that are blocked on condition
+   variable COND.  */
+extern int pthread_cond_signal (pthread_cond_t *__cond)
+	__THROWNL __nonnull ((1));
+
+/* Unblock all threads that are blocked on condition variable COND.  */
+extern int pthread_cond_broadcast (pthread_cond_t *__cond)
+	__THROWNL __nonnull ((1));
+
+/* Block on condition variable COND.  MUTEX should be held by the
+   calling thread.  On success, MUTEX will be held by the calling
+   thread.  */
+extern int pthread_cond_wait (pthread_cond_t *__restrict __cond,
+			      pthread_mutex_t *__restrict __mutex)
+	 __nonnull ((1, 2));
+
+/* Block on condition variable COND.  MUTEX should be held by the
+   calling thread. On success, MUTEX will be held by the calling
+   thread.  If the time specified by ABSTIME passes, ETIMEDOUT is
+   returned, and MUTEX will nevertheless be held.  */
+extern int pthread_cond_timedwait (pthread_cond_t *__restrict __cond,
+				   pthread_mutex_t *__restrict __mutex,
+				   __const struct timespec *__restrict __abstime)
+	 __nonnull ((1, 2, 3));
+
+
+/* Spin locks.  */
+
+#ifdef __USE_XOPEN2K
+
+# include <bits/spin-lock.h>
+
+#define PTHREAD_SPINLOCK_INITIALIZER __PTHREAD_SPIN_LOCK_INITIALIZER
+
+/* Destroy the spin lock object LOCK.  */
+extern int pthread_spin_destroy (pthread_spinlock_t *__lock)
+	__nonnull ((1));
+
+/* Initialize the spin lock object LOCK.  PSHARED determines whether
+   the spin lock can be operated upon by multiple processes.  */
+extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared)
+	__nonnull ((1));
+
+/* Lock the spin lock object LOCK.  If the lock is held by another
+   thread spin until it becomes available.  */
+extern int pthread_spin_lock (pthread_spinlock_t *__lock)
+	__nonnull ((1));
+
+/* Lock the spin lock object LOCK.  Fail if the lock is held by
+   another thread.  */
+extern int pthread_spin_trylock (pthread_spinlock_t *__lock)
+	__nonnull ((1));
+
+/* Unlock the spin lock object LOCK.  */
+extern int pthread_spin_unlock (pthread_spinlock_t *__lock)
+	__nonnull ((1));
+
+# if defined __USE_EXTERN_INLINES && defined _LIBC
+
+# include <bits/spin-lock-inline.h>
+
+__extern_inline int
+pthread_spin_destroy (pthread_spinlock_t *__lock)
+{
+  return __pthread_spin_destroy (__lock);
+}
+
+__extern_inline int
+pthread_spin_init (pthread_spinlock_t *__lock, int __pshared)
+{
+  return __pthread_spin_init (__lock, __pshared);
+}
+
+__extern_inline int
+pthread_spin_lock (pthread_spinlock_t *__lock)
+{
+  return __pthread_spin_lock (__lock);
+}
+
+__extern_inline int
+pthread_spin_trylock (pthread_spinlock_t *__lock)
+{
+  return __pthread_spin_trylock (__lock);
+}
+
+__extern_inline int
+pthread_spin_unlock (pthread_spinlock_t *__lock)
+{
+  return __pthread_spin_unlock (__lock);
+}
+
+# endif /* Use extern inlines.  */
+
+#endif /* XPG6.  */
+
+
+/* rwlock attributes.  */
+
+#if defined __USE_UNIX98 || defined __USE_XOPEN2K
+
+#include <bits/rwlock-attr.h>
+
+/* Initialize rwlock attribute object in *ATTR to the default
+   values.  */
+extern int pthread_rwlockattr_init (pthread_rwlockattr_t *__attr)
+	__THROW __nonnull ((1));
+
+/* Destroy the rwlock attribute object in *ATTR.  */
+extern int pthread_rwlockattr_destroy (pthread_rwlockattr_t *__attr)
+	__THROW __nonnull ((1));
+
+
+/* Return the value of the process shared attribute in *ATTR in
+   *PSHARED.  */
+extern int pthread_rwlockattr_getpshared (const pthread_rwlockattr_t *__restrict __attr,
+					  int *__restrict __pshared)
+	__THROW __nonnull ((1, 2));
+
+/* Set the value of the process shared atrribute in *ATTR to
+   PSHARED.  */
+extern int pthread_rwlockattr_setpshared (pthread_rwlockattr_t *__attr,
+					  int __pshared)
+	__THROW __nonnull ((1));
+
+
+/* rwlocks.  */
+
+#include <bits/rwlock.h>
+
+#define PTHREAD_RWLOCK_INITIALIZER __PTHREAD_RWLOCK_INITIALIZER
+/* Create a rwlock object with attributes given by ATTR and strore the
+   result in *RWLOCK.  */
+extern int pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock,
+				const pthread_rwlockattr_t *__restrict __attr)
+	__THROW __nonnull ((1));
+
+/* Destroy the rwlock *RWLOCK.  */
+extern int pthread_rwlock_destroy (pthread_rwlock_t *__rwlock)
+	__THROW __nonnull ((1));
+
+/* Acquire the rwlock *RWLOCK for reading.  */
+extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock)
+	__THROWNL __nonnull ((1));
+
+/* Acquire the rwlock *RWLOCK for reading.  */
+extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock)
+	__THROWNL __nonnull ((1));
+
+# ifdef __USE_XOPEN2K
+/* Acquire the rwlock *RWLOCK for reading blocking until *ABSTIME if
+   it is already held.  */
+extern int pthread_rwlock_timedrdlock (struct __pthread_rwlock *__restrict __rwlock,
+				       const struct timespec *__restrict __abstime)
+	__THROWNL __nonnull ((1, 2));
+# endif
+
+/* Acquire the rwlock *RWLOCK for writing.  */
+extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock)
+	__THROWNL __nonnull ((1));
+
+/* Try to acquire the rwlock *RWLOCK for writing.  */
+extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock)
+	__THROWNL __nonnull ((1));
+
+# ifdef __USE_XOPEN2K
+/* Acquire the rwlock *RWLOCK for writing blocking until *ABSTIME if
+   it is already held.  */
+extern int pthread_rwlock_timedwrlock (struct __pthread_rwlock *__restrict __rwlock,
+				       const struct timespec *__restrict __abstime)
+	__THROWNL __nonnull ((1, 2));
+# endif
+
+/* Release the lock held by the current thread on *RWLOCK.  */
+extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock)
+	__THROWNL __nonnull ((1));
+
+#endif /* __USE_UNIX98 || __USE_XOPEN2K */
+
+
+
+/* Cancelation.  */
+
+/* Register a cleanup handler.  */
+extern void pthread_cleanup_push (void (*__routine) (void *), void *__arg);
+
+/* Unregister a cleanup handler.  */
+extern void pthread_cleanup_pop (int __execute);
+
+#include <bits/cancelation.h>
+
+#define pthread_cleanup_push(rt, rtarg) __pthread_cleanup_push(rt, rtarg)
+#define pthread_cleanup_pop(execute) __pthread_cleanup_pop(execute)
+
+#define PTHREAD_CANCEL_DISABLE 0
+#define PTHREAD_CANCEL_ENABLE 1
+
+/* Return the calling thread's cancelation state in *OLDSTATE and set
+   its state to STATE.  */
+extern int pthread_setcancelstate (int __state, int *__oldstate);
+
+#define PTHREAD_CANCEL_DEFERRED 0
+#define PTHREAD_CANCEL_ASYNCHRONOUS 1
+
+/* Return the calling thread's cancelation type in *OLDTYPE and set
+   its type to TYPE.  */
+extern int pthread_setcanceltype (int __type, int *__oldtype);
+
+/* Value returned by pthread_join if the target thread was
+   canceled.  */
+#define PTHREAD_CANCELED ((void *) -1)
+
+/* Cancel THEAD.  */
+extern int pthread_cancel (pthread_t __thr);
+
+/* Add an explicit cancelation point.  */
+extern void pthread_testcancel (void);
+
+
+/* Barriers attributes.  */
+
+#ifdef __USE_XOPEN2K
+
+#include <bits/barrier-attr.h>
+
+/* Initialize barrier attribute object in *ATTR to the default
+   values.  */
+extern int pthread_barrierattr_init (pthread_barrierattr_t *__attr)
+	__THROW __nonnull ((1));
+
+/* Destroy the barrier attribute object in *ATTR.  */
+extern int pthread_barrierattr_destroy (pthread_barrierattr_t *__attr)
+	__THROW __nonnull ((1));
+
+
+/* Return the value of the process shared attribute in *ATTR in
+   *PSHARED.  */
+extern int pthread_barrierattr_getpshared (const pthread_barrierattr_t *__restrict __attr,
+					   int *__restrict __pshared)
+	__THROW __nonnull ((1, 2));
+
+/* Set the value of the process shared atrribute in *ATTR to
+   PSHARED.  */
+extern int pthread_barrierattr_setpshared (pthread_barrierattr_t *__attr,
+					   int __pshared)
+	__THROW __nonnull ((1));
+
+
+/* Barriers.  */
+
+#include <bits/barrier.h>
+
+/* Returned by pthread_barrier_wait to exactly one thread each time a
+   barrier is passed.  */
+#define PTHREAD_BARRIER_SERIAL_THREAD -1
+
+/* Initialize barrier BARRIER.  */
+extern int pthread_barrier_init (pthread_barrier_t *__restrict __barrier,
+				const pthread_barrierattr_t *__restrict __attr,
+				unsigned __count)
+	__THROW __nonnull ((1));
+
+/* Destroy 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)
+	__THROWNL __nonnull ((1));
+
+#endif /* __USE_XOPEN2K */
+
+
+
+/* Thread specific data.  */
+
+#include <bits/thread-specific.h>
+
+/* Create a thread specific data key in KEY visible to all threads.
+   On thread destruction, DESTRUCTOR shall be called with the thread
+   specific data associate with KEY if it is not NULL.  */
+extern int pthread_key_create (pthread_key_t *__key,
+			       void (*__destructor) (void *))
+	__THROW __nonnull ((1));
+
+/* Delete the thread specific data key KEY.  The associated destructor
+   function is not called.  */
+extern int pthread_key_delete (pthread_key_t __key) __THROW;
+
+/* Return the caller thread's thread specific value of KEY.  */
+extern void *pthread_getspecific (pthread_key_t __key) __THROW;
+
+/* Set the caller thread's thread specific value of KEY to VALUE.  */
+extern int pthread_setspecific (pthread_key_t __key, const void *__value)
+	__THROW;
+
+
+/* Dynamic package initialization.  */
+
+#include <bits/once.h>
+
+#define PTHREAD_ONCE_INIT __PTHREAD_ONCE_INIT
+
+/* Call INIT_ROUTINE if this function has never been called with
+   *ONCE_CONTROL, otherwise do nothing.  */
+extern int pthread_once (pthread_once_t *__once_control,
+			 void (*__init_routine) (void)) __nonnull ((1, 2));
+
+
+/* Concurrency.  */
+
+#ifdef __USE_UNIX98
+/* Set the desired concurrency level to NEW_LEVEL.  */
+extern int pthread_setconcurrency (int __new_level) __THROW;
+
+/* Get the current concurrency level.  */
+extern int pthread_getconcurrency (void) __THROW;
+#endif
+
+
+/* Forking.  */
+
+/* Register the function PREPARE to be run before the process forks,
+   the function PARENT to be run after a fork in the parent and the
+   function CHILD to be run in the child after the fork.  If no
+   handling is desired then any of PREPARE, PARENT and CHILD may be
+   NULL.  The prepare handles will be called in the reverse order
+   which they were registered and the parent and child handlers in the
+   order in which they were registered.  */
+extern int pthread_atfork (void (*__prepare) (void), void (*__parent) (void),
+			   void (*__child) (void)) __THROW;
+
+
+/* Signals (should be in <signal.h>).  */
+
+/* Send signal SIGNO to thread THREAD.  */
+extern int pthread_kill (pthread_t __thr, int __signo) __THROW;
+
+
+/* Time.  */
+
+#ifdef __USE_XOPEN2K
+/* Return the thread cpu clock.  */
+extern int pthread_getcpuclockid (pthread_t __thr, __clockid_t *__clock)
+	__THROW __nonnull ((2));
+#endif
+
+
+/* Scheduling.  */
+
+/* Return thread THREAD's scheduling paramters.  */
+extern int pthread_getschedparam (pthread_t __thr, int *__restrict __policy,
+				  struct sched_param *__restrict __param)
+	__THROW __nonnull ((2, 3));
+
+/* Set thread THREAD's scheduling paramters.  */
+extern int pthread_setschedparam (pthread_t __thr, int __policy,
+				  const struct sched_param *__param)
+	__THROW __nonnull ((3));
+
+/* Set thread THREAD's scheduling priority.  */
+extern int pthread_setschedprio (pthread_t __thr, int __prio) __THROW;
+
+#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;
+#endif
+
+
+/* Kernel-specific interfaces.  */
+
+#include <bits/pthread-np.h>
+
+
+__END_DECLS
+
+#endif /* pthread.h */
diff --git a/htl/sysdeps/generic/pthread/pthreadtypes.h b/htl/sysdeps/generic/pthread/pthreadtypes.h
new file mode 100644
index 0000000..d8aed4d
--- /dev/null
+++ b/htl/sysdeps/generic/pthread/pthreadtypes.h
@@ -0,0 +1,131 @@
+/* Copyright (C) 2000, 2002, 2005, 2008 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.  */
+
+/*
+ *	POSIX Threads Extension: ???			<pthreadtypes.h>
+ */
+
+#ifndef _PTHREADTYPES_H
+#define _PTHREADTYPES_H	1
+
+#include <features.h>
+
+#include <bits/types.h>
+
+__BEGIN_DECLS
+
+#include <bits/pthread.h>
+typedef __pthread_t pthread_t;
+
+/* Possible values for the process shared attribute.  */
+enum __pthread_process_shared
+  {
+    __PTHREAD_PROCESS_PRIVATE = 0,
+    __PTHREAD_PROCESS_SHARED
+  };
+
+/* Possible values for the inheritsched attribute.  */
+enum __pthread_inheritsched
+  {
+    __PTHREAD_EXPLICIT_SCHED = 0,
+    __PTHREAD_INHERIT_SCHED
+  };
+
+/* Possible values for the `contentionscope' attribute.  */
+enum __pthread_contentionscope
+  {
+    __PTHREAD_SCOPE_SYSTEM = 0,
+    __PTHREAD_SCOPE_PROCESS
+  };
+
+/* Possible values for the `detachstate' attribute.  */
+enum __pthread_detachstate
+  {
+    __PTHREAD_CREATE_JOINABLE = 0,
+    __PTHREAD_CREATE_DETACHED
+  };
+
+#include <bits/thread-attr.h>
+typedef struct __pthread_attr pthread_attr_t;
+
+enum __pthread_mutex_protocol
+  {
+    __PTHREAD_PRIO_NONE= 0,
+    __PTHREAD_PRIO_INHERIT,
+    __PTHREAD_PRIO_PROTECT
+  };
+
+enum __pthread_mutex_type
+  {
+    __PTHREAD_MUTEX_TIMED,
+    __PTHREAD_MUTEX_ERRORCHECK,
+    __PTHREAD_MUTEX_RECURSIVE
+  };
+
+enum __pthread_mutex_robustness
+  {
+    __PTHREAD_MUTEX_STALLED,
+    __PTHREAD_MUTEX_ROBUST = 0x100
+  };
+
+#include <bits/mutex-attr.h>
+typedef struct __pthread_mutexattr pthread_mutexattr_t;
+
+#include <bits/mutex.h>
+typedef struct __pthread_mutex pthread_mutex_t;
+
+#include <bits/condition-attr.h>
+typedef struct __pthread_condattr pthread_condattr_t;
+
+#include <bits/condition.h>
+typedef struct __pthread_cond pthread_cond_t;
+
+#ifdef __USE_XOPEN2K
+# include <bits/spin-lock.h>
+typedef __pthread_spinlock_t pthread_spinlock_t;
+#endif /* XPG6.  */
+
+#if defined __USE_UNIX98 || defined __USE_XOPEN2K
+
+#include <bits/rwlock-attr.h>
+typedef struct __pthread_rwlockattr pthread_rwlockattr_t;
+
+#include <bits/rwlock.h>
+typedef struct __pthread_rwlock pthread_rwlock_t;
+
+#endif /* __USE_UNIX98 || __USE_XOPEN2K */
+
+#ifdef __USE_XOPEN2K
+
+#include <bits/barrier-attr.h>
+typedef struct __pthread_barrierattr pthread_barrierattr_t;
+
+#include <bits/barrier.h>
+typedef struct __pthread_barrier pthread_barrier_t;
+
+#endif /* __USE_XOPEN2K */
+
+#include <bits/thread-specific.h>
+typedef __pthread_key pthread_key_t;
+
+#include <bits/once.h>
+typedef struct __pthread_once pthread_once_t;
+
+__END_DECLS
+
+#endif /* pthreadtypes.h */
diff --git a/htl/sysdeps/generic/raise.c b/htl/sysdeps/generic/raise.c
new file mode 100644
index 0000000..b98cf51
--- /dev/null
+++ b/htl/sysdeps/generic/raise.c
@@ -0,0 +1,51 @@
+/* raise.c - Generic raise implementation.
+   Copyright (C) 2008 Free Software Foundation, Inc.
+   Written by Neal H. Walfield <neal@gnu.org>.
+
+   This file is part of the GNU Hurd.
+
+   The GNU Hurd is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License
+   as published by the Free Software Foundation; either version 3 of
+   the License, or (at your option) any later version.
+
+   The GNU Hurd is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this program.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <pthreadP.h>
+#include <signal.h>
+#include <unistd.h>
+
+#pragma weak __pthread_kill
+#pragma weak __pthread_self
+#pragma weak __pthread_threads
+int
+raise (int signo)
+{
+  /* According to POSIX, if we implement threads (and we do), then
+     "the effect of the raise() function shall be equivalent to
+     calling: pthread_kill(pthread_self(), sig);"  */
+
+  if (__pthread_kill && __pthread_threads)
+    {
+      int err;
+      err = __pthread_kill (__pthread_self (), signo);
+      if (err)
+	{
+	  errno = err;
+	  return -1;
+	}
+      return 0;
+    }
+  else
+    return __kill (__getpid (), signo);
+}
+
+libc_hidden_def (raise)
+weak_alias (raise, gsignal)
diff --git a/htl/sysdeps/generic/sem-close.c b/htl/sysdeps/generic/sem-close.c
new file mode 100644
index 0000000..9f48032
--- /dev/null
+++ b/htl/sysdeps/generic/sem-close.c
@@ -0,0 +1,32 @@
+/* Close a named semaphore.  Generic version.
+   Copyright (C) 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 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 <semaphore.h>
+#include <errno.h>
+
+#include <pt-internal.h>
+
+int
+__sem_close (sem_t *sem)
+{
+  errno = EOPNOTSUPP;
+  return -1;
+}
+
+strong_alias (__sem_close, sem_close);
diff --git a/htl/sysdeps/generic/sem-destroy.c b/htl/sysdeps/generic/sem-destroy.c
new file mode 100644
index 0000000..6486599
--- /dev/null
+++ b/htl/sysdeps/generic/sem-destroy.c
@@ -0,0 +1,38 @@
+/* Destroy a semaphore.  Generic version.
+   Copyright (C) 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 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 <semaphore.h>
+#include <errno.h>
+
+#include <pt-internal.h>
+
+int
+__sem_destroy (sem_t *sem)
+{
+  if (sem->__queue)
+    /* There are threads waiting on *SEM.  */
+    {
+      errno = EBUSY;
+      return -1;
+    }
+
+  return 0;
+}
+
+strong_alias (__sem_destroy, sem_destroy);
diff --git a/htl/sysdeps/generic/sem-getvalue.c b/htl/sysdeps/generic/sem-getvalue.c
new file mode 100644
index 0000000..7762089
--- /dev/null
+++ b/htl/sysdeps/generic/sem-getvalue.c
@@ -0,0 +1,33 @@
+/* Get the value of a semaphore.  Generic version.
+   Copyright (C) 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 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 <semaphore.h>
+#include <pt-internal.h>
+
+int
+__sem_getvalue (sem_t *restrict sem, int *restrict value)
+{
+  __pthread_spin_lock (&sem->__lock);
+  *value = sem->__value;
+  __pthread_spin_unlock (&sem->__lock);
+
+  return 0;
+}
+
+strong_alias (__sem_getvalue, sem_getvalue);
diff --git a/htl/sysdeps/generic/sem-init.c b/htl/sysdeps/generic/sem-init.c
new file mode 100644
index 0000000..d2414f5
--- /dev/null
+++ b/htl/sysdeps/generic/sem-init.c
@@ -0,0 +1,46 @@
+/* Initialize a semaphore.  Generic version.
+   Copyright (C) 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 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 <semaphore.h>
+#include <errno.h>
+
+#include <pt-internal.h>
+
+int
+__sem_init (sem_t *sem, int pshared, unsigned value)
+{
+  if (pshared != 0)
+    {
+      errno = EOPNOTSUPP;
+      return -1;
+    }
+
+#ifdef SEM_VALUE_MAX
+  if (value > SEM_VALUE_MAX)
+    {
+      errno = EINVAL;
+      return -1;
+    }
+#endif
+
+  *sem = (sem_t) __SEMAPHORE_INITIALIZER (pshared, value);
+  return 0;
+}
+
+strong_alias (__sem_init, sem_init);
diff --git a/htl/sysdeps/generic/sem-open.c b/htl/sysdeps/generic/sem-open.c
new file mode 100644
index 0000000..bae87ed
--- /dev/null
+++ b/htl/sysdeps/generic/sem-open.c
@@ -0,0 +1,32 @@
+/* Open a named semaphore.  Generic version.
+   Copyright (C) 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 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 <semaphore.h>
+#include <errno.h>
+
+#include <pt-internal.h>
+
+sem_t *
+__sem_open (const char *name, int open_flags, ...)
+{
+  errno = EOPNOTSUPP;
+  return SEM_FAILED;
+}
+
+strong_alias (__sem_open, sem_open);
diff --git a/htl/sysdeps/generic/sem-post.c b/htl/sysdeps/generic/sem-post.c
new file mode 100644
index 0000000..6d438bf
--- /dev/null
+++ b/htl/sysdeps/generic/sem-post.c
@@ -0,0 +1,62 @@
+/* Post a semaphore.  Generic version.
+   Copyright (C) 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 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 <semaphore.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+int
+__sem_post (sem_t *sem)
+{
+  struct __pthread *wakeup;
+
+  __pthread_spin_lock (&sem->__lock);
+  if (sem->__value > 0)
+    /* Do a quick up.  */
+    {
+      assert (! sem->__queue);
+      sem->__value ++;
+      __pthread_spin_unlock (&sem->__lock);
+      return 0;
+    }
+
+  if (! sem->__queue)
+    /* No one waiting.  */
+    {
+      sem->__value = 1;
+      __pthread_spin_unlock (&sem->__lock);
+      return 0;
+    }
+
+  /* Wake someone up.  */
+
+  /* First dequeue someone.  */
+  wakeup = sem->__queue;
+  __pthread_dequeue (wakeup);
+
+  /* Then drop the lock and transfer control.  */
+  __pthread_spin_unlock (&sem->__lock);
+
+  __pthread_wakeup (wakeup);
+
+  return 0;
+}
+
+strong_alias (__sem_post, sem_post);
diff --git a/htl/sysdeps/generic/sem-timedwait.c b/htl/sysdeps/generic/sem-timedwait.c
new file mode 100644
index 0000000..11c1391
--- /dev/null
+++ b/htl/sysdeps/generic/sem-timedwait.c
@@ -0,0 +1,100 @@
+/* Wait on a semaphore with a timeout.  Generic version.
+   Copyright (C) 2005, 2006, 2008 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 <semaphore.h>
+#include <errno.h>
+#include <assert.h>
+
+#include <pt-internal.h>
+
+int
+__sem_timedwait_internal (sem_t *restrict sem,
+			  const struct timespec *restrict timeout)
+{
+  error_t err;
+  int drain;
+  struct __pthread *self;
+
+  __pthread_spin_lock (&sem->__lock);
+  if (sem->__value > 0)
+    /* Successful down.  */
+    {
+      sem->__value --;
+      __pthread_spin_unlock (&sem->__lock);
+      return 0;
+    }
+
+  if (timeout && (timeout->tv_nsec < 0 || timeout->tv_nsec >= 1000000000))
+    {
+      errno = EINVAL;
+      return -1;
+    }
+
+  /* Add ourselves to the queue.  */
+  self = _pthread_self ();
+
+  __pthread_enqueue (&sem->__queue, self);
+  __pthread_spin_unlock (&sem->__lock);
+
+  /* Block the thread.  */
+  if (timeout)
+    err = __pthread_timedblock (self, timeout, CLOCK_REALTIME);
+  else
+    {
+      err = 0;
+      __pthread_block (self);
+    }
+
+  __pthread_spin_lock (&sem->__lock);
+  if (! self->prevp)
+    /* Another thread removed us from the queue, which means a wakeup message
+       has been sent.  It was either consumed while we were blocking, or
+       queued after we timed out and before we acquired the semaphore lock, in
+       which case the message queue must be drained.  */
+    drain = err ? 1 : 0;
+  else
+    {
+      /* We're still in the queue.  Noone attempted to wake us up, i.e. we
+	 timed out.  */
+      __pthread_dequeue (self);
+      drain = 0;
+    }
+  __pthread_spin_unlock (&sem->__lock);
+
+  if (drain)
+    __pthread_block (self);
+
+  if (err)
+    {
+      assert (err == ETIMEDOUT);
+      errno = err;
+      return -1;
+    }
+
+  return 0;
+}
+
+int
+__sem_timedwait (sem_t *restrict sem,
+		 const struct timespec *restrict timeout)
+{
+  return __sem_timedwait_internal (sem, timeout);
+}
+
+weak_alias (__sem_timedwait, sem_timedwait);
diff --git a/htl/sysdeps/generic/sem-trywait.c b/htl/sysdeps/generic/sem-trywait.c
new file mode 100644
index 0000000..437e282
--- /dev/null
+++ b/htl/sysdeps/generic/sem-trywait.c
@@ -0,0 +1,42 @@
+/* Lock a semaphore if it does not require blocking.  Generic version.
+   Copyright (C) 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 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 <semaphore.h>
+#include <errno.h>
+
+#include <pt-internal.h>
+
+int
+__sem_trywait (sem_t *sem)
+{
+  __pthread_spin_lock (&sem->__lock);
+  if (sem->__value > 0)
+    /* Successful down.  */
+    {
+      sem->__value --;
+      __pthread_spin_unlock (&sem->__lock);
+      return 0;
+    }
+  __pthread_spin_unlock (&sem->__lock);
+
+  errno = EAGAIN;
+  return -1;
+}
+
+strong_alias (__sem_trywait, sem_trywait);
diff --git a/htl/sysdeps/generic/sem-unlink.c b/htl/sysdeps/generic/sem-unlink.c
new file mode 100644
index 0000000..570ed61
--- /dev/null
+++ b/htl/sysdeps/generic/sem-unlink.c
@@ -0,0 +1,32 @@
+/* Unlink a named semaphore.  Generic version.
+   Copyright (C) 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 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 <semaphore.h>
+#include <errno.h>
+
+#include <pt-internal.h>
+
+int
+__sem_unlink (const char *name)
+{
+  errno = EOPNOTSUPP;
+  return -1;
+}
+
+strong_alias (__sem_unlink, sem_unlink);
diff --git a/htl/sysdeps/generic/sem-wait.c b/htl/sysdeps/generic/sem-wait.c
new file mode 100644
index 0000000..8347480
--- /dev/null
+++ b/htl/sysdeps/generic/sem-wait.c
@@ -0,0 +1,32 @@
+/* Wait on a semaphore.  Generic version.
+   Copyright (C) 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 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 <semaphore.h>
+#include <pt-internal.h>
+
+extern int __sem_timedwait_internal (sem_t *restrict sem,
+				     const struct timespec *restrict timeout);
+
+int
+__sem_wait (sem_t *sem)
+{
+  return __sem_timedwait_internal (sem, 0);
+}
+
+strong_alias (__sem_wait, sem_wait);
diff --git a/htl/sysdeps/generic/shm-directory.h b/htl/sysdeps/generic/shm-directory.h
new file mode 100644
index 0000000..8950284
--- /dev/null
+++ b/htl/sysdeps/generic/shm-directory.h
@@ -0,0 +1,31 @@
+/* Header for directory for shm/sem files.  libpthread version.
+   Copyright (C) 2014-2015 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _SHM_DIRECTORY_H
+
+#include <sysdeps/posix/shm-directory.h>
+
+/* For libpthread the __shm_directory function lives in libpthread.
+   We don't want PLT calls from there.  But it's also used from
+   librt, so it cannot just be declared hidden.  */
+
+#if IS_IN (libpthread)
+hidden_proto (__shm_directory)
+#endif
+
+#endif  /* shm-directory.h */
diff --git a/htl/sysdeps/hurd/pt-kill.c b/htl/sysdeps/hurd/pt-kill.c
new file mode 100644
index 0000000..6aaf241
--- /dev/null
+++ b/htl/sysdeps/hurd/pt-kill.c
@@ -0,0 +1,52 @@
+/* pthread_kill.  Hurd 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.  */
+
+#include <pthread.h>
+#include <assert.h>
+#include <signal.h>
+#include <hurd/signal.h>
+
+#include <pt-internal.h>
+
+int
+__pthread_kill (pthread_t thread, int sig)
+{
+  struct __pthread *pthread;
+  struct hurd_signal_detail detail;
+  struct hurd_sigstate *ss;
+
+  /* Lookup the thread structure for THREAD.  */
+  pthread = __pthread_getid (thread);
+  if (pthread == NULL)
+    return ESRCH;
+
+  ss = _hurd_thread_sigstate (pthread->kernel_thread);
+  assert (ss);
+
+  if (!sig)
+    return 0;
+
+  detail.exc = 0;
+  detail.code = sig;
+  detail.error = 0;
+
+  __spin_lock (&ss->lock);
+  return _hurd_raise_signal (ss, sig, &detail);
+}
+strong_alias (__pthread_kill, pthread_kill)
diff --git a/htl/sysdeps/i386/bits/memory.h b/htl/sysdeps/i386/bits/memory.h
new file mode 100644
index 0000000..932c408
--- /dev/null
+++ b/htl/sysdeps/i386/bits/memory.h
@@ -0,0 +1,40 @@
+/* Memory barrier operations.  i386 version.
+   Copyright (C) 2002, 2008 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.  */
+
+#ifndef _BITS_MEMORY_H
+#define _BITS_MEMORY_H	1
+
+/* Prevent read and write reordering across this function.  */
+static inline void
+__memory_barrier (void)
+{
+  int i;
+
+  /* Any lock'ed instruction will do.  We just do a simple
+     increment.  */
+  __asm__ __volatile ("lock; incl %0" : "=m" (i) : "m" (i) : "memory");
+}
+
+/* Prevent read reordering across this function.  */
+#define __memory_read_barrier __memory_barrier
+
+/* Prevent write reordering across this function.  */
+#define __memory_write_barrier __memory_barrier
+
+#endif
diff --git a/htl/sysdeps/i386/bits/pt-atomic.h b/htl/sysdeps/i386/bits/pt-atomic.h
new file mode 100644
index 0000000..0dfc1f6
--- /dev/null
+++ b/htl/sysdeps/i386/bits/pt-atomic.h
@@ -0,0 +1,66 @@
+/* Atomic operations.  i386 version.
+   Copyright (C) 2000 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.  */
+
+#ifndef _BITS_ATOMIC_H
+#define _BITS_ATOMIC_H	1
+
+typedef __volatile int __atomic_t;
+
+static inline void
+__atomic_inc (__atomic_t *__var)
+{
+  __asm__ __volatile ("lock; incl %0" : "=m" (*__var) : "m" (*__var));
+}
+
+static inline void
+__atomic_dec (__atomic_t *__var)
+{
+  __asm__ __volatile ("lock; decl %0" : "=m" (*__var) : "m" (*__var));
+}
+
+static inline int
+__atomic_dec_and_test (__atomic_t *__var)
+{
+  unsigned char __ret;
+
+  __asm__ __volatile ("lock; decl %0; sete %1"
+		      : "=m" (*__var), "=qm" (__ret) : "m" (*__var));
+  return __ret != 0;
+}
+
+/* We assume that an __atomicptr_t is only used for pointers to
+   word-aligned objects, and use the lowest bit for a simple lock.  */
+typedef __volatile int * __atomicptr_t;
+
+/* Actually we don't implement that yet, and assume that we run on
+   something that has the i486 instruction set.  */
+static inline int
+__atomicptr_compare_and_swap (__atomicptr_t *__ptr, void *__oldval,
+			      void * __newval)
+{
+  char __ret;
+  int __dummy;
+
+  __asm__ __volatile ("lock; cmpxchgl %3, %1; sete %0"
+		      : "=q" (__ret), "=m" (*__ptr), "=a" (__dummy)
+		      : "r" (__newval), "m" (*__ptr), "a" (__oldval));
+  return __ret;
+}
+
+#endif
diff --git a/htl/sysdeps/i386/bits/pthreadtypes-arch.h b/htl/sysdeps/i386/bits/pthreadtypes-arch.h
new file mode 100644
index 0000000..7e7a311
--- /dev/null
+++ b/htl/sysdeps/i386/bits/pthreadtypes-arch.h
@@ -0,0 +1,21 @@
+/* Copyright (C) 2002-2017 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _BITS_PTHREADTYPES_ARCH_H
+#define _BITS_PTHREADTYPES_ARCH_H	1
+
+#endif	/* bits/pthreadtypes.h */
diff --git a/htl/sysdeps/i386/machine-sp.h b/htl/sysdeps/i386/machine-sp.h
new file mode 100644
index 0000000..cef6ab7
--- /dev/null
+++ b/htl/sysdeps/i386/machine-sp.h
@@ -0,0 +1,30 @@
+/* Machine-specific function to return the stack pointer.  i386 version.
+   Copyright (C) 1994, 1997, 2001, 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 _MACHINE_SP_H
+#define _MACHINE_SP_H
+
+/* Return the current stack pointer.  */
+
+#define __thread_stack_pointer() ({					      \
+  register void *__sp__ asm("esp");					      \
+  __sp__;								      \
+})
+
+#endif	/* machine-sp.h */
diff --git a/htl/sysdeps/i386/pt-machdep.h b/htl/sysdeps/i386/pt-machdep.h
new file mode 100644
index 0000000..6d45636
--- /dev/null
+++ b/htl/sysdeps/i386/pt-machdep.h
@@ -0,0 +1,29 @@
+/* Machine dependent pthreads internal defenitions.  i386 version.
+   Copyright (C) 2000 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.  */
+
+#ifndef _PT_MACHDEP_H
+#define _PT_MACHDEP_H	1
+
+struct pthread_mcontext
+{
+  void *pc;
+  void *sp;
+};
+
+#endif /* pt-machdep.h */
diff --git a/htl/sysdeps/mach/bits/spin-lock-inline.h b/htl/sysdeps/mach/bits/spin-lock-inline.h
new file mode 100644
index 0000000..98e4b3b
--- /dev/null
+++ b/htl/sysdeps/mach/bits/spin-lock-inline.h
@@ -0,0 +1,88 @@
+/* Definitions of user-visible names for spin locks.
+   Copyright (C) 1994, 1997, 2002, 2008, 2009 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_SPIN_LOCK_INLINE_H
+#define _BITS_SPIN_LOCK_INLINE_H	1
+
+#include <features.h>
+#include <bits/spin-lock.h>
+#include <lock-intern.h>   /* This does all the work.  */
+
+__BEGIN_DECLS
+
+#if defined __USE_EXTERN_INLINES || defined _FORCE_INLINES
+
+# ifndef __EBUSY
+#  include <errno.h>
+#  define __EBUSY EBUSY
+# endif
+
+# ifndef __PT_SPIN_INLINE
+#  define __PT_SPIN_INLINE __extern_inline
+# endif
+
+__PT_SPIN_INLINE int __pthread_spin_destroy (__pthread_spinlock_t *__lock);
+
+__PT_SPIN_INLINE int
+__pthread_spin_destroy (__pthread_spinlock_t *__lock)
+{
+  return 0;
+}
+
+__PT_SPIN_INLINE int __pthread_spin_init (__pthread_spinlock_t *__lock,
+					  int __pshared);
+
+__PT_SPIN_INLINE int
+__pthread_spin_init (__pthread_spinlock_t *__lock, int __pshared)
+{
+  *__lock = __PTHREAD_SPIN_LOCK_INITIALIZER;
+  return 0;
+}
+
+__PT_SPIN_INLINE int __pthread_spin_trylock (__pthread_spinlock_t *__lock);
+
+__PT_SPIN_INLINE int
+__pthread_spin_trylock (__pthread_spinlock_t *__lock)
+{
+  return __spin_try_lock ((__spin_lock_t *) __lock) ? 0 : __EBUSY;
+}
+
+__PT_SPIN_INLINE int __pthread_spin_lock (__pthread_spinlock_t *__lock);
+
+__PT_SPIN_INLINE int
+__pthread_spin_lock (__pthread_spinlock_t *__lock)
+{
+  __spin_lock ((__spin_lock_t *) __lock);
+  return 0;
+}
+
+__PT_SPIN_INLINE int __pthread_spin_unlock (__pthread_spinlock_t *__lock);
+
+__PT_SPIN_INLINE int
+__pthread_spin_unlock (__pthread_spinlock_t *__lock)
+{
+  __spin_unlock ((__spin_lock_t *) __lock);
+  return 0;
+}
+
+#endif /* Use extern inlines or force inlines.  */
+
+__END_DECLS
+
+#endif /* bits/spin-lock.h */
diff --git a/htl/sysdeps/mach/bits/spin-lock.h b/htl/sysdeps/mach/bits/spin-lock.h
new file mode 100644
index 0000000..7574b37
--- /dev/null
+++ b/htl/sysdeps/mach/bits/spin-lock.h
@@ -0,0 +1,35 @@
+/* Definitions of user-visible names for spin locks.
+   Copyright (C) 1994, 1997, 2002, 2008, 2009 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_SPIN_LOCK_H
+#define _BITS_SPIN_LOCK_H	1
+
+#include <features.h>
+
+__BEGIN_DECLS
+
+/* The type of a spin lock object.  */
+typedef volatile int __pthread_spinlock_t;
+
+/* Initializer for a spin lock object.  */
+#define __PTHREAD_SPIN_LOCK_INITIALIZER 0
+
+__END_DECLS
+
+#endif /* bits/spin-lock.h */
diff --git a/htl/sysdeps/mach/hurd/Implies b/htl/sysdeps/mach/hurd/Implies
new file mode 100644
index 0000000..c32378a
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/Implies
@@ -0,0 +1,2 @@
+hurd
+pthread
diff --git a/htl/sysdeps/mach/hurd/bits/mutex.h b/htl/sysdeps/mach/hurd/bits/mutex.h
new file mode 100644
index 0000000..a52a2ad
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/bits/mutex.h
@@ -0,0 +1,64 @@
+/* Mutex type.  Generic version.
+
+   Copyright (C) 2000-2016
+     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.  */
+
+#ifndef _BITS_MUTEX_H
+
+#ifndef __need_pthread_mutex
+# define _BITS_MUTEX_H	1
+#endif
+
+#ifndef __pthread_mutex_defined
+# if defined __need_pthread_mutex || defined _BITS_MUTEX_H
+#  undef __need_pthread_mutex
+#  define __pthread_mutex_defined
+
+#  include <bits/mutex-attr.h>
+
+/* User visible part of a mutex.  */
+struct __pthread_mutex
+{
+  unsigned int __lock;
+  unsigned int __owner_id;
+  unsigned int __cnt;
+  int __shpid;
+  int __type;
+  int __flags;
+  unsigned int __reserved1;
+  unsigned int __reserved2;
+};
+
+/* Static mutex initializers. */
+#define __PTHREAD_MUTEX_INITIALIZER   \
+  { 0, 0, 0, 0, __PTHREAD_MUTEX_TIMED, 0, 0, 0 }
+
+/* The +1 is to mantain binary compatibility with the old
+ * libpthread implementation. */
+#define __PTHREAD_ERRORCHECK_MUTEX_INITIALIZER   \
+  { 0, 0, 0, 0, __PTHREAD_MUTEX_ERRORCHECK + 1, 0, 0, 0 }
+
+#define __PTHREAD_RECURSIVE_MUTEX_INITIALIZER   \
+  { 0, 0, 0, 0, __PTHREAD_MUTEX_RECURSIVE + 1, 0, 0, 0 }
+
+# endif
+#endif /* Not __pthread_mutex_defined.  */
+
+#endif /* bits/mutex.h */
diff --git a/htl/sysdeps/mach/hurd/bits/pthread-np.h b/htl/sysdeps/mach/hurd/bits/pthread-np.h
new file mode 100644
index 0000000..4487ffd
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/bits/pthread-np.h
@@ -0,0 +1,38 @@
+/* Non-portable functions. Hurd on Mach version.
+   Copyright (C) 2008 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.  */
+
+/*
+ * Never include this file directly; use <pthread.h> or <cthreads.h> instead.
+ */
+
+#ifndef _BITS_PTHREAD_NP_H
+#define _BITS_PTHREAD_NP_H	1
+
+/* Same as pthread_cond_wait, but for Hurd-specific cancellation.
+   See hurd_thread_cancel.  */
+extern int pthread_hurd_cond_wait_np (pthread_cond_t *__restrict __cond,
+				      pthread_mutex_t *__restrict __mutex);
+
+/* Same as pthread_cond_timedwait, but for Hurd-specific cancellation.
+   See hurd_thread_cancel.  */
+extern int pthread_hurd_cond_timedwait_np (pthread_cond_t *__restrict __cond,
+					   pthread_mutex_t *__restrict __mutex,
+					   const struct timespec *__abstime);
+
+#endif /* bits/pthread-np.h */
diff --git a/htl/sysdeps/mach/hurd/i386/pt-machdep.c b/htl/sysdeps/mach/hurd/i386/pt-machdep.c
new file mode 100644
index 0000000..f3c8cf5
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/i386/pt-machdep.c
@@ -0,0 +1,83 @@
+/* Machine dependent pthreads code.  Hurd/i386 version.
+   Copyright (C) 2000, 2002, 2007 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 <mach.h>
+#include <mach/i386/thread_status.h>
+#include <mach/i386/mach_i386.h>
+#include <mach/mig_errors.h>
+#include <mach/thread_status.h>
+
+#define HURD_TLS_DESC_DECL(desc, tcb)					      \
+  struct descriptor desc =						      \
+    {				/* low word: */				      \
+      0xffff			/* limit 0..15 */			      \
+      | (((unsigned int) (tcb)) << 16) /* base 0..15 */			      \
+      ,				/* high word: */			      \
+      ((((unsigned int) (tcb)) >> 16) & 0xff) /* base 16..23 */		      \
+      | ((0x12 | 0x60 | 0x80) << 8) /* access = ACC_DATA_W|ACC_PL_U|ACC_P */  \
+      | (0xf << 16)		/* limit 16..19 */			      \
+      | ((4 | 8) << 20)		/* granularity = SZ_32|SZ_G */		      \
+      | (((unsigned int) (tcb)) & 0xff000000) /* base 24..31 */		      \
+    }
+
+int
+__thread_set_pcsptp (thread_t thread,
+		   int set_ip, void *ip,
+		   int set_sp, void *sp,
+		   int set_tp, void *tp)
+{
+  error_t err;
+  struct i386_thread_state state;
+  mach_msg_type_number_t state_count;
+
+  state_count = i386_THREAD_STATE_COUNT;
+
+  err = __thread_get_state (thread, i386_REGS_SEGS_STATE,
+			    (thread_state_t) &state, &state_count);
+  if (err)
+    return err;
+
+  if (set_sp)
+    state.uesp = (unsigned int) sp;
+  if (set_ip)
+    state.eip = (unsigned int) ip;
+  if (set_tp) {
+    HURD_TLS_DESC_DECL(desc, tp);
+    int sel;
+
+    asm ("mov %%gs, %w0" : "=q" (sel) : "0" (0));
+    if (__builtin_expect (sel, 0x48) & 4) /* LDT selector */
+      err = __i386_set_ldt (thread, sel, &desc, 1);
+    else
+      err = __i386_set_gdt (thread, &sel, desc);
+    if (err)
+      return err;
+    state.gs = sel;
+  }
+
+  err = __thread_set_state (thread, i386_REGS_SEGS_STATE,
+			    (thread_state_t) &state,
+			    i386_THREAD_STATE_COUNT);
+  if (err)
+    return err;
+
+  return 0;
+}
diff --git a/htl/sysdeps/mach/hurd/i386/pt-setup.c b/htl/sysdeps/mach/hurd/i386/pt-setup.c
new file mode 100644
index 0000000..4511463
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/i386/pt-setup.c
@@ -0,0 +1,110 @@
+/* Setup thread stack.  Hurd/i386 version.
+   Copyright (C) 2000, 2002, 2005, 2007, 2008 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 <stdint.h>
+#include <assert.h>
+#include <mach.h>
+
+#include <pt-internal.h>
+
+/* The stack layout used on the i386 is:
+
+    -----------------
+   |  ARG            |
+    -----------------
+   |  START_ROUTINE  |
+    -----------------
+   |  0              |
+    -----------------
+ */
+
+/* Set up the stack for THREAD, such that it appears as if
+   START_ROUTINE and ARG were passed to the new thread's entry-point.
+   Return the stack pointer for the new thread.  */
+static void *
+stack_setup (struct __pthread *thread,
+	     void *(*start_routine)(void *), void *arg)
+{
+  error_t err;
+  uintptr_t *bottom, *top;
+
+  /* Calculate the top of the new stack.  */
+  bottom = thread->stackaddr;
+  top = (uintptr_t *) ((uintptr_t) bottom + thread->stacksize
+        + ((thread->guardsize + __vm_page_size-1)
+	   / __vm_page_size) * __vm_page_size);
+
+  if (start_routine)
+    {
+      /* And then the call frame.  */
+      top -= 3;
+      top = (uintptr_t *) ((uintptr_t) top & ~0xf);
+      top[2] = (uintptr_t) arg;	/* Argument to START_ROUTINE.  */
+      top[1] = (uintptr_t) start_routine;
+      top[0] = (uintptr_t) thread;
+      *--top = 0;		/* Fake return address.  */
+    }
+
+  if (thread->guardsize)
+    {
+      err = __vm_protect (__mach_task_self (), (vm_address_t) bottom,
+			  thread->guardsize, 0, 0);
+      assert_perror (err);
+    }
+
+  return top;
+}
+
+int
+__pthread_setup (struct __pthread *thread,
+		 void (*entry_point)(struct __pthread *, void *(*)(void *), void *),
+		 void *(*start_routine)(void *), void *arg)
+{
+  tcbhead_t *tcb;
+  error_t err;
+  mach_port_t ktid;
+
+  thread->mcontext.pc = entry_point;
+  thread->mcontext.sp = stack_setup (thread, start_routine, arg);
+
+  ktid = __mach_thread_self ();
+  if (thread->kernel_thread == ktid)
+    /* Fix up the TCB for the main thread.  The C library has already
+       installed a TCB, which we want to keep using.  This TCB must not
+       be freed so don't register it in the thread structure.  On the
+       other hand, it's not yet possible to reliably release a TCB.
+       Leave the unused one registered so that it doesn't leak.  The
+       only thing left to do is to correctly set the `self' member in
+       the already existing TCB.  */
+    tcb = THREAD_SELF;
+  else
+    {
+      err = __thread_set_pcsptp (thread->kernel_thread,
+			       1, thread->mcontext.pc,
+			       1, thread->mcontext.sp,
+			       1, thread->tcb);
+      assert_perror (err);
+      tcb = thread->tcb;
+    }
+  __mach_port_deallocate (__mach_task_self (), ktid);
+
+  tcb->self = thread->kernel_thread;
+
+  return 0;
+}
diff --git a/htl/sysdeps/mach/hurd/pt-attr-setstackaddr.c b/htl/sysdeps/mach/hurd/pt-attr-setstackaddr.c
new file mode 100644
index 0000000..864835f
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-attr-setstackaddr.c
@@ -0,0 +1,29 @@
+/* pthread_attr_setstackaddr.  Hurd on Mach 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_setstackaddr (pthread_attr_t *attr,
+			   void *stackaddr)
+{
+  attr->__stackaddr = stackaddr;
+  return 0;
+}
diff --git a/htl/sysdeps/mach/hurd/pt-attr-setstacksize.c b/htl/sysdeps/mach/hurd/pt-attr-setstacksize.c
new file mode 100644
index 0000000..7757bac
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-attr-setstacksize.c
@@ -0,0 +1,29 @@
+/* pthread_attr_setstacksize.  Hurd on Mach 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+int
+pthread_attr_setstacksize (pthread_attr_t *attr,
+			   size_t stacksize)
+{
+  attr->__stacksize = stacksize;
+  return 0;
+}
diff --git a/htl/sysdeps/mach/hurd/pt-docancel.c b/htl/sysdeps/mach/hurd/pt-docancel.c
new file mode 100644
index 0000000..b3a5507
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-docancel.c
@@ -0,0 +1,66 @@
+/* Cancel a thread.
+   Copyright (C) 2002, 2007, 2008 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 <pthread.h>
+
+#include <pt-internal.h>
+
+static void
+call_exit (void)
+{
+  pthread_exit (0);
+}
+
+int
+__pthread_do_cancel (struct __pthread *p)
+{
+  mach_port_t ktid;
+  int me;
+
+  assert (p->cancel_pending == 1);
+  assert (p->cancel_state == PTHREAD_CANCEL_ENABLE);
+
+  __pthread_mutex_unlock (&p->cancel_lock);
+
+  ktid = __mach_thread_self ();
+  me = p->kernel_thread == ktid;
+  __mach_port_deallocate (__mach_task_self (), ktid);
+
+  if (me)
+    call_exit ();
+  else
+    {
+      error_t err;
+      
+      err = __thread_suspend (p->kernel_thread);
+      assert_perror (err);
+
+      err = __thread_abort (p->kernel_thread);
+      assert_perror (err);
+
+      err = __thread_set_pcsptp (p->kernel_thread,
+			       1, (void *) call_exit, 0, 0, 0, 0);
+      assert_perror (err);
+
+      err = __thread_resume (p->kernel_thread);
+      assert_perror (err);
+    }
+
+  return 0;
+}
diff --git a/htl/sysdeps/mach/hurd/pt-hurd-cond-timedwait.c b/htl/sysdeps/mach/hurd/pt-hurd-cond-timedwait.c
new file mode 100644
index 0000000..3d1fe53
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-hurd-cond-timedwait.c
@@ -0,0 +1,169 @@
+/* pthread_hurd_cond_timedwait_np.  Hurd-specific wait on a condition.
+   Copyright (C) 2012 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 <pthread.h>
+#include <assert.h>
+#include <hurd/signal.h>
+
+#include <pt-internal.h>
+
+extern int __pthread_hurd_cond_timedwait_internal (pthread_cond_t *cond,
+						   pthread_mutex_t *mutex,
+						   const struct timespec *abstime);
+
+int
+__pthread_hurd_cond_timedwait_np (pthread_cond_t *cond,
+				  pthread_mutex_t *mutex,
+				  const struct timespec *abstime)
+{
+  return __pthread_hurd_cond_timedwait_internal (cond, mutex, abstime);
+}
+
+strong_alias (__pthread_hurd_cond_timedwait_np, pthread_hurd_cond_timedwait_np);
+
+int
+__pthread_hurd_cond_timedwait_internal (pthread_cond_t *cond,
+					pthread_mutex_t *mutex,
+					const struct timespec *abstime)
+{
+  struct hurd_sigstate *ss = _hurd_self_sigstate ();
+  struct __pthread *self = _pthread_self ();
+  error_t err = 0;
+  int cancel, drain;
+  clockid_t clock_id = __pthread_default_condattr.__clock;
+
+  /* This function will be called by hurd_thread_cancel while we are blocked
+     We wake up our thread if it's still blocking or about to block, so it will
+     progress and notice the cancellation flag.  */
+  void cancel_me (void)
+    {
+      int unblock;
+
+      __pthread_spin_lock (&cond->__lock);
+      /* The thread only needs to be awaken if it's blocking or about to block.
+	 If it was already unblocked, it's not queued any more.  */
+      unblock = self->prevp != NULL;
+      if (unblock)
+	__pthread_dequeue (self);
+      __pthread_spin_unlock (&cond->__lock);
+
+      if (unblock)
+	__pthread_wakeup (self);
+    }
+
+  assert (ss->intr_port == MACH_PORT_NULL); /* Sanity check for signal bugs. */
+
+  if (abstime && (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000))
+    return EINVAL;
+
+  /* Atomically enqueue our thread on the condition variable's queue of
+     waiters, and mark our sigstate to indicate that `cancel_me' must be
+     called to wake us up.  We must hold the sigstate lock while acquiring
+     the condition variable's lock and tweaking it, so that
+     hurd_thread_cancel can never suspend us and then deadlock waiting for
+     the condition variable's lock.  */
+
+  __spin_lock (&ss->lock);
+  __pthread_spin_lock (&cond->__lock);
+  cancel = ss->cancel;
+  if (cancel)
+    /* We were cancelled before doing anything.  Don't block at all.  */
+    ss->cancel = 0;
+  else
+    {
+      /* Put us on the queue so that pthread_cond_broadcast will know to wake
+         us up.  */
+      __pthread_enqueue (&cond->__queue, self);
+      if (cond->__attr)
+	clock_id = cond->__attr->__clock;
+      /* Tell hurd_thread_cancel how to unblock us.  */
+      ss->cancel_hook = &cancel_me;
+    }
+  __pthread_spin_unlock (&cond->__lock);
+  __spin_unlock (&ss->lock);
+
+  if (cancel)
+    {
+      /* Cancelled on entry.  Just leave the mutex locked.  */
+      mutex = NULL;
+
+      __spin_lock (&ss->lock);
+    }
+  else
+    {
+      /* Release MUTEX before blocking.  */
+      __pthread_mutex_unlock (mutex);
+
+      /* Block the thread.  */
+      if (abstime)
+	err = __pthread_timedblock (self, abstime, clock_id);
+      else
+	{
+	  err = 0;
+	  __pthread_block (self);
+	}
+
+      /* As it was done when enqueueing, prevent hurd_thread_cancel from
+	 suspending us while the condition lock is held.  */
+      __spin_lock (&ss->lock);
+      __pthread_spin_lock (&cond->__lock);
+      if (! self->prevp)
+	/* Another thread removed us from the list of waiters, which means
+	   a wakeup message has been sent.  It was either consumed while
+	   we were blocking, or queued after we timed out and before we
+	   acquired the condition lock, in which case the message queue
+	   must be drained.  */
+	drain = err ? 1 : 0;
+      else
+	{
+	  /* We're still in the list of waiters.  Noone attempted to wake us
+	     up, i.e. we timed out.  */
+	  __pthread_dequeue (self);
+	  drain = 0;
+	}
+      __pthread_spin_unlock (&cond->__lock);
+
+      if (drain)
+	__pthread_block (self);
+    }
+
+  /* Clear the hook, now that we are done blocking.  */
+  ss->cancel_hook = NULL;
+  /* Check the cancellation flag; we might have unblocked due to
+     cancellation rather than a normal pthread_cond_signal or
+     pthread_cond_broadcast (or we might have just happened to get cancelled
+     right after waking up).  */
+  cancel |= ss->cancel;
+  ss->cancel = 0;
+  __spin_unlock (&ss->lock);
+
+  if (mutex)
+    /* Reacquire the mutex and return.  */
+    __pthread_mutex_lock (mutex);
+
+  if (cancel)
+    return EINTR;
+  else if (err)
+    {
+      assert (err == ETIMEDOUT);
+      return err;
+    }
+
+  return 0;
+}
diff --git a/htl/sysdeps/mach/hurd/pt-hurd-cond-wait.c b/htl/sysdeps/mach/hurd/pt-hurd-cond-wait.c
new file mode 100644
index 0000000..5e7c007
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-hurd-cond-wait.c
@@ -0,0 +1,41 @@
+/* pthread_hurd_cond_wait.  Hurd-specific wait on a condition.
+   Copyright (C) 2012 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 <pthread.h>
+#include <assert.h>
+#include <hurd/signal.h>
+
+#include <pt-internal.h>
+
+/* Implemented in pt-hurd-cond-timedwait.c.  */
+extern int __pthread_hurd_cond_timedwait_internal (pthread_cond_t *cond,
+						   pthread_mutex_t *mutex,
+						   const struct timespec *abstime);
+
+int
+__pthread_hurd_cond_wait_np (pthread_cond_t *cond,
+			     pthread_mutex_t *mutex)
+{
+  error_t err;
+
+  err = __pthread_hurd_cond_timedwait_internal (cond, mutex, NULL);
+  return (err == EINTR);
+}
+
+strong_alias (__pthread_hurd_cond_wait_np, pthread_hurd_cond_wait_np);
diff --git a/htl/sysdeps/mach/hurd/pt-mutex-consistent.c b/htl/sysdeps/mach/hurd/pt-mutex-consistent.c
new file mode 100644
index 0000000..28e9e4a
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutex-consistent.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutex_consistent (pthread_mutex_t *mtxp)
+{
+  int ret = EINVAL;
+  unsigned int val = mtxp->__lock;
+
+  if ((mtxp->__flags & PTHREAD_MUTEX_ROBUST) != 0 &&
+      (val & LLL_DEAD_OWNER) != 0 &&
+      atomic_compare_and_exchange_bool_acq (&mtxp->__lock,
+        __getpid () | LLL_WAITERS, val) == 0)
+    {
+      /* The mutex is now ours, and it's consistent. */
+      mtxp->__owner_id = _pthread_self()->thread;
+      mtxp->__cnt = 1;
+      ret = 0;
+    }
+
+  return (ret);
+}
+
+weak_alias (pthread_mutex_consistent, pthread_mutex_consistent_np)
diff --git a/htl/sysdeps/mach/hurd/pt-mutex-destroy.c b/htl/sysdeps/mach/hurd/pt-mutex-destroy.c
new file mode 100644
index 0000000..2c6acd1
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutex-destroy.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int _pthread_mutex_destroy (pthread_mutex_t *mtxp)
+{
+  atomic_read_barrier ();
+  if (*(volatile unsigned int *)&mtxp->__lock != 0)
+    return (EBUSY);
+
+  mtxp->__type = -1;
+  return (0);
+}
+
+strong_alias (_pthread_mutex_destroy, pthread_mutex_destroy)
diff --git a/htl/sysdeps/mach/hurd/pt-mutex-getprioceiling.c b/htl/sysdeps/mach/hurd/pt-mutex-getprioceiling.c
new file mode 100644
index 0000000..8a8a080
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutex-getprioceiling.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutex_getprioceiling (const pthread_mutex_t *mtxp, int *clp)
+{
+  (void)mtxp; (void)clp;
+  return (ENOSYS);
+}
+
+stub_warning (pthread_mutex_getprioceiling)
diff --git a/htl/sysdeps/mach/hurd/pt-mutex-init.c b/htl/sysdeps/mach/hurd/pt-mutex-init.c
new file mode 100644
index 0000000..af9ed7e
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutex-init.c
@@ -0,0 +1,55 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+static const pthread_mutexattr_t dfl_attr =
+{
+  .__prioceiling = 0,
+  .__protocol = PTHREAD_PRIO_NONE,
+  .__pshared = PTHREAD_PROCESS_PRIVATE,
+  .__mutex_type = __PTHREAD_MUTEX_TIMED
+};
+
+int _pthread_mutex_init (pthread_mutex_t *mtxp,
+  const pthread_mutexattr_t *attrp)
+{
+  if (attrp == NULL)
+    attrp = &dfl_attr;
+
+  mtxp->__flags = (attrp->__pshared == PTHREAD_PROCESS_SHARED ?
+    GSYNC_SHARED : 0) | ((attrp->__prioceiling & PTHREAD_MUTEX_ROBUST) ?
+      PTHREAD_MUTEX_ROBUST : 0);
+
+  mtxp->__type = attrp->__mutex_type +
+    (attrp->__mutex_type != __PTHREAD_MUTEX_TIMED);
+
+  mtxp->__owner_id = 0;
+  mtxp->__shpid = 0;
+  mtxp->__cnt = 0;
+  mtxp->__lock = 0;
+
+  return (0);
+}
+
+strong_alias (_pthread_mutex_init, pthread_mutex_init)
diff --git a/htl/sysdeps/mach/hurd/pt-mutex-lock.c b/htl/sysdeps/mach/hurd/pt-mutex-lock.c
new file mode 100644
index 0000000..5d3c958
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutex-lock.c
@@ -0,0 +1,79 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int __pthread_mutex_lock (pthread_mutex_t *mtxp)
+{
+  struct __pthread *self;
+  int flags = mtxp->__flags & GSYNC_SHARED;
+  int ret = 0;
+
+  switch (MTX_TYPE (mtxp))
+    {
+      case PT_MTX_NORMAL:
+        lll_lock (&mtxp->__lock, flags);
+        break;
+
+      case PT_MTX_RECURSIVE:
+        self = _pthread_self ();
+        if (mtx_owned_p (mtxp, self, flags))
+          {
+            if (__glibc_unlikely (mtxp->__cnt + 1 == 0))
+              return (EAGAIN);
+
+            ++mtxp->__cnt;
+            return (ret);
+          }
+
+        lll_lock (&mtxp->__lock, flags);
+        mtx_set_owner (mtxp, self, flags);
+        mtxp->__cnt = 1;
+        break;
+
+      case PT_MTX_ERRORCHECK:
+        self = _pthread_self ();
+        if (mtx_owned_p (mtxp, self, flags))
+          return (EDEADLK);
+
+        lll_lock (&mtxp->__lock, flags);
+        mtx_set_owner (mtxp, self, flags);
+        break;
+
+      case PT_MTX_NORMAL     | PTHREAD_MUTEX_ROBUST:
+      case PT_MTX_RECURSIVE  | PTHREAD_MUTEX_ROBUST:
+      case PT_MTX_ERRORCHECK | PTHREAD_MUTEX_ROBUST:
+        self = _pthread_self ();
+        ROBUST_LOCK (self, mtxp, __lll_robust_lock, flags);
+        break;
+
+      default:
+        ret = EINVAL;
+        break;
+    }
+
+  return (ret);
+}
+
+strong_alias (__pthread_mutex_lock, _pthread_mutex_lock)
+strong_alias (__pthread_mutex_lock, pthread_mutex_lock)
diff --git a/htl/sysdeps/mach/hurd/pt-mutex-setprioceiling.c b/htl/sysdeps/mach/hurd/pt-mutex-setprioceiling.c
new file mode 100644
index 0000000..b88917d
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutex-setprioceiling.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutex_setprioceiling (pthread_mutex_t *mtxp, int cl, int *prp)
+{
+  (void)mtxp; (void)cl; (void)prp;
+  return (ENOSYS);
+}
+
+stub_warning (pthread_mutex_setprioceiling)
diff --git a/htl/sysdeps/mach/hurd/pt-mutex-timedlock.c b/htl/sysdeps/mach/hurd/pt-mutex-timedlock.c
new file mode 100644
index 0000000..3fdd5da
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutex-timedlock.c
@@ -0,0 +1,80 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutex_timedlock (pthread_mutex_t *mtxp,
+  const struct timespec *tsp)
+{
+  struct __pthread *self;
+  int ret, flags = mtxp->__flags & GSYNC_SHARED;
+
+  switch (MTX_TYPE (mtxp))
+    {
+      case PT_MTX_NORMAL:
+        ret = lll_abstimed_lock (&mtxp->__lock, tsp, flags);
+        break;
+
+      case PT_MTX_RECURSIVE:
+        self = _pthread_self ();
+        if (mtx_owned_p (mtxp, self, flags))
+          {
+            if (__glibc_unlikely (mtxp->__cnt + 1 == 0))
+              return (EAGAIN);
+
+            ++mtxp->__cnt;
+            ret = 0;
+          }
+        else if ((ret = lll_abstimed_lock (&mtxp->__lock,
+            tsp, flags)) == 0)
+          {
+            mtx_set_owner (mtxp, self, flags);
+            mtxp->__cnt = 1;
+          }
+
+        break;
+
+      case PT_MTX_ERRORCHECK:
+        self = _pthread_self ();
+        if (mtx_owned_p (mtxp, self, flags))
+          ret = EDEADLK;
+        else if ((ret = lll_abstimed_lock (&mtxp->__lock,
+            tsp, flags)) == 0)
+          mtx_set_owner (mtxp, self, flags);
+
+        break;
+
+      case PT_MTX_NORMAL     | PTHREAD_MUTEX_ROBUST:
+      case PT_MTX_RECURSIVE  | PTHREAD_MUTEX_ROBUST:
+      case PT_MTX_ERRORCHECK | PTHREAD_MUTEX_ROBUST:
+        self = _pthread_self ();
+        ROBUST_LOCK (self, mtxp, lll_robust_abstimed_lock, tsp, flags);
+        break;
+
+      default:
+        ret = EINVAL;
+        break;
+    }
+
+  return (ret);
+}
diff --git a/htl/sysdeps/mach/hurd/pt-mutex-transfer-np.c b/htl/sysdeps/mach/hurd/pt-mutex-transfer-np.c
new file mode 100644
index 0000000..410474f
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutex-transfer-np.c
@@ -0,0 +1,74 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int __pthread_mutex_transfer_np (pthread_mutex_t *mtxp, pthread_t th)
+{
+  struct __pthread *self = _pthread_self ();
+  struct __pthread *pt = __pthread_getid (th);
+
+  if (!pt)
+    return (ESRCH);
+  else if (pt == self)
+    return (0);
+
+  int ret = 0;
+  int flags = mtxp->__flags & GSYNC_SHARED;
+
+  switch (MTX_TYPE (mtxp))
+    {
+      case PT_MTX_NORMAL:
+        break;
+
+      case PT_MTX_RECURSIVE:
+      case PT_MTX_ERRORCHECK:
+        if (!mtx_owned_p (mtxp, self, flags))
+          ret = EPERM;
+        else
+          mtx_set_owner (mtxp, pt, flags);
+
+        break;
+
+      case PT_MTX_NORMAL     | PTHREAD_MUTEX_ROBUST:
+      case PT_MTX_RECURSIVE  | PTHREAD_MUTEX_ROBUST:
+      case PT_MTX_ERRORCHECK | PTHREAD_MUTEX_ROBUST:
+        /* Note that this can be used to transfer an inconsistent
+         * mutex as well. The new owner will still have the same
+         * flags as the original. */
+        if (mtxp->__owner_id != self->thread ||
+            (int)(mtxp->__lock & LLL_OWNER_MASK) != __getpid ())
+          ret = EPERM;
+        else
+          mtxp->__owner_id = pt->thread;
+
+        break;
+
+      default:
+        ret = EINVAL;
+    }
+
+  return (ret);
+}
+
+weak_alias (__pthread_mutex_transfer_np, pthread_mutex_transfer_np)
diff --git a/htl/sysdeps/mach/hurd/pt-mutex-trylock.c b/htl/sysdeps/mach/hurd/pt-mutex-trylock.c
new file mode 100644
index 0000000..6680094
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutex-trylock.c
@@ -0,0 +1,77 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int __pthread_mutex_trylock (pthread_mutex_t *mtxp)
+{
+  struct __pthread *self;
+  int ret;
+
+  switch (MTX_TYPE (mtxp))
+    {
+      case PT_MTX_NORMAL:
+        ret = lll_trylock (&mtxp->__lock);
+        break;
+
+      case PT_MTX_RECURSIVE:
+        self = _pthread_self ();
+        if (mtx_owned_p (mtxp, self, mtxp->__flags))
+          {
+            if (__glibc_unlikely (mtxp->__cnt + 1 == 0))
+              return (EAGAIN);
+
+            ++mtxp->__cnt;
+            ret = 0;
+          }
+        else if ((ret = lll_trylock (&mtxp->__lock)) == 0)
+          {
+            mtx_set_owner (mtxp, self, mtxp->__flags);
+            mtxp->__cnt = 1;
+          }
+
+        break;
+
+      case PT_MTX_ERRORCHECK:
+        self = _pthread_self ();
+        if ((ret = lll_trylock (&mtxp->__lock)) == 0)
+          mtx_set_owner (mtxp, self, mtxp->__flags);
+        break;
+
+      case PT_MTX_NORMAL     | PTHREAD_MUTEX_ROBUST:
+      case PT_MTX_RECURSIVE  | PTHREAD_MUTEX_ROBUST:
+      case PT_MTX_ERRORCHECK | PTHREAD_MUTEX_ROBUST:
+        self = _pthread_self ();
+        ROBUST_LOCK (self, mtxp, __lll_robust_trylock);
+        break;
+
+      default:
+        ret = EINVAL;
+        break;
+    }
+
+  return (ret);
+}
+
+strong_alias (__pthread_mutex_trylock, _pthread_mutex_trylock)
+strong_alias (__pthread_mutex_trylock, pthread_mutex_trylock)
diff --git a/htl/sysdeps/mach/hurd/pt-mutex-unlock.c b/htl/sysdeps/mach/hurd/pt-mutex-unlock.c
new file mode 100644
index 0000000..071f622
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutex-unlock.c
@@ -0,0 +1,90 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int __pthread_mutex_unlock (pthread_mutex_t *mtxp)
+{
+  struct __pthread *self;
+  int ret = 0, flags = mtxp->__flags & GSYNC_SHARED;
+
+  switch (MTX_TYPE (mtxp))
+    {
+      case PT_MTX_NORMAL:
+        lll_unlock (&mtxp->__lock, flags);
+        break;
+
+      case PT_MTX_RECURSIVE:
+        self = _pthread_self ();
+        if (!mtx_owned_p (mtxp, self, flags))
+          ret = EPERM;
+        else if (--mtxp->__cnt == 0)
+          {
+            mtxp->__owner_id = mtxp->__shpid = 0;
+            lll_unlock (&mtxp->__lock, flags);
+          }
+
+        break;
+
+      case PT_MTX_ERRORCHECK:
+        self = _pthread_self ();
+        if (!mtx_owned_p (mtxp, self, flags))
+          ret = EPERM;
+        else
+          {
+            mtxp->__owner_id = mtxp->__shpid = 0;
+            lll_unlock (&mtxp->__lock, flags);
+          }
+
+        break;
+
+      case PT_MTX_NORMAL     | PTHREAD_MUTEX_ROBUST:
+      case PT_MTX_RECURSIVE  | PTHREAD_MUTEX_ROBUST:
+      case PT_MTX_ERRORCHECK | PTHREAD_MUTEX_ROBUST:
+        self = _pthread_self ();
+        if (mtxp->__owner_id == NOTRECOVERABLE_ID)
+          ;   /* Nothing to do. */
+        else if (mtxp->__owner_id != self->thread ||
+            (int)(mtxp->__lock & LLL_OWNER_MASK) != __getpid ())
+          ret = EPERM;
+        else if (--mtxp->__cnt == 0)
+          {
+            /* Release the lock. If it's in an inconsistent
+             * state, mark it as irrecoverable. */
+            mtxp->__owner_id = (mtxp->__lock & LLL_DEAD_OWNER) ?
+              NOTRECOVERABLE_ID : 0;
+            __lll_robust_unlock (&mtxp->__lock, flags);
+          }
+
+        break;
+
+      default:
+        ret = EINVAL;
+        break;
+    }
+
+  return (ret);
+}
+
+strong_alias (__pthread_mutex_unlock, _pthread_mutex_unlock)
+strong_alias (__pthread_mutex_unlock, pthread_mutex_unlock)
diff --git a/htl/sysdeps/mach/hurd/pt-mutex.h b/htl/sysdeps/mach/hurd/pt-mutex.h
new file mode 100644
index 0000000..c67453e
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutex.h
@@ -0,0 +1,92 @@
+/* Internal definitions for pthreads library.
+   Copyright (C) 2016 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   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.  */
+
+#ifndef _PT_MUTEX_H
+#define _PT_MUTEX_H	1
+
+/* Special ID used to signal an unrecoverable robust mutex. */
+#define NOTRECOVERABLE_ID   (1U << 31)
+
+/* Common path for robust mutexes. Assumes the variable 'ret'
+ * is bound in the function this is called from. */
+#define ROBUST_LOCK(self, mtxp, cb, ...)   \
+  if (mtxp->__owner_id == NOTRECOVERABLE_ID)   \
+    return (ENOTRECOVERABLE);   \
+  else if (mtxp->__owner_id == self->thread &&   \
+      __getpid () == (int)(mtxp->__lock & LLL_OWNER_MASK))   \
+    {   \
+      if (mtxp->__type == PT_MTX_RECURSIVE)   \
+        {   \
+          if (__glibc_unlikely (mtxp->__cnt + 1 == 0))   \
+            return (EAGAIN);   \
+          \
+          ++mtxp->__cnt;   \
+          return (0);   \
+        }   \
+      else if (mtxp->__type == PT_MTX_ERRORCHECK)   \
+        return (EDEADLK);   \
+    }   \
+  \
+  ret = cb (&mtxp->__lock, ##__VA_ARGS__);   \
+  if (ret == 0 || ret == EOWNERDEAD)   \
+    {   \
+      if (mtxp->__owner_id == ENOTRECOVERABLE)   \
+        ret = ENOTRECOVERABLE;   \
+      else   \
+        {   \
+          mtxp->__owner_id = self->thread;   \
+          mtxp->__cnt = 1;   \
+          if (ret == EOWNERDEAD)   \
+            {   \
+              mtxp->__lock = mtxp->__lock | LLL_DEAD_OWNER;   \
+              atomic_write_barrier ();   \
+            }   \
+        }   \
+    }   \
+  (void)0
+
+/* Check that a thread owns the mutex. For non-robust, task-shared
+ * objects, we have to check the thread *and* process-id. */
+#define mtx_owned_p(mtx, pt, flags)   \
+  ((mtx)->__owner_id == (pt)->thread &&   \
+    (((flags) & GSYNC_SHARED) == 0 ||   \
+      (mtx)->__shpid == __getpid ()))
+
+/* Record a thread as the owner of the mutex. */
+#define mtx_set_owner(mtx, pt, flags)   \
+  (void)   \
+    ({   \
+       (mtx)->__owner_id = (pt)->thread;   \
+       if ((flags) & GSYNC_SHARED)   \
+         (mtx)->__shpid = __getpid ();   \
+     })
+
+/* Redefined mutex types. The +1 is for binary compatibility. */
+#define PT_MTX_NORMAL       __PTHREAD_MUTEX_TIMED
+#define PT_MTX_RECURSIVE    (__PTHREAD_MUTEX_RECURSIVE + 1)
+#define PT_MTX_ERRORCHECK   (__PTHREAD_MUTEX_ERRORCHECK + 1)
+
+/* Mutex type, including robustness. */
+#define MTX_TYPE(mtxp)   \
+  ((mtxp)->__type | ((mtxp)->__flags & PTHREAD_MUTEX_ROBUST))
+
+extern int __getpid (void) __attribute__ ((const));
+
+#endif /* pt-mutex.h */
diff --git a/htl/sysdeps/mach/hurd/pt-mutexattr-destroy.c b/htl/sysdeps/mach/hurd/pt-mutexattr-destroy.c
new file mode 100644
index 0000000..ad711ac
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutexattr-destroy.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int __pthread_mutexattr_destroy (pthread_mutexattr_t *attrp)
+{
+  (void)attrp;
+  return (0);
+}
+weak_alias (__pthread_mutexattr_destroy, pthread_mutexattr_destroy)
diff --git a/htl/sysdeps/mach/hurd/pt-mutexattr-getprioceiling.c b/htl/sysdeps/mach/hurd/pt-mutexattr-getprioceiling.c
new file mode 100644
index 0000000..bcfc8c8
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutexattr-getprioceiling.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutexattr_getprioceiling (const pthread_mutexattr_t *ap, int *clp)
+{
+  (void)ap; (void)clp;
+  return (ENOSYS);
+}
+
+stub_warning (pthread_mutexattr_getprioceiling)
diff --git a/htl/sysdeps/mach/hurd/pt-mutexattr-getprotocol.c b/htl/sysdeps/mach/hurd/pt-mutexattr-getprotocol.c
new file mode 100644
index 0000000..cb94424
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutexattr-getprotocol.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutexattr_getprotocol (const pthread_mutexattr_t *attrp, int *ptp)
+{
+  *ptp = attrp->__protocol;
+  return (0);
+}
diff --git a/htl/sysdeps/mach/hurd/pt-mutexattr-getpshared.c b/htl/sysdeps/mach/hurd/pt-mutexattr-getpshared.c
new file mode 100644
index 0000000..7639528
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutexattr-getpshared.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutexattr_getpshared (const pthread_mutexattr_t *attrp, int *outp)
+{
+  *outp = attrp->__pshared;
+  return (0);
+}
diff --git a/htl/sysdeps/mach/hurd/pt-mutexattr-getrobust.c b/htl/sysdeps/mach/hurd/pt-mutexattr-getrobust.c
new file mode 100644
index 0000000..86a0909
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutexattr-getrobust.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutexattr_getrobust (const pthread_mutexattr_t *attrp, int *outp)
+{
+  *outp = (attrp->__prioceiling & PTHREAD_MUTEX_ROBUST) ?
+    PTHREAD_MUTEX_ROBUST : PTHREAD_MUTEX_STALLED;
+  return (0);
+}
+
+weak_alias (pthread_mutexattr_getrobust, pthread_mutexattr_getrobust_np)
diff --git a/htl/sysdeps/mach/hurd/pt-mutexattr-gettype.c b/htl/sysdeps/mach/hurd/pt-mutexattr-gettype.c
new file mode 100644
index 0000000..746f628
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutexattr-gettype.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutexattr_gettype (const pthread_mutexattr_t *attrp, int *outp)
+{
+  *outp = attrp->__mutex_type;
+  return (0);
+}
+
diff --git a/htl/sysdeps/mach/hurd/pt-mutexattr-init.c b/htl/sysdeps/mach/hurd/pt-mutexattr-init.c
new file mode 100644
index 0000000..4cac661
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutexattr-init.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+static const pthread_mutexattr_t dfl_attr =
+{
+  .__prioceiling = 0,
+  .__protocol = PTHREAD_PRIO_NONE,
+  .__pshared = PTHREAD_PROCESS_PRIVATE,
+  .__mutex_type = __PTHREAD_MUTEX_TIMED
+};
+
+int __pthread_mutexattr_init (pthread_mutexattr_t *attrp)
+{
+  *attrp = dfl_attr;
+  return (0);
+}
+weak_alias (__pthread_mutexattr_init, pthread_mutexattr_init)
diff --git a/htl/sysdeps/mach/hurd/pt-mutexattr-setprioceiling.c b/htl/sysdeps/mach/hurd/pt-mutexattr-setprioceiling.c
new file mode 100644
index 0000000..d399050
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutexattr-setprioceiling.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutexattr_setprioceiling (pthread_mutexattr_t *attrp, int cl)
+{
+  (void)attrp; (void)cl;
+  return (ENOSYS);
+}
+
+stub_warning (pthread_mutexattr_setprioceiling)
diff --git a/htl/sysdeps/mach/hurd/pt-mutexattr-setprotocol.c b/htl/sysdeps/mach/hurd/pt-mutexattr-setprotocol.c
new file mode 100644
index 0000000..9f7f152
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutexattr-setprotocol.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutexattr_setprotocol (pthread_mutexattr_t *attrp, int proto)
+{
+  (void)attrp;
+  return (proto == PTHREAD_PRIO_NONE ? 0 :
+    proto != PTHREAD_PRIO_INHERIT &&
+    proto != PTHREAD_PRIO_PROTECT ? EINVAL : ENOTSUP);
+}
diff --git a/htl/sysdeps/mach/hurd/pt-mutexattr-setpshared.c b/htl/sysdeps/mach/hurd/pt-mutexattr-setpshared.c
new file mode 100644
index 0000000..c10dfa0
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutexattr-setpshared.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutexattr_setpshared (pthread_mutexattr_t *attrp, int pshared)
+{
+  if (pshared != PTHREAD_PROCESS_PRIVATE &&
+      pshared != PTHREAD_PROCESS_SHARED)
+    return (EINVAL);
+
+  attrp->__pshared = pshared;
+  return (0);
+}
diff --git a/htl/sysdeps/mach/hurd/pt-mutexattr-setrobust.c b/htl/sysdeps/mach/hurd/pt-mutexattr-setrobust.c
new file mode 100644
index 0000000..a90e747
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutexattr-setrobust.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int pthread_mutexattr_setrobust (pthread_mutexattr_t *attrp, int robust)
+{
+  if (robust != PTHREAD_MUTEX_ROBUST &&
+      robust != PTHREAD_MUTEX_STALLED)
+    return (EINVAL);
+
+  attrp->__prioceiling |= robust;
+  return (0);
+}
+
+weak_alias (pthread_mutexattr_setrobust, pthread_mutexattr_setrobust_np)
diff --git a/htl/sysdeps/mach/hurd/pt-mutexattr-settype.c b/htl/sysdeps/mach/hurd/pt-mutexattr-settype.c
new file mode 100644
index 0000000..67ed4f5
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutexattr-settype.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+   Contributed by Agustina Arzille <avarzille@riseup.net>, 2016.
+
+   This program 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.
+
+   This program is distributed in the hope that 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 this program; if not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <pt-internal.h>
+#include "pt-mutex.h"
+#include <hurdlock.h>
+
+int __pthread_mutexattr_settype (pthread_mutexattr_t *attrp, int type)
+{
+  if (type < 0 || type > __PTHREAD_MUTEX_RECURSIVE)
+    return (EINVAL);
+
+  attrp->__mutex_type = type;
+  return (0);
+}
+weak_alias (__pthread_mutexattr_settype, pthread_mutexattr_settype)
diff --git a/htl/sysdeps/mach/hurd/pt-mutexattr.c b/htl/sysdeps/mach/hurd/pt-mutexattr.c
new file mode 100644
index 0000000..40a8c17
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-mutexattr.c
@@ -0,0 +1 @@
+/* empty */
diff --git a/htl/sysdeps/mach/hurd/pt-sigstate-destroy.c b/htl/sysdeps/mach/hurd/pt-sigstate-destroy.c
new file mode 100644
index 0000000..d5e28d2
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-sigstate-destroy.c
@@ -0,0 +1,28 @@
+/* Destroy the signal state.  Hurd on Mach 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.  */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+void
+__pthread_sigstate_destroy (struct __pthread *thread)
+{
+  _hurd_sigstate_delete (thread->kernel_thread);
+}
diff --git a/htl/sysdeps/mach/hurd/pt-sigstate-init.c b/htl/sysdeps/mach/hurd/pt-sigstate-init.c
new file mode 100644
index 0000000..500b4d4
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-sigstate-init.c
@@ -0,0 +1,44 @@
+/* Initialize the signal state.  Hurd on Mach 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.  */
+
+#include <pthread.h>
+#include <pt-internal.h>
+
+error_t
+__pthread_sigstate_init (struct __pthread *thread)
+{
+  static int do_init_global;
+
+  /* Mark the thread as a global signal receiver so as to conform with
+     the pthread semantics.  However, we must be careful.  The first
+     pthread created is the main thread, during libpthread initialization.
+     We must not mark it, otherwise the sigprocmask call in
+     __pthread_create would try to access _hurd_global_sigstate,
+     which is not initialized yet.  When glibc runs _hurdsig_init later
+     on, the message thread is created, which must not be marked either.  */
+  if (do_init_global)
+    {
+      struct hurd_sigstate *ss = _hurd_thread_sigstate (thread->kernel_thread);
+      _hurd_sigstate_set_global_rcv (ss);
+    }
+  else if (__pthread_num_threads >= 2)
+    do_init_global = 1;
+
+  return 0;
+}
diff --git a/htl/sysdeps/mach/hurd/pt-sigstate.c b/htl/sysdeps/mach/hurd/pt-sigstate.c
new file mode 100644
index 0000000..74fd72a
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-sigstate.c
@@ -0,0 +1,80 @@
+/* Set a thread's signal state.  Hurd on Mach 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.  */
+
+#include <pthread.h>
+#include <assert.h>
+#include <signal.h>
+#include <hurd/signal.h>
+#include <hurd/msg.h>
+
+#include <pt-internal.h>
+
+error_t
+__pthread_sigstate (struct __pthread *thread, int how,
+		    const sigset_t *set, sigset_t *oset,
+		    int clear_pending)
+{
+  error_t err = 0;
+  struct hurd_sigstate *ss;
+  sigset_t pending;
+
+  ss = _hurd_thread_sigstate (thread->kernel_thread);
+  assert (ss);
+
+  _hurd_sigstate_lock (ss);
+
+  if (oset)
+    *oset = ss->blocked;
+
+  if (set)
+    {
+      switch (how)
+	{
+	case SIG_BLOCK:
+	  ss->blocked |= *set;
+	  break;
+
+	case SIG_SETMASK:
+	  ss->blocked = *set;
+	  break;
+
+	case SIG_UNBLOCK:
+	  ss->blocked &= ~*set;
+	  break;
+
+	default:
+	  err = EINVAL;
+	  break;
+	}
+      ss->blocked &= ~_SIG_CANT_MASK;
+    }
+
+  if (! err && clear_pending)
+    __sigemptyset (&ss->pending);
+
+  pending = _hurd_sigstate_pending (ss) & ~ss->blocked;
+  _hurd_sigstate_unlock (ss);
+
+  if (! err && pending)
+    /* Send a message to the signal thread so it
+       will wake up and check for pending signals.  */
+    __msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ());
+
+  return err;
+}
diff --git a/htl/sysdeps/mach/hurd/pt-sysdep.c b/htl/sysdeps/mach/hurd/pt-sysdep.c
new file mode 100644
index 0000000..939194b
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-sysdep.c
@@ -0,0 +1,98 @@
+/* System dependent pthreads code.  Hurd version.
+   Copyright (C) 2000, 2002, 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 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 <assert.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include <mach.h>
+#include <mach/mig_support.h>
+
+#include <pt-internal.h>
+
+__thread struct __pthread *___pthread_self;
+
+/* Forward.  */
+static void *init_routine (void);
+
+/* OK, the name of this variable isn't really appropriate, but I don't
+   want to change it yet.  */
+void *(*_cthread_init_routine)(void) = &init_routine;
+
+/* This function is called from the Hurd-specific startup code.  It
+   should return a new stack pointer for the main thread.  The caller
+   will switch to this new stack before doing anything serious.  */
+static void *
+_init_routine (void *stack)
+{
+  struct __pthread *thread;
+  int err;
+  pthread_attr_t attr, *attrp = 0;
+
+  if (__pthread_threads)
+    /* Already initialized */
+    return 0;
+
+  /* Initialize the library.  */
+  ___pthread_init ();
+
+  if (stack)
+    {
+      /* We are getting initialized due to dlopening a library using libpthread
+	 while the main program was not linked against libpthread.  */
+      /* Avoid allocating another stack */
+      attrp = &attr;
+      pthread_attr_init(attrp);
+      pthread_attr_setstack(attrp, stack, __vm_page_size);
+    }
+
+  /* Create the pthread structure for the main thread (i.e. us).  */
+  err = __pthread_create_internal (&thread, attrp, 0, 0);
+  assert_perror (err);
+
+  /* XXX The caller copies the command line arguments and the environment
+     to the new stack.  Pretend it wasn't allocated so that it remains
+     valid if the main thread terminates.  */
+  thread->stack = 0;
+
+  ___pthread_self = thread;
+
+  /* Decrease the number of threads, to take into account that the
+     signal thread (which will be created by the glibc startup code
+     when we return from here) shouldn't be seen as a user thread.  */
+  __pthread_total--;
+
+  /* Make MiG code thread aware.  */
+  __mig_init (thread->stackaddr);
+
+  return thread->mcontext.sp;
+}
+
+static void *
+init_routine (void)
+{
+  return _init_routine (0);
+}
+
+#ifdef SHARED
+__attribute__ ((constructor)) static void dynamic_init_routine(void)
+{
+  _init_routine (__libc_stack_end);
+}
+#endif
diff --git a/htl/sysdeps/mach/hurd/pt-sysdep.h b/htl/sysdeps/mach/hurd/pt-sysdep.h
new file mode 100644
index 0000000..35912a3
--- /dev/null
+++ b/htl/sysdeps/mach/hurd/pt-sysdep.h
@@ -0,0 +1,67 @@
+/* Internal defenitions for pthreads library.
+   Copyright (C) 2000, 2002, 2007, 2008 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.  */
+
+#ifndef _PT_SYSDEP_H
+#define _PT_SYSDEP_H	1
+
+#include <mach.h>
+
+/* XXX */
+#define _POSIX_THREAD_THREADS_MAX	64
+
+/* The default stack size.  */
+#define PTHREAD_STACK_DEFAULT	(2 * 1024 * 1024)
+
+#define PTHREAD_SYSDEP_MEMBERS \
+  thread_t kernel_thread;      \
+  mach_msg_header_t wakeupmsg;
+
+extern __thread struct __pthread *___pthread_self;
+#define _pthread_self()                                            \
+	({                                                         \
+	  struct __pthread *thread;                                \
+	                                                           \
+	  assert (__pthread_threads);                              \
+	  thread = ___pthread_self;                                \
+	                                                           \
+	  assert (thread);                                         \
+	  assert (({ mach_port_t ktid = __mach_thread_self ();     \
+                     int ok = thread->kernel_thread == ktid;       \
+                     __mach_port_deallocate (__mach_task_self (), ktid);\
+                     ok; }));                                      \
+          thread;                                                  \
+         })
+
+extern inline void
+__attribute__((__always_inline__))
+__pthread_stack_dealloc (void *stackaddr, size_t stacksize)
+{
+  __vm_deallocate (__mach_task_self (), (vm_offset_t) stackaddr, stacksize);
+}
+
+/* Change thread THREAD's program counter to PC if SET_PC is true,
+   its stack pointer to SP if SET_IP is true, and its thread pointer
+   to TP if SET_TP is true.  */
+extern int __thread_set_pcsptp (thread_t thread,
+			      int set_pc, void *pc,
+			      int set_sp, void *sp,
+			      int set_tp, void *tp);
+
+
+#endif /* pt-sysdep.h */
diff --git a/htl/sysdeps/mach/pt-block.c b/htl/sysdeps/mach/pt-block.c
new file mode 100644
index 0000000..a947b27
--- /dev/null
+++ b/htl/sysdeps/mach/pt-block.c
@@ -0,0 +1,39 @@
+/* Block a thread.  Mach version.
+   Copyright (C) 2000 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 <assert.h>
+#include <errno.h>
+
+#include <mach.h>
+#include <mach/message.h>
+
+#include <pt-internal.h>
+
+/* Block THREAD.  */
+void
+__pthread_block (struct __pthread *thread)
+{
+  mach_msg_header_t msg;
+  error_t err;
+
+  err = __mach_msg (&msg, MACH_RCV_MSG, 0, sizeof msg,
+		    thread->wakeupmsg.msgh_remote_port,
+		    MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
+  assert_perror (err);
+}
diff --git a/htl/sysdeps/mach/pt-spin.c b/htl/sysdeps/mach/pt-spin.c
new file mode 100644
index 0000000..0cf1c49
--- /dev/null
+++ b/htl/sysdeps/mach/pt-spin.c
@@ -0,0 +1,32 @@
+/* Spin locks.  Mach version.
+   Copyright (C) 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 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 <machine-lock.h>
+
+/* In glibc.  */
+extern void __spin_lock_solid (__spin_lock_t *lock);
+
+/* Lock the spin lock object LOCK.  If the lock is held by another
+   thread spin until it becomes available.  */
+int
+_pthread_spin_lock (__spin_lock_t *lock)
+{
+  __spin_lock_solid (lock);
+  return 0;
+}
diff --git a/htl/sysdeps/mach/pt-stack-alloc.c b/htl/sysdeps/mach/pt-stack-alloc.c
new file mode 100644
index 0000000..121c189
--- /dev/null
+++ b/htl/sysdeps/mach/pt-stack-alloc.c
@@ -0,0 +1,69 @@
+/* Allocate a new stack.  Mach version.
+   Copyright (C) 2000,02 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 <mach.h>
+#include <mach/machine/vm_param.h>
+
+#include <pt-internal.h>
+
+/* The next address to use for stack allocation.  */
+static vm_address_t next_stack_base = VM_MIN_ADDRESS;
+
+
+/* Allocate a new stack of size STACKSIZE.  If successful, store the
+   address of the newly allocated stack in *STACKADDR and return 0.
+   Otherwise return an error code (EINVAL for an invalid stack size,
+   EAGAIN if the system lacked the necessary resources to allocate a
+   new stack).  */
+int
+__pthread_stack_alloc (void **stackaddr, size_t stacksize)
+{
+  vm_offset_t base;
+  int i = 0;
+
+ get_stack:
+  i ++;
+  for (base = next_stack_base;
+       base < VM_MAX_ADDRESS
+	 && __vm_allocate (__mach_task_self (), &base,
+			   stacksize, FALSE) != KERN_SUCCESS;
+       base += stacksize)
+    ;
+
+  if (base >= VM_MAX_ADDRESS)
+    {
+      if (i == 1)
+	{
+	  next_stack_base = VM_MIN_ADDRESS;
+	  goto get_stack;
+	}
+      else
+	return EAGAIN;
+    }
+
+  if (base >= VM_MAX_ADDRESS)
+    return EAGAIN;
+
+  next_stack_base = base + stacksize;
+
+  (*stackaddr) = (void *) base;
+  return 0;
+}
diff --git a/htl/sysdeps/mach/pt-thread-alloc.c b/htl/sysdeps/mach/pt-thread-alloc.c
new file mode 100644
index 0000000..76e5660
--- /dev/null
+++ b/htl/sysdeps/mach/pt-thread-alloc.c
@@ -0,0 +1,95 @@
+/* Start thread.  Mach version.
+   Copyright (C) 2000, 2002, 2005, 2008 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 <assert.h>
+#include <errno.h>
+#include <string.h>
+
+#include <mach.h>
+
+#include <pt-internal.h>
+
+/* Prepare a wakeup message.  */
+static error_t
+create_wakeupmsg (struct __pthread *thread)
+{
+  kern_return_t err;
+
+  /* Build wakeup message.  */
+  thread->wakeupmsg.msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, 0);
+  thread->wakeupmsg.msgh_size = 0;
+
+  err = __mach_port_allocate (__mach_task_self (), MACH_PORT_RIGHT_RECEIVE,
+			      &thread->wakeupmsg.msgh_remote_port);
+  if (err)
+    return EAGAIN;
+
+  thread->wakeupmsg.msgh_local_port = MACH_PORT_NULL;
+  thread->wakeupmsg.msgh_seqno = 0;
+  thread->wakeupmsg.msgh_id = 0;
+
+  err = __mach_port_insert_right (__mach_task_self (),
+				  thread->wakeupmsg.msgh_remote_port,
+				  thread->wakeupmsg.msgh_remote_port,
+				  MACH_MSG_TYPE_MAKE_SEND);
+  if (err)
+    {
+      __mach_port_destroy (__mach_task_self (),
+			   thread->wakeupmsg.msgh_remote_port);
+      return EAGAIN;
+    }
+
+  /* No need to queue more than one wakeup message on this port.  */
+  __mach_port_set_qlimit (__mach_task_self (),
+			  thread->wakeupmsg.msgh_remote_port, 1);
+
+  return 0;
+}
+
+/* Allocate any resouces for THREAD.  The new kernel thread should not
+   be eligible to be scheduled.  */
+int
+__pthread_thread_alloc (struct __pthread *thread)
+{
+  static int do_create;
+  error_t err;
+
+  err = create_wakeupmsg (thread);
+  if (err)
+    return err;
+
+  if (! do_create)
+    {
+      assert (__pthread_total == 0);
+      thread->kernel_thread = __mach_thread_self ();
+      do_create = 1;
+    }
+  else
+    {
+      err = __thread_create (__mach_task_self (), &thread->kernel_thread);
+      if (err)
+	{
+	  __mach_port_destroy (__mach_task_self (),
+			       thread->wakeupmsg.msgh_remote_port);
+	  return EAGAIN;
+	}
+    }
+
+  return 0;
+}
diff --git a/htl/sysdeps/mach/pt-thread-start.c b/htl/sysdeps/mach/pt-thread-start.c
new file mode 100644
index 0000000..df490ab
--- /dev/null
+++ b/htl/sysdeps/mach/pt-thread-start.c
@@ -0,0 +1,51 @@
+/* Start thread.  Mach version.
+   Copyright (C) 2000,02 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 <assert.h>
+#include <errno.h>
+#include <mach.h>
+
+#include <pt-internal.h>
+
+/* Start THREAD.  Get the kernel thread scheduled and running.  */
+int
+__pthread_thread_start (struct __pthread *thread)
+{
+  static int do_start;
+  error_t err;
+
+  if (! do_start)
+    {
+      /* The main thread is already running: do nothing.  */
+      assert (__pthread_total == 1);
+      assert (({ mach_port_t ktid = __mach_thread_self ();
+                 int ok = thread->kernel_thread == ktid;
+                 __mach_port_deallocate (__mach_task_self (),
+					 thread->kernel_thread);
+		 ok; }));
+      do_start = 1;
+    }
+  else
+    {
+      err = __thread_resume (thread->kernel_thread);
+      assert_perror (err);
+    }
+
+  return 0;
+}
diff --git a/htl/sysdeps/mach/pt-thread-terminate.c b/htl/sysdeps/mach/pt-thread-terminate.c
new file mode 100644
index 0000000..5d9da26
--- /dev/null
+++ b/htl/sysdeps/mach/pt-thread-terminate.c
@@ -0,0 +1,85 @@
+/* Deallocate the kernel thread resources.  Mach version.
+   Copyright (C) 2000, 2002, 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 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 <assert.h>
+#include <errno.h>
+#include <mach.h>
+
+#include <mach/mig_support.h>
+
+#include <pt-internal.h>
+
+/* Terminate the kernel thread associated with THREAD, and deallocate its
+   right reference and its stack.  The function also drops a reference
+   on THREAD.  */
+void
+__pthread_thread_terminate (struct __pthread *thread)
+{
+  thread_t kernel_thread, self_ktid;
+  mach_port_t wakeup_port, reply_port;
+  void *stackaddr;
+  size_t stacksize;
+  error_t err;
+
+  kernel_thread = thread->kernel_thread;
+
+  if (thread->stack)
+    {
+      stackaddr = thread->stackaddr;
+      stacksize = ((thread->guardsize + __vm_page_size-1)
+		  / __vm_page_size) * __vm_page_size
+		  + thread->stacksize;
+    }
+  else
+    {
+      stackaddr = NULL;
+      stacksize = 0;
+    }
+
+  wakeup_port = thread->wakeupmsg.msgh_remote_port;
+
+  /* Each thread has its own reply port, allocated from MiG stub code calling
+     __mig_get_reply_port.  Destroying it is a bit tricky because the calls
+     involved are also RPCs, causing the creation of a new reply port if
+     currently null. The __thread_terminate_release call is actually a one way
+     simple routine designed not to require a reply port.  */
+  self_ktid = __mach_thread_self ();
+  reply_port = (self_ktid == kernel_thread)
+	       ? __mig_get_reply_port ()
+	       : MACH_PORT_NULL;
+  __mach_port_deallocate (__mach_task_self (), self_ktid);
+
+  /* Finally done with the thread structure.  */
+  __pthread_dealloc (thread);
+
+  /* The wake up port is now no longer needed.  */
+  __mach_port_destroy (__mach_task_self (), wakeup_port);
+
+  /* Terminate and release all that's left.  */
+  err = __thread_terminate_release (kernel_thread, mach_task_self (),
+				    kernel_thread, reply_port,
+				    (vm_address_t) stackaddr, stacksize);
+
+  /* The kernel does not support it yet.  Leak but at least terminate
+     correctly.  */
+  err = __thread_terminate (kernel_thread);
+
+  /* We are out of luck.  */
+  assert_perror (err);
+}
diff --git a/htl/sysdeps/mach/pt-timedblock.c b/htl/sysdeps/mach/pt-timedblock.c
new file mode 100644
index 0000000..d72ef73
--- /dev/null
+++ b/htl/sysdeps/mach/pt-timedblock.c
@@ -0,0 +1,68 @@
+/* Block a thread with a timeout.  Mach version.
+   Copyright (C) 2000, 2002, 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 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 <assert.h>
+#include <errno.h>
+#include <time.h>
+#include <sys/time.h>
+
+#include <mach.h>
+#include <mach/message.h>
+
+#include <pt-internal.h>
+
+/* Block THREAD.  */
+error_t
+__pthread_timedblock (struct __pthread *thread,
+		      const struct timespec *abstime,
+		      clockid_t clock_id)
+{
+  error_t err;
+  mach_msg_header_t msg;
+  mach_msg_timeout_t timeout;
+  struct timespec now;
+
+  /* We have an absolute time and now we have to convert it to a
+     relative time.  Arg.  */
+
+  err = clock_gettime (clock_id, &now);
+  assert (! err);
+
+  if (now.tv_sec > abstime->tv_sec
+      || (now.tv_sec == abstime->tv_sec
+	  && now.tv_nsec > abstime->tv_nsec))
+    return ETIMEDOUT;
+
+  timeout = (abstime->tv_sec - now.tv_sec) * 1000;
+
+  if (abstime->tv_nsec >= now.tv_nsec)
+    timeout += (abstime->tv_nsec - now.tv_nsec + 999999) / 1000000;
+  else
+    /* Need to do a carry.  */
+    timeout -= (now.tv_nsec - abstime->tv_nsec + 999999) / 1000000;
+
+  err = __mach_msg (&msg, MACH_RCV_MSG | MACH_RCV_TIMEOUT, 0,
+		    sizeof msg, thread->wakeupmsg.msgh_remote_port,
+		    timeout, MACH_PORT_NULL);
+  if (err == EMACH_RCV_TIMED_OUT)
+    return ETIMEDOUT;
+
+  assert_perror (err);
+  return 0;
+}
diff --git a/htl/sysdeps/mach/pt-wakeup.c b/htl/sysdeps/mach/pt-wakeup.c
new file mode 100644
index 0000000..95fdbf9
--- /dev/null
+++ b/htl/sysdeps/mach/pt-wakeup.c
@@ -0,0 +1,38 @@
+/* Wakeup a thread.  Mach version.
+   Copyright (C) 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 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 <assert.h>
+#include <errno.h>
+
+#include <mach.h>
+#include <mach/message.h>
+
+#include <pt-internal.h>
+
+/* Wakeup THREAD.  */
+void
+__pthread_wakeup (struct __pthread *thread)
+{
+  error_t err;
+  
+  err = __mach_msg (&thread->wakeupmsg, MACH_SEND_MSG | MACH_SEND_TIMEOUT,
+		    sizeof (thread->wakeupmsg), 0, MACH_PORT_NULL,
+		    0 , MACH_PORT_NULL);
+  assert_perror (err);
+}
diff --git a/htl/sysdeps/posix/pt-spin.c b/htl/sysdeps/posix/pt-spin.c
new file mode 100644
index 0000000..07f8936
--- /dev/null
+++ b/htl/sysdeps/posix/pt-spin.c
@@ -0,0 +1,51 @@
+/* Spin locks.
+   Copyright (C) 2000, 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 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 <pthread.h>
+#include <sched.h>
+
+/* The default for single processor machines; don't spin, it's
+   pointless.  */
+#ifndef __PTHREAD_SPIN_COUNT
+# define __PTHREAD_SPIN_COUNT 1
+#endif
+
+/* The number of times to spin while trying to lock a spin lock object
+   before yielding the processor. */
+int __pthread_spin_count = __PTHREAD_SPIN_COUNT;
+
+
+/* Lock the spin lock object LOCK.  If the lock is held by another
+   thread spin until it becomes available.  */
+int
+_pthread_spin_lock (__pthread_spinlock_t *lock)
+{
+  int i;
+
+  while (1)
+    {
+      for (i = 0; i < __pthread_spin_count; i++)
+	{
+	  if (__pthread_spin_trylock (lock) == 0)
+	    return 0;
+	}
+
+      __sched_yield ();
+    }
+}
diff --git a/htl/sysdeps/pthread/Makefile b/htl/sysdeps/pthread/Makefile
new file mode 100644
index 0000000..f5dbd25
--- /dev/null
+++ b/htl/sysdeps/pthread/Makefile
@@ -0,0 +1,7 @@
+ifeq ($(subdir),rt)
+librt-sysdep_routines += timer_routines
+endif
+ifeq ($(subdir),posix)
+  # FIXME: this is not getting $(pthread-version) from libpthread/Makefile!
+CFLAGS-confstr.c += -DLIBPTHREAD_VERSION='"libpthread $(pthread-version)"'
+endif
diff --git a/htl/sysdeps/pthread/Versions b/htl/sysdeps/pthread/Versions
new file mode 100644
index 0000000..3a3b1e8
--- /dev/null
+++ b/htl/sysdeps/pthread/Versions
@@ -0,0 +1,15 @@
+libc {
+  GLIBC_2.2 {
+    # XXX
+    __vm_deallocate; __mach_port_insert_right; __mach_reply_port;
+    __mig_init; __vm_allocate; __mach_port_allocate;
+
+    # functions used in inline functions or macros
+    __pthread_spin_destroy; __pthread_spin_init; __pthread_spin_lock;
+    _pthread_spin_lock; __pthread_spin_trylock; __pthread_spin_unlock;
+
+    # p*
+    pthread_spin_destroy; pthread_spin_init; pthread_spin_lock;
+    pthread_spin_trylock; pthread_spin_unlock;
+  }
+}
diff --git a/htl/sysdeps/pthread/bits/barrier-attr.h b/htl/sysdeps/pthread/bits/barrier-attr.h
new file mode 100644
index 0000000..7734069
--- /dev/null
+++ b/htl/sysdeps/pthread/bits/barrier-attr.h
@@ -0,0 +1,32 @@
+/* Thread barrier attribute type.  Generic version.
+   Copyright (C) 2002, 2008 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.  */
+
+#ifndef _BITS_BARRIER_ATTR_H
+#define _BITS_BARRIER_ATTR_H	1
+
+enum __pthread_process_shared;
+
+/* This structure describes the attributes of a POSIX thread barrier.
+   Note that not all of them are supported on all systems.  */
+struct __pthread_barrierattr
+{
+  enum __pthread_process_shared __pshared;
+};
+
+#endif /* bits/barrier-attr.h */
diff --git a/htl/sysdeps/pthread/bits/barrier.h b/htl/sysdeps/pthread/bits/barrier.h
new file mode 100644
index 0000000..dabe86f
--- /dev/null
+++ b/htl/sysdeps/pthread/bits/barrier.h
@@ -0,0 +1,39 @@
+/* Thread barrier attribute type.  Generic 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.  */
+
+#ifndef _BITS_BARRIER_H
+#define _BITS_BARRIER_H	1
+
+#include <bits/spin-lock.h>
+
+/* This structure describes the attributes of a POSIX barrier.  */
+struct __pthread_barrier
+{
+  __pthread_spinlock_t __lock;
+  struct __pthread *__queue; /* List of waiters.  */
+  unsigned __pending;	/* Number of that still need to wait on
+			   barrier.  */
+  unsigned __count;	/* Number of threads that must wait before
+			   barrier is passed.  */
+  struct __pthread_barrierattr *__attr;
+  void *__data;
+};
+
+
+#endif /* bits/barrier.h */
diff --git a/htl/sysdeps/pthread/bits/cancelation.h b/htl/sysdeps/pthread/bits/cancelation.h
new file mode 100644
index 0000000..1ed16c6
--- /dev/null
+++ b/htl/sysdeps/pthread/bits/cancelation.h
@@ -0,0 +1,51 @@
+/* Cancelation.  Generic version.
+   Copyright (C) 2002, 2008 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.  */
+
+#ifndef _BITS_CANCELATION_H
+#define _BITS_CANCELATION_H	1
+
+struct __pthread_cancelation_handler
+{
+  void (*__handler)(void *);
+  void *__arg;
+  struct __pthread_cancelation_handler *__next;
+};
+
+/* Returns the thread local location of the cleanup handler stack.  */
+struct __pthread_cancelation_handler **__pthread_get_cleanup_stack (void);
+
+#define __pthread_cleanup_push(rt, rtarg) \
+	{ \
+	  struct __pthread_cancelation_handler **__handlers \
+	    = __pthread_get_cleanup_stack (); \
+	  struct __pthread_cancelation_handler __handler = \
+	    { \
+	      (rt), \
+	      (rtarg), \
+	      *__handlers \
+	    }; \
+	  *__handlers = &__handler;
+	  
+#define __pthread_cleanup_pop(execute) \
+	  if (execute) \
+	    __handler.__handler (__handler.__arg); \
+	  *__handlers = __handler.__next; \
+	}
+
+#endif /* _BITS_CANCELATION_H */
diff --git a/htl/sysdeps/pthread/bits/condition-attr.h b/htl/sysdeps/pthread/bits/condition-attr.h
new file mode 100644
index 0000000..19c92bb
--- /dev/null
+++ b/htl/sysdeps/pthread/bits/condition-attr.h
@@ -0,0 +1,34 @@
+/* Condition attribute type.  Generic version.
+   Copyright (C) 2002, 2008 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.  */
+
+#ifndef _BITS_CONDITION_ATTR_H
+#define _BITS_CONDITION_ATTR_H	1
+
+#include <bits/types.h>
+
+enum __pthread_process_shared;
+
+/* User visible part of a condition attribute variable.  */
+struct __pthread_condattr
+  {
+    enum __pthread_process_shared __pshared;
+    __clockid_t __clock;
+  };
+
+#endif /* bits/condition.h */
diff --git a/htl/sysdeps/pthread/bits/condition.h b/htl/sysdeps/pthread/bits/condition.h
new file mode 100644
index 0000000..bf13ada
--- /dev/null
+++ b/htl/sysdeps/pthread/bits/condition.h
@@ -0,0 +1,39 @@
+/* Condition type.  Generic version.
+   Copyright (C) 2000, 2005, 2009 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.  */
+
+#ifndef _BITS_CONDITION_H
+#define _BITS_CONDITION_H	1
+
+#include <bits/spin-lock.h>
+
+/* User visible part of a condition variable.  */
+struct __pthread_cond
+  {
+    __pthread_spinlock_t __lock;
+    struct __pthread *__queue;
+    struct __pthread_condattr *__attr;
+    struct __pthread_condimpl *__impl;
+    void *__data;
+  };
+
+/* Initializer for a condition variable.  */
+#define __PTHREAD_COND_INITIALIZER \
+  { __PTHREAD_SPIN_LOCK_INITIALIZER, NULL, NULL, NULL, NULL }
+
+#endif /* bits/condition.h */
diff --git a/htl/sysdeps/pthread/bits/mutex-attr.h b/htl/sysdeps/pthread/bits/mutex-attr.h
new file mode 100644
index 0000000..f3d0752
--- /dev/null
+++ b/htl/sysdeps/pthread/bits/mutex-attr.h
@@ -0,0 +1,41 @@
+/* Mutex attribute type.  Generic version.
+   Copyright (C) 2002, 2008 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.  */
+
+#ifndef _BITS_MUTEX_ATTR_H
+#define _BITS_MUTEX_ATTR_H	1
+
+enum __pthread_mutex_protocol;
+enum __pthread_process_shared;
+enum __pthread_mutex_type;
+
+/* This structure describes the attributes of a POSIX mutex
+   attribute.  */
+struct __pthread_mutexattr
+{
+  int __prioceiling;
+  enum __pthread_mutex_protocol __protocol;
+  enum __pthread_process_shared __pshared;
+  enum __pthread_mutex_type __mutex_type;
+};
+
+/* Attributes for a recursive mutex.  */
+extern const struct __pthread_mutexattr __pthread_errorcheck_mutexattr;
+extern const struct __pthread_mutexattr __pthread_recursive_mutexattr;
+
+#endif /* bits/mutex-attr.h */
diff --git a/htl/sysdeps/pthread/bits/mutex.h b/htl/sysdeps/pthread/bits/mutex.h
new file mode 100644
index 0000000..3120237
--- /dev/null
+++ b/htl/sysdeps/pthread/bits/mutex.h
@@ -0,0 +1,75 @@
+/* Mutex type.  Generic version.
+
+   Copyright (C) 2000, 2002, 2005, 2006, 2007, 2008, 2009
+     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.  */
+
+#ifndef _BITS_MUTEX_H
+
+#ifndef __need_pthread_mutex
+# define _BITS_MUTEX_H	1
+#endif
+
+#ifndef __pthread_mutex_defined
+# if defined __need_pthread_mutex || defined _BITS_MUTEX_H
+#  undef __need_pthread_mutex
+#  define __pthread_mutex_defined
+
+#  include <bits/spin-lock.h>
+#  include <bits/mutex-attr.h>
+
+/* User visible part of a mutex.  */
+struct __pthread_mutex
+  {
+    __pthread_spinlock_t __held;
+    __pthread_spinlock_t __lock;
+    /* In cthreads, mutex_init does not initialized thre third
+       pointer, as such, we cannot rely on its value for anything.  */
+    char *__cthreadscompat1;
+    struct __pthread *__queue;
+    struct __pthread_mutexattr *__attr;
+    void *__data;
+    /*  Up to this point, we are completely compatible with cthreads
+	and what libc expects.  */
+    void *__owner;
+    unsigned __locks;
+    /* If NULL then the default attributes apply.  */
+  };
+
+/* Initializer for a mutex.  N.B.  this also happens to be compatible
+   with the cthread mutex initializer.  */
+#  define __PTHREAD_MUTEX_INITIALIZER \
+    { __PTHREAD_SPIN_LOCK_INITIALIZER, __PTHREAD_SPIN_LOCK_INITIALIZER, 0, 0, 0, 0, 0, 0 }
+
+#  define __PTHREAD_ERRORCHECK_MUTEXATTR ((struct __pthread_mutexattr *) ((unsigned long) __PTHREAD_MUTEX_ERRORCHECK + 1))
+
+#  define __PTHREAD_ERRORCHECK_MUTEX_INITIALIZER \
+    { __PTHREAD_SPIN_LOCK_INITIALIZER, __PTHREAD_SPIN_LOCK_INITIALIZER, 0, 0,	\
+	__PTHREAD_ERRORCHECK_MUTEXATTR, 0, 0, 0 }
+
+#  define __PTHREAD_RECURSIVE_MUTEXATTR ((struct __pthread_mutexattr *) ((unsigned long) __PTHREAD_MUTEX_RECURSIVE + 1))
+
+#  define __PTHREAD_RECURSIVE_MUTEX_INITIALIZER \
+    { __PTHREAD_SPIN_LOCK_INITIALIZER, __PTHREAD_SPIN_LOCK_INITIALIZER, 0, 0,	\
+	__PTHREAD_RECURSIVE_MUTEXATTR, 0, 0, 0 }
+
+# endif
+#endif /* Not __pthread_mutex_defined.  */
+
+#endif /* bits/mutex.h */
diff --git a/htl/sysdeps/pthread/bits/once.h b/htl/sysdeps/pthread/bits/once.h
new file mode 100644
index 0000000..53dbfd3
--- /dev/null
+++ b/htl/sysdeps/pthread/bits/once.h
@@ -0,0 +1,34 @@
+/* Dynamic package initialization data structures.  Generic version.
+   Copyright (C) 2002, 2009 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.  */
+
+#ifndef _BITS_ONCE_H
+#define _BITS_ONCE_H	1
+
+#include <bits/spin-lock.h>
+
+struct __pthread_once
+{
+  int __run;
+  __pthread_spinlock_t __lock;
+};
+
+#define __PTHREAD_ONCE_INIT \
+	(struct __pthread_once) { 0, __PTHREAD_SPIN_LOCK_INITIALIZER }
+
+#endif /* bits/once.h */
diff --git a/htl/sysdeps/pthread/bits/pthread-np.h b/htl/sysdeps/pthread/bits/pthread-np.h
new file mode 100644
index 0000000..d5ddbb0
--- /dev/null
+++ b/htl/sysdeps/pthread/bits/pthread-np.h
@@ -0,0 +1,27 @@
+/* Non-portable functions. Generic version.
+   Copyright (C) 2008 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.  */
+
+/*
+ * Never include this file directly; use <pthread.h> or <cthreads.h> instead.
+ */
+
+#ifndef _BITS_PTHREAD_NP_H
+#define _BITS_PTHREAD_NP_H	1
+
+#endif /* bits/pthread-np.h */
diff --git a/htl/sysdeps/pthread/bits/pthread.h b/htl/sysdeps/pthread/bits/pthread.h
new file mode 100644
index 0000000..80e6b09
--- /dev/null
+++ b/htl/sysdeps/pthread/bits/pthread.h
@@ -0,0 +1,38 @@
+/* Pthread data structures.  Generic version.
+   Copyright (C) 2002, 2008 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.  */
+
+#ifndef _BITS_PTHREAD_H
+#define _BITS_PTHREAD_H	1
+
+typedef int __pthread_t;
+
+/* Return true if __T1 and __T2 both name the same thread.  Otherwise,
+   false.  */
+extern int
+__pthread_equal (__pthread_t __t1, __pthread_t __t2);
+
+#ifdef __USE_EXTERN_INLINES
+__extern_inline int
+__pthread_equal (__pthread_t __t1, __pthread_t __t2)
+{
+  return __t1 == __t2;
+}
+#endif
+
+#endif /* bits/pthread.h */
diff --git a/htl/sysdeps/pthread/bits/pthreadtypes.h b/htl/sysdeps/pthread/bits/pthreadtypes.h
new file mode 100644
index 0000000..3e44d6b
--- /dev/null
+++ b/htl/sysdeps/pthread/bits/pthreadtypes.h
@@ -0,0 +1,30 @@
+/* 
+   Copyright (C) 2000-2017 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.  */
+
+#if !defined _BITS_TYPES_H && !defined _PTHREAD_H
+# error "Never include <bits/pthreadtypes.h> directly; use <sys/types.h> instead."
+#endif
+
+#ifndef _BITS_PTHREADTYPES_H
+#define _BITS_PTHREADTYPES_H    1
+
+#include <pthread/pthreadtypes.h>
+#include <bits/thread-shared-types.h>
+
+#endif /* bits/pthreadtypes.h */
diff --git a/htl/sysdeps/pthread/bits/rwlock-attr.h b/htl/sysdeps/pthread/bits/rwlock-attr.h
new file mode 100644
index 0000000..e78b91e
--- /dev/null
+++ b/htl/sysdeps/pthread/bits/rwlock-attr.h
@@ -0,0 +1,32 @@
+/* Thread rwlock attribute type.  Generic version.
+   Copyright (C) 2002, 2008 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.  */
+
+#ifndef _BITS_RWLOCK_ATTR_H
+#define _BITS_RWLOCK_ATTR_H	1
+
+enum __pthread_process_shared;
+
+/* This structure describes the attributes of a POSIX thread rwlock.
+   Note that not all of them are supported on all systems.  */
+struct __pthread_rwlockattr
+{
+  enum __pthread_process_shared __pshared;
+};
+
+#endif /* bits/rwlock-attr.h */
diff --git a/htl/sysdeps/pthread/bits/rwlock.h b/htl/sysdeps/pthread/bits/rwlock.h
new file mode 100644
index 0000000..bc27726
--- /dev/null
+++ b/htl/sysdeps/pthread/bits/rwlock.h
@@ -0,0 +1,46 @@
+/* rwlock type.  Generic version.
+   Copyright (C) 2002, 2005, 2006, 2007, 2009 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.  */
+
+#ifndef _BITS_RWLOCK_H
+#define _BITS_RWLOCK_H
+
+#include <bits/spin-lock.h>
+
+/* User visible part of a rwlock.  If __held is not held and readers
+   is 0, then the lock is unlocked.  If __held is held and readers is
+   0, then the lock is held by a writer.  If __held is held and
+   readers is greater than 0, then the lock is held by READERS
+   readers.  */
+struct __pthread_rwlock
+  {
+    __pthread_spinlock_t __held;
+    __pthread_spinlock_t __lock;
+    int __readers;
+    struct __pthread *__readerqueue;
+    struct __pthread *__writerqueue;
+    struct __pthread_rwlockattr *__attr;
+    void *__data;
+  };
+
+/* Initializer for a rwlock.  */
+#define __PTHREAD_RWLOCK_INITIALIZER \
+    { __PTHREAD_SPIN_LOCK_INITIALIZER, __PTHREAD_SPIN_LOCK_INITIALIZER, 0, 0, 0, 0, 0 }
+
+
+#endif /* bits/rwlock.h */
diff --git a/htl/sysdeps/pthread/bits/semaphore.h b/htl/sysdeps/pthread/bits/semaphore.h
new file mode 100644
index 0000000..4c78409
--- /dev/null
+++ b/htl/sysdeps/pthread/bits/semaphore.h
@@ -0,0 +1,44 @@
+/* Semaphore type.  Generic version.
+   Copyright (C) 2005, 2009 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.  */
+
+#ifndef _BITS_SEMAPHORE_H
+#define _BITS_SEMAPHORE_H	1
+
+#ifndef _SEMAPHORE_H
+#error Never include <bits/semaphore.h> directly.
+#endif
+
+#include <bits/spin-lock.h>
+#include <bits/pthread.h>
+
+/* User visible part of a semaphore.  */
+struct __semaphore
+  {
+    __pthread_spinlock_t __lock;
+    struct __pthread *__queue;
+    int __pshared;
+    int __value;
+    void *__data;
+  };
+
+/* Initializer for a semaphore.  */
+#define __SEMAPHORE_INITIALIZER(pshared, value) \
+  { __PTHREAD_SPIN_LOCK_INITIALIZER, NULL, (pshared), (value), NULL }
+
+#endif /* bits/mutex.h */
diff --git a/htl/sysdeps/pthread/bits/thread-attr.h b/htl/sysdeps/pthread/bits/thread-attr.h
new file mode 100644
index 0000000..d9456b0
--- /dev/null
+++ b/htl/sysdeps/pthread/bits/thread-attr.h
@@ -0,0 +1,47 @@
+/* Thread attribute type.  Generic version.
+   Copyright (C) 2000, 2002, 2008 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.  */
+
+#ifndef _BITS_THREAD_ATTR_H
+#define _BITS_THREAD_ATTR_H	1
+
+#define __need_schedparam
+#include <bits/sched.h>
+
+#define __need_size_t
+#include <stddef.h>
+
+enum __pthread_detachstate;
+enum __pthread_inheritsched;
+enum __pthread_contentionscope;
+
+/* This structure describes the attributes of a POSIX thread.  Note
+   that not all of them are supported on all systems.  */
+struct __pthread_attr
+{
+  struct __sched_param __schedparam;
+  void *__stackaddr;
+  size_t __stacksize;
+  size_t __guardsize;
+  enum __pthread_detachstate __detachstate;
+  enum __pthread_inheritsched __inheritsched;
+  enum __pthread_contentionscope __contentionscope;
+  int __schedpolicy;
+};
+
+#endif /* bits/thread-attr.h */
diff --git a/htl/sysdeps/pthread/bits/thread-shared-types.h b/htl/sysdeps/pthread/bits/thread-shared-types.h
new file mode 100644
index 0000000..369fead
--- /dev/null
+++ b/htl/sysdeps/pthread/bits/thread-shared-types.h
@@ -0,0 +1,24 @@
+/* Common threading primitives definitions for both POSIX and C11.
+   Copyright (C) 2017 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _THREAD_SHARED_TYPES_H
+#define _THREAD_SHARED_TYPES_H 1
+
+#include <bits/pthreadtypes-arch.h>
+
+#endif /* _THREAD_SHARED_TYPES_H  */
diff --git a/htl/sysdeps/pthread/bits/thread-specific.h b/htl/sysdeps/pthread/bits/thread-specific.h
new file mode 100644
index 0000000..b42d99e
--- /dev/null
+++ b/htl/sysdeps/pthread/bits/thread-specific.h
@@ -0,0 +1,25 @@
+/* Thread specific data.  Generic 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.  */
+
+#ifndef _BITS_THREAD_SPECIFIC_H
+#define _BITS_THREAD_SPECIFIC_H	1
+
+typedef int __pthread_key;
+
+#endif /* bits/thread-specific.h */
diff --git a/htl/sysdeps/pthread/flockfile.c b/htl/sysdeps/pthread/flockfile.c
new file mode 100644
index 0000000..0153a2c
--- /dev/null
+++ b/htl/sysdeps/pthread/flockfile.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2002-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+#include <libio.h>
+#include <libc-lock.h>
+
+
+void
+__flockfile (FILE *stream)
+{
+#ifdef SHARED
+  __libc_ptf_call (_IO_flockfile, (stream), 0);
+#endif
+}
+weak_alias (__flockfile, _IO_flockfile)
+weak_alias (__flockfile, flockfile)
diff --git a/htl/sysdeps/pthread/ftrylockfile.c b/htl/sysdeps/pthread/ftrylockfile.c
new file mode 100644
index 0000000..48420de
--- /dev/null
+++ b/htl/sysdeps/pthread/ftrylockfile.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 2002-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdio-lock.h>
+
+
+int
+__ftrylockfile (FILE *stream)
+{
+#ifdef SHARED
+  return __libc_ptf_call (_IO_ftrylockfile, (stream), 0);
+#else
+  return 0;
+#endif
+}
+weak_alias (__ftrylockfile, _IO_ftrylockfile)
+weak_alias (__ftrylockfile, ftrylockfile)
diff --git a/htl/sysdeps/pthread/funlockfile.c b/htl/sysdeps/pthread/funlockfile.c
new file mode 100644
index 0000000..78fd211
--- /dev/null
+++ b/htl/sysdeps/pthread/funlockfile.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 2002-2014 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <pthread.h>
+#include <stdio.h>
+#include <libio.h>
+#include <stdio-lock.h>
+
+
+void
+__funlockfile (FILE *stream)
+{
+#ifdef SHARED
+  __libc_ptf_call (_IO_funlockfile, (stream), 0);
+#endif
+}
+weak_alias (__funlockfile, _IO_funlockfile)
+weak_alias (__funlockfile, funlockfile)
diff --git a/htl/sysdeps/pthread/libc-lockP.h b/htl/sysdeps/pthread/libc-lockP.h
new file mode 100644
index 0000000..c04881d
--- /dev/null
+++ b/htl/sysdeps/pthread/libc-lockP.h
@@ -0,0 +1,158 @@
+/* Private libc-internal interface for mutex locks.
+   Copyright (C) 2015 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, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef _BITS_LIBC_LOCKP_H
+#define _BITS_LIBC_LOCKP_H 1
+
+#include <pthread.h>
+#include <pthread-functions.h>
+
+/* 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 && IS_IN (libc)
+# define PTFAVAIL(NAME) __libc_pthread_functions_init
+# define __libc_ptf_call(FUNC, ARGS, ELSE) \
+  (__libc_pthread_functions_init ? PTHFCT_CALL (ptr_##FUNC, ARGS) : ELSE)
+# define __libc_ptf_call_always(FUNC, ARGS) \
+  PTHFCT_CALL (ptr_##FUNC, ARGS)
+#else
+# define PTFAVAIL(NAME) (NAME != NULL)
+# define __libc_ptf_call(FUNC, ARGS, ELSE) \
+  __libc_maybe_call (FUNC, ARGS, ELSE)
+# define __libc_ptf_call_always(FUNC, ARGS) \
+  FUNC ARGS
+#endif
+
+/* 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);
+
+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);
+
+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.  */
+#if !defined(__NO_WEAK_PTHREAD_ALIASES) && !IS_IN (libpthread)
+# ifdef weak_extern
+weak_extern (__pthread_mutex_init)
+weak_extern (__pthread_mutex_destroy)
+weak_extern (__pthread_mutex_lock)
+weak_extern (__pthread_mutex_trylock)
+weak_extern (__pthread_mutex_unlock)
+weak_extern (__pthread_mutexattr_init)
+weak_extern (__pthread_mutexattr_destroy)
+weak_extern (__pthread_mutexattr_settype)
+weak_extern (__pthread_rwlock_init)
+weak_extern (__pthread_rwlock_destroy)
+weak_extern (__pthread_rwlock_rdlock)
+weak_extern (__pthread_rwlock_tryrdlock)
+weak_extern (__pthread_rwlock_wrlock)
+weak_extern (__pthread_rwlock_trywrlock)
+weak_extern (__pthread_rwlock_unlock)
+weak_extern (__pthread_key_create)
+weak_extern (__pthread_setspecific)
+weak_extern (__pthread_getspecific)
+weak_extern (__pthread_once)
+weak_extern (__pthread_initialize)
+weak_extern (__pthread_atfork)
+weak_extern (__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_setcancelstate
+# endif
+#endif
+
+#endif	/* bits/libc-lockP.h */
diff --git a/htl/sysdeps/pthread/pthread-functions.h b/htl/sysdeps/pthread/pthread-functions.h
new file mode 100644
index 0000000..0fc8968
--- /dev/null
+++ b/htl/sysdeps/pthread/pthread-functions.h
@@ -0,0 +1,141 @@
+/* Copyright (C) 2003, 2012 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>
+
+int __pthread_attr_destroy (pthread_attr_t *);
+int __pthread_attr_init (pthread_attr_t *);
+int __pthread_attr_getdetachstate (const pthread_attr_t *, int *);
+int __pthread_attr_setdetachstate (pthread_attr_t *, int);
+int __pthread_attr_getinheritsched (const pthread_attr_t *, int *);
+int __pthread_attr_setinheritsched (pthread_attr_t *, int);
+int __pthread_attr_getschedparam (const pthread_attr_t *,
+    				 struct sched_param *);
+int __pthread_attr_setschedparam (pthread_attr_t *,
+    				 const struct sched_param *);
+int __pthread_attr_getschedpolicy (const pthread_attr_t *, int *);
+int __pthread_attr_setschedpolicy (pthread_attr_t *, int);
+int __pthread_attr_getscope (const pthread_attr_t *, int *);
+int __pthread_attr_setscope (pthread_attr_t *, int);
+int __pthread_condattr_destroy (pthread_condattr_t *);
+int __pthread_condattr_init (pthread_condattr_t *);
+int __pthread_cond_broadcast (pthread_cond_t *);
+int __pthread_cond_destroy (pthread_cond_t *);
+int __pthread_cond_init (pthread_cond_t *,
+    		       const pthread_condattr_t *);
+int __pthread_cond_signal (pthread_cond_t *);
+int __pthread_cond_wait (pthread_cond_t *, pthread_mutex_t *);
+int __pthread_cond_timedwait (pthread_cond_t *, pthread_mutex_t *,
+    			     const struct timespec *);
+int __pthread_equal (pthread_t, pthread_t);
+void __pthread_exit (void *);
+int __pthread_getschedparam (pthread_t, int *, struct sched_param *);
+int __pthread_setschedparam (pthread_t, int,
+    			    const struct sched_param *);
+int _pthread_mutex_destroy (pthread_mutex_t *);
+int _pthread_mutex_init (pthread_mutex_t *,
+    			 const pthread_mutexattr_t *);
+int __pthread_mutex_lock (pthread_mutex_t *);
+int __pthread_mutex_trylock (pthread_mutex_t *);
+int __pthread_mutex_unlock (pthread_mutex_t *);
+pthread_t __pthread_self (void);
+int __pthread_setcancelstate (int, int *);
+int __pthread_setcanceltype (int, int *);
+struct __pthread_cancelation_handler **__pthread_get_cleanup_stack (void);
+int __pthread_once (pthread_once_t *, void (*) (void));
+int __pthread_rwlock_rdlock (pthread_rwlock_t *);
+int __pthread_rwlock_wrlock (pthread_rwlock_t *);
+int __pthread_rwlock_unlock (pthread_rwlock_t *);
+int __pthread_key_create (pthread_key_t *, void (*) (void *));
+void *__pthread_getspecific (pthread_key_t);
+int __pthread_setspecific (pthread_key_t, const void *);
+
+void _cthreads_flockfile (FILE *);
+void _cthreads_funlockfile (FILE *);
+int _cthreads_ftrylockfile (FILE *);
+
+/* Data type shared with libc.  The libc uses it to pass on calls to
+   the thread functions.  Wine pokes directly into this structure,
+   so if possible avoid breaking it and append new hooks to the end.  */
+struct pthread_functions
+{
+  int (*ptr_pthread_attr_destroy) (pthread_attr_t *);
+  int (*ptr_pthread_attr_init) (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_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_trylock) (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 *);
+  struct __pthread_cancelation_handler **(*ptr___pthread_get_cleanup_stack) (void);
+  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__IO_flockfile) (FILE *);
+  void (*ptr__IO_funlockfile) (FILE *);
+  int (*ptr__IO_ftrylockfile) (FILE *);
+};
+
+/* Variable in libc.so.  */
+extern struct pthread_functions __libc_pthread_functions attribute_hidden;
+extern int __libc_pthread_functions_init attribute_hidden;
+
+void __libc_pthread_init (const struct pthread_functions *functions);
+
+# define PTHFCT_CALL(fct, params) \
+    __libc_pthread_functions.fct params
+
+#endif	/* pthread-functions.h */
diff --git a/htl/sysdeps/pthread/pthread.h b/htl/sysdeps/pthread/pthread.h
new file mode 100644
index 0000000..8e65b05
--- /dev/null
+++ b/htl/sysdeps/pthread/pthread.h
@@ -0,0 +1,22 @@
+#ifndef _PTHREAD_H
+#include <pthread/pthread.h>
+
+/* These represent the interface used by glibc itself.  */
+
+extern int __pthread_mutex_lock (pthread_mutex_t *__mutex);
+extern int __pthread_mutex_unlock (pthread_mutex_t *__mutex);
+
+typedef struct __cthread *__cthread_t;
+typedef int __cthread_key_t;
+typedef void *	(*__cthread_fn_t)(void *__arg);
+
+__cthread_t __cthread_fork (__cthread_fn_t, void *);
+void __cthread_detach (__cthread_t);
+int __cthread_keycreate (__cthread_key_t *);
+int __cthread_getspecific (__cthread_key_t, void **);
+int __cthread_setspecific (__cthread_key_t, void *);
+
+int __pthread_getattr_np (pthread_t, pthread_attr_t *);
+int __pthread_attr_getstack (const pthread_attr_t *, void **, size_t *);
+
+#endif
diff --git a/htl/sysdeps/pthread/pthreadP.h b/htl/sysdeps/pthread/pthreadP.h
new file mode 100644
index 0000000..97e3028
--- /dev/null
+++ b/htl/sysdeps/pthread/pthreadP.h
@@ -0,0 +1,27 @@
+/* Copyright (C) 2016 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _PTHREADP_H
+#define _PTHREADP_H	1
+
+#include <pthread.h>
+
+extern pthread_t __pthread_self (void);
+extern int __pthread_kill (pthread_t threadid, int signo);
+extern struct __pthread **__pthread_threads;
+
+#endif	/* pthreadP.h */
diff --git a/htl/sysdeps/pthread/semaphore.h b/htl/sysdeps/pthread/semaphore.h
new file mode 100644
index 0000000..64249f6
--- /dev/null
+++ b/htl/sysdeps/pthread/semaphore.h
@@ -0,0 +1,81 @@
+/* Copyright (C) 2005, 2007 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.  */
+
+#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 struct __semaphore.  */
+#include <bits/semaphore.h>
+
+
+__BEGIN_DECLS
+
+#define SEM_FAILED ((void *) 0)
+
+typedef struct __semaphore sem_t;
+
+/* Initialize semaphore *SEM with value VALUE.  */
+extern int sem_init (sem_t *__sem, int __pshared, unsigned int __value)
+     __THROW;
+/* Destroy semaphore *SEM created with sem_init.  */
+extern int sem_destroy (sem_t *__sem) __THROW;
+
+/* Open a named semaphore.  */
+extern sem_t *sem_open (const char *__name, int __oflag, ...) __THROW;
+
+/* Close a semaphore returned by sem_open.  */
+extern int sem_close (sem_t *__sem) __THROW;
+
+/* Unlink a named semaphore.  */
+extern int sem_unlink (const char *__name) __THROW;
+
+/* Perform a down operation on semaphore *SEM.
+
+   This function is a cancellation point and therefore not marked with
+   __THROW.  */
+extern int sem_wait (sem_t *__sem);
+
+#ifdef __USE_XOPEN2K
+/* Perform a down operation on semaphore *SEM but don't wait longer
+   than TIMEOUT.  */
+extern int sem_timedwait (sem_t *__restrict __sem,
+			  const struct timespec *__restrict __abstime);
+#endif
+
+/* Perform a down operation on semaphore *SEM if it can be done so
+   without blocking.  */
+extern int sem_trywait (sem_t *__sem) __THROWNL;
+
+/* Perform an up operation on semaphore *SEM.  */
+extern int sem_post (sem_t *__sem) __THROWNL;
+
+/* Store the value of semaphore *SEM in *VALUE.  */
+extern int sem_getvalue (sem_t *__restrict __sem, int *__restrict __sval)
+    __THROW;
+
+
+__END_DECLS
+
+#endif /* semaphore.h */
diff --git a/htl/tests/.cvsignore b/htl/tests/.cvsignore
new file mode 100644
index 0000000..70845e0
--- /dev/null
+++ b/htl/tests/.cvsignore
@@ -0,0 +1 @@
+Makefile.in
diff --git a/htl/tests/Makefile b/htl/tests/Makefile
new file mode 100644
index 0000000..7177ad1
--- /dev/null
+++ b/htl/tests/Makefile
@@ -0,0 +1,40 @@
+ifdef INSTALL_ROOT
+INSTALL_ROOT_CPPFLAGS = -isystem $(INSTALL_ROOT)/include
+INSTALL_ROOT_LDFLAGS = -L$(INSTALL_ROOT)/lib -Wl,-rpath,$(INSTALL_ROOT)/lib
+endif
+
+CFLAGS=-Wall -g
+
+LDLIBS = -lpthread
+
+CHECK_SRC := test-1.c test-2.c test-3.c test-6.c test-7.c test-8.c	\
+	test-9.c test-10.c test-11.c test-12.c test-13.c test-14.c	\
+	test-15.c test-16.c test-17.c test-__pthread_destroy_specific-skip.c
+
+CHECK_OBJS := $(addsuffix .o,$(basename $(notdir $(CHECK_SRC))))
+CHECK_PROGS := $(basename $(notdir $(CHECK_SRC))) \
+	$(addsuffix -static, $(basename $(CHECK_SRC)))
+
+%.o: %.c
+	$(CC) $(INSTALL_ROOT_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) $< -c -o $@
+
+%: %.o
+	$(CC) $(INSTALL_ROOT_LDFLAGS) $(LDFLAGS) $< -o $@ $(LDLIBS)
+
+%-static: %.o
+	$(CC) -static $(INSTALL_ROOT_LDFLAGS) $(LDFLAGS) $< -o $@ $(LDLIBS)
+
+check: $(CHECK_OBJS) $(CHECK_PROGS)
+	for i in $(CHECK_PROGS); do		\
+	  echo -n Running $$i...\ ;		\
+	  if ./$$i 2>&1 > $$i.out;		\
+	  then					\
+	    echo Success.;			\
+	  else					\
+	    echo Failure.;			\
+	  fi					\
+	done
+
+clean:
+	rm -f $(CHECK_OBJS) $(CHECK_PROGS) \
+	  $(addsuffix .out,$(basename $(notdir $(CHECK_PROGS))))
\ No newline at end of file
diff --git a/htl/tests/README b/htl/tests/README
new file mode 100644
index 0000000..230f1b2
--- /dev/null
+++ b/htl/tests/README
@@ -0,0 +1,6 @@
+Testing of installed package:
+
+    $ [libpthread]/configure --prefix=[install_root]
+    $ make
+    $ make install
+    $ make -C [libpthread]/tests/ INSTALL_ROOT=[install_root] clean check
diff --git a/htl/tests/test-1.c b/htl/tests/test-1.c
new file mode 100644
index 0000000..6ec1afb
--- /dev/null
+++ b/htl/tests/test-1.c
@@ -0,0 +1,50 @@
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <unistd.h>
+#include <error.h>
+#include <errno.h>
+#include <stdio.h>
+
+#define THREADS 500
+
+void *
+foo (void *arg)
+{
+  pthread_mutex_t *mutex = arg;
+  pthread_mutex_lock (mutex);
+  pthread_mutex_unlock (mutex);
+  return mutex;
+}
+
+int
+main (int argc, char **argv)
+{
+  int i;
+  error_t err;
+  pthread_t tid[THREADS];
+  pthread_mutex_t mutex[THREADS];
+
+  for (i = 0; i < THREADS; i ++)
+    {
+      pthread_mutex_init (&mutex[i], 0);
+      pthread_mutex_lock (&mutex[i]);
+      err = pthread_create (&tid[i], 0, foo, &mutex[i]);
+      if (err)
+	error (1, err, "pthread_create");
+      sched_yield ();
+    }
+
+  for (i = THREADS - 1; i >= 0; i --)
+    {
+      void *ret;
+      pthread_mutex_unlock (&mutex[i]);
+      err = pthread_join (tid[i], &ret);
+      if (err)
+	error (1, err, "pthread_join");
+      assert (ret == &mutex[i]);
+    }
+
+  return 0;
+}
diff --git a/htl/tests/test-10.c b/htl/tests/test-10.c
new file mode 100644
index 0000000..bec05c1
--- /dev/null
+++ b/htl/tests/test-10.c
@@ -0,0 +1,46 @@
+/* Test error checking mutexes.  */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+
+int
+main (int argc, char **argv)
+{
+  error_t err;
+  pthread_mutexattr_t mattr;
+  pthread_mutex_t mutex;
+
+  err = pthread_mutexattr_init (&mattr);
+  if (err)
+    error (1, err, "pthread_mutexattr_init");
+
+  err = pthread_mutexattr_settype (&mattr, PTHREAD_MUTEX_ERRORCHECK);
+  if (err)
+    error (1, err, "pthread_mutexattr_settype");
+
+  err = pthread_mutex_init (&mutex, &mattr);
+  if (err)
+    error (1, err, "pthread_mutex_init");
+
+  err = pthread_mutexattr_destroy (&mattr);
+  if (err)
+    error (1, err, "pthread_mutexattr_destroy");
+
+  err = pthread_mutex_lock (&mutex);
+  assert (err == 0);
+
+  err = pthread_mutex_lock (&mutex);
+  assert (err == EDEADLK);
+
+  err = pthread_mutex_unlock (&mutex);
+  assert (err == 0);
+
+  err = pthread_mutex_unlock (&mutex);
+  assert (err == EPERM);
+
+  return 0;
+}
diff --git a/htl/tests/test-11.c b/htl/tests/test-11.c
new file mode 100644
index 0000000..de779a4
--- /dev/null
+++ b/htl/tests/test-11.c
@@ -0,0 +1,143 @@
+/* Test rwlocks.  */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+
+#define THREADS 1
+
+int a;
+int b;
+
+/* Get a read lock and assert that a == b.  */
+void *
+test1 (void *arg)
+{
+  error_t err;
+  pthread_rwlock_t *lock = arg;
+  int i;
+
+  for (i = 0; i < 200; i ++)
+    {
+      err = pthread_rwlock_rdlock (lock);
+      assert (err == 0);
+
+      assert (a == b);
+
+      sched_yield ();
+
+      assert (a == b);
+
+      err = pthread_rwlock_unlock (lock);
+      assert (err == 0);
+    }
+
+  return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+  error_t err;
+  pthread_rwlockattr_t attr;
+  pthread_rwlock_t lock;
+  int pshared;
+
+  int i;
+  pthread_t tid[THREADS];
+  void *ret;
+
+  err = pthread_rwlockattr_init (&attr);
+  if (err)
+    error (1, err, "pthread_rwlockattr_init");
+
+  err = pthread_rwlockattr_getpshared (&attr, &pshared);
+  if (err)
+    error (1, err, "pthread_rwlockattr_getpshared");
+
+  /* Assert the default state as mandated by POSIX.  */
+  assert (pshared == PTHREAD_PROCESS_PRIVATE);
+
+  err = pthread_rwlockattr_setpshared (&attr, pshared);
+  if (err)
+    error (1, err, "pthread_rwlockattr_setpshared");
+
+  err = pthread_rwlock_init (&lock, &attr);
+  if (err)
+    error (1, err, "pthread_rwlock_init");
+
+  err = pthread_rwlockattr_destroy (&attr);
+  if (err)
+    error (1, err, "pthread_rwlockattr_destroy");
+
+  /* Now test the lock.  */
+
+  for (i = 0; i < THREADS; i ++)
+    {
+      err = pthread_create (&tid[i], 0, test1, &lock);
+      if (err)
+	error (1, err, "pthread_create");
+    }
+
+  for (i = 0; i < 10; i ++)
+    {
+      sched_yield ();
+
+      /* Get a write lock.  */
+      pthread_rwlock_wrlock (&lock);
+      /* Increment a and b giving other threads a chance to run in
+	 between.  */
+      sched_yield ();
+      a ++;
+      sched_yield ();
+      b ++;
+      sched_yield ();
+      /* Unlock.  */
+      pthread_rwlock_unlock (&lock);
+    }
+
+  for (i = 0; i < THREADS; i ++)
+    {
+      err = pthread_join (tid[i], &ret);
+      if (err)
+	error (1, err, "pthread_join");
+    }
+
+  /* Read lock it.  */
+  err = pthread_rwlock_tryrdlock (&lock);
+  assert (err == 0);
+  
+  /* Try to write lock it.  It should fail with EBUSY.  */
+  err = pthread_rwlock_trywrlock (&lock);
+  assert (err == EBUSY);
+  
+  /* Drop the read lock.  */
+  err = pthread_rwlock_unlock (&lock);
+  assert (err == 0);
+
+  /* Get a write lock.  */
+  err = pthread_rwlock_trywrlock (&lock);
+  assert (err == 0);
+
+  /* Fail trying to acquire another write lock.  */
+  err = pthread_rwlock_trywrlock (&lock);
+  assert (err == EBUSY);
+
+  /* Try to get a read lock which should also fail.  */
+  err = pthread_rwlock_tryrdlock (&lock);
+  assert (err == EBUSY);
+
+  /* Unlock it.  */
+  err = pthread_rwlock_unlock (&lock);
+  assert (err == 0);
+
+
+  err = pthread_rwlock_destroy (&lock);
+  if (err)
+    error (1, err, "pthread_rwlock_destroy");
+
+  return 0;
+}
diff --git a/htl/tests/test-12.c b/htl/tests/test-12.c
new file mode 100644
index 0000000..2b78490
--- /dev/null
+++ b/htl/tests/test-12.c
@@ -0,0 +1,29 @@
+/* Test concurrency level.  */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+
+int
+main (int argc, char **argv)
+{
+  int i;
+  int err;
+
+  i = pthread_getconcurrency ();
+  assert (i == 0);
+
+  err = pthread_setconcurrency (-1);
+  assert (err == EINVAL);
+
+  err = pthread_setconcurrency (4);
+  assert (err == 0);
+
+  i = pthread_getconcurrency ();
+  assert (i == 4);
+
+  return 0;
+}
diff --git a/htl/tests/test-13.c b/htl/tests/test-13.c
new file mode 100644
index 0000000..13b0905
--- /dev/null
+++ b/htl/tests/test-13.c
@@ -0,0 +1,66 @@
+/* Test condition attributes and pthread_cond_timedwait.  */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <stdio.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+#include <sys/time.h>
+
+int
+main (int argc, char **argv)
+{
+  error_t err;
+  int i;
+  pthread_condattr_t attr;
+  pthread_cond_t cond;
+  struct timespec ts;
+  pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
+  struct timeval before, after;
+  int diff;
+
+  err = pthread_condattr_init (&attr);
+  if (err)
+    error (1, err, "pthread_condattr_init");
+
+  err = pthread_condattr_getpshared (&attr, &i);
+  if (err)
+    error (1, err, "pthread_condattr_getpshared");
+  assert (i == PTHREAD_PROCESS_PRIVATE);
+
+  err = pthread_condattr_setpshared (&attr, PTHREAD_PROCESS_PRIVATE);
+  assert (err == 0);
+
+  err = pthread_cond_init (&cond, &attr);
+  if (err)
+    error (1, err, "pthread_cond_init");
+
+  err = pthread_condattr_destroy (&attr);
+  if (err)
+    error (1, err, "pthread_condattr_destroy");
+
+  gettimeofday (&before, 0);
+  ts.tv_sec = before.tv_sec + 1;
+  ts.tv_nsec = before.tv_usec * 1000;
+
+  printf ("Starting wait @ %d\n", (int) before.tv_sec);
+
+  pthread_mutex_lock (&m);
+  err = pthread_cond_timedwait (&cond, &m, &ts);
+
+  gettimeofday (&after, 0);
+
+  printf ("End wait @ %d (err = %d)\n", (int) after.tv_sec, err);
+
+  assert (err == ETIMEDOUT);
+
+  diff = after.tv_sec * 1000000 + after.tv_usec
+    - before.tv_sec * 1000000 - before.tv_usec;
+
+  if (diff < 900000 || diff > 1100000)
+    error (1, EGRATUITOUS, "pthread_cond_timedwait waited %d us", diff);
+
+  return 0;
+}
diff --git a/htl/tests/test-14.c b/htl/tests/test-14.c
new file mode 100644
index 0000000..b1dbfa6
--- /dev/null
+++ b/htl/tests/test-14.c
@@ -0,0 +1,44 @@
+/* Test pthread_mutex_timedlock.  */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <stdio.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+#include <sys/time.h>
+
+int
+main (int argc, char **argv)
+{
+  error_t err;
+  struct timespec ts;
+  pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
+  struct timeval before, after;
+  int diff;
+
+  gettimeofday (&before, 0);
+  ts.tv_sec = before.tv_sec + 1;
+  ts.tv_nsec = before.tv_usec * 1000;
+
+  printf ("Starting wait @ %d\n", (int) before.tv_sec);
+
+  pthread_mutex_lock (&m);
+  /* A default mutex shall dead lock if locked twice.  As such we do
+     not need spawn a second thread.  */
+  err = pthread_mutex_timedlock (&m, &ts);
+  assert (err == ETIMEDOUT);
+
+  gettimeofday (&after, 0);
+
+  printf ("End wait @ %d\n", (int) after.tv_sec);
+
+  diff = after.tv_sec * 1000000 + after.tv_usec
+    - before.tv_sec * 1000000 - before.tv_usec;
+
+  if (diff < 900000 || diff > 1100000)
+    error (1, EGRATUITOUS, "pthread_mutex_timedlock waited %d us", diff);
+
+  return 0;
+}
diff --git a/htl/tests/test-15.c b/htl/tests/test-15.c
new file mode 100644
index 0000000..173f8b6
--- /dev/null
+++ b/htl/tests/test-15.c
@@ -0,0 +1,87 @@
+/* Test pthread_rwlock_timedrdlock and pthread_rwlock_timedwrlock.  */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <stdio.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+#include <sys/time.h>
+
+#define THREADS 10
+
+pthread_rwlock_t rwlock;
+
+void *
+test (void *arg)
+{
+  error_t err;
+  int foo = (int) arg;
+  struct timespec ts;
+  struct timeval before, after;
+  int diff;
+
+  gettimeofday (&before, 0);
+  ts.tv_sec = before.tv_sec + 1;
+  ts.tv_nsec = before.tv_usec * 1000;
+
+  printf ("Thread %d starting wait @ %d\n", pthread_self (),
+	  (int) before.tv_sec);
+
+  if (foo % 2 == 0)
+    err = pthread_rwlock_timedrdlock (&rwlock, &ts);
+  else
+    err = pthread_rwlock_timedwrlock (&rwlock, &ts);
+
+  assert (err == ETIMEDOUT);
+
+  gettimeofday (&after, 0);
+
+  printf ("Thread %d ending wait @ %d\n", pthread_self (),
+	  (int) after.tv_sec);
+
+  diff = after.tv_sec * 1000000 + after.tv_usec
+    - before.tv_sec * 1000000 - before.tv_usec;
+
+  if (diff < 900000 || diff > 1100000)
+    error (1, EGRATUITOUS, "pthread_mutex_timedlock waited %d us", diff);
+
+  return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+  error_t err;
+  int i;
+  pthread_t tid[THREADS];
+
+  err = pthread_rwlock_init (&rwlock, 0);
+  if (err)
+    error (1, err, "pthread_rwlock_init");
+
+  /* Lock it so all the threads will block.  */
+  err = pthread_rwlock_wrlock (&rwlock);
+  assert (err == 0);
+
+  for (i = 0; i < THREADS; i ++)
+    {
+      err = pthread_create (&tid[i], 0, test, (void *) i);
+      if (err)
+	error (1, err, "pthread_create");
+    }
+
+  for (i = 0; i < THREADS; i ++)
+    {
+      void *ret;
+
+      err = pthread_join (tid[i], &ret);
+      if (err)
+	error (1, err, "pthread_join");
+
+      assert (ret == 0);
+    }
+
+  return 0;
+}
diff --git a/htl/tests/test-16.c b/htl/tests/test-16.c
new file mode 100644
index 0000000..3660f5f
--- /dev/null
+++ b/htl/tests/test-16.c
@@ -0,0 +1,71 @@
+/* Test pthread_kill.c.  */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+#include <hurd/signal.h>
+
+pthread_t testthread;
+
+int i;
+
+void *
+test (void *arg)
+{
+  error_t err;
+
+  printf ("test: %d\n", pthread_self ());
+
+  err = pthread_kill (pthread_self (), SIGINFO);
+  if (err)
+    error (1, err, "pthread_kill");
+
+  /* To avoid using condition variables in a signal handler.  */
+  while (i == 0)
+    sched_yield ();
+
+  return 0;
+}
+
+static void
+handler (int sig)
+{
+  assert (pthread_equal (pthread_self (), testthread));
+  printf ("handler: %d\n", pthread_self ());
+  i = 1;
+}
+
+int
+main (int argc, char **argv)
+{
+  error_t err;
+  struct sigaction sa;
+  void *ret;
+
+  printf ("main: %d\n", pthread_self ());
+
+  sa.sa_handler = handler;
+  sa.sa_mask = 0;
+  sa.sa_flags = 0;
+
+  err = sigaction (SIGINFO, &sa, 0);
+  if (err)
+    error (1, err, "sigaction");
+
+  err = pthread_create (&testthread, 0, test, 0);
+  if (err)
+    error (1, err, "pthread_create");
+
+  err = pthread_join (testthread, &ret);
+  if (err)
+    error (1, err, "pthread_join");
+
+  assert (ret == 0);
+
+  return 0;
+}
diff --git a/htl/tests/test-17.c b/htl/tests/test-17.c
new file mode 100644
index 0000000..a8bd150
--- /dev/null
+++ b/htl/tests/test-17.c
@@ -0,0 +1,57 @@
+/* Test that the key reuse inside libpthread does not cause thread
+   specific values to persist. */
+
+#define _GNU_SOURCE 1
+
+#include <pthread.h>
+#include <stdio.h>
+#include <assert.h>
+#include <errno.h>
+
+void
+work (int iter)
+{
+  error_t err;
+  pthread_key_t key1;
+  pthread_key_t key2;
+  void *value1;
+  void *value2;
+
+  printf ("work/%d: start\n", iter);
+  err = pthread_key_create (&key1, NULL);
+  assert (err == 0);
+  err = pthread_key_create (&key2, NULL);
+  assert (err == 0);
+
+  value1 = pthread_getspecific (key1);
+  value2 = pthread_getspecific (key2);
+  printf ("work/%d: pre-setspecific: %p,%p\n", iter, value1, value2);
+  assert (value1 == NULL);
+  assert (value2 == NULL);
+  err = pthread_setspecific (key1, (void *)(0x100 + iter));
+  assert (err == 0);
+  err = pthread_setspecific (key2, (void *)(0x200 + iter));
+  assert (err == 0);
+
+  value1 = pthread_getspecific (key1);
+  value2 = pthread_getspecific (key2);
+  printf ("work/%d: post-setspecific: %p,%p\n", iter, value1, value2);
+  assert (value1 == (void *)(0x100 + iter));
+  assert (value2 == (void *)(0x200 + iter));
+
+  err = pthread_key_delete (key1);
+  assert (err == 0);
+  err = pthread_key_delete (key2);
+  assert (err == 0);
+}
+
+int
+main (int argc, char *argv[])
+{
+  int i;
+
+  for (i = 0; i < 8; ++i)
+    work (i + 1);
+
+  return 0;
+}
diff --git a/htl/tests/test-2.c b/htl/tests/test-2.c
new file mode 100644
index 0000000..701462e
--- /dev/null
+++ b/htl/tests/test-2.c
@@ -0,0 +1,39 @@
+/* Test detachability.  */
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+#include <unistd.h>
+
+void *
+thread (void *arg)
+{
+  while (1)
+    sched_yield ();
+}
+
+int
+main (int argc, char **argv)
+{
+  int err;
+  pthread_t tid;
+  void *ret;
+
+  err = pthread_create (&tid, 0, thread, 0);
+  if (err)
+    error (1, err, "pthread_create");
+
+  err = pthread_detach (tid);
+  if (err)
+    error (1, err, "pthread_detach");
+
+  err = pthread_detach (tid);
+  assert (err == EINVAL);
+
+  err = pthread_join (tid, &ret);
+  assert (err == EINVAL);
+
+  return 0;
+}
diff --git a/htl/tests/test-3.c b/htl/tests/test-3.c
new file mode 100644
index 0000000..7db2e43
--- /dev/null
+++ b/htl/tests/test-3.c
@@ -0,0 +1,55 @@
+/* Test the thread attribute get and set methods.  */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <sched.h>
+#include <assert.h>
+#include <errno.h>
+
+int
+main (int argc, char *argv[])
+{
+  error_t err;
+  pthread_attr_t attr;
+
+  int i;
+  struct sched_param sp;
+  void *p;
+  size_t sz;
+
+  err = pthread_attr_init (&attr);
+  assert_perror (err);
+
+  err = pthread_attr_destroy (&attr);
+  assert_perror (err);
+
+  err = pthread_attr_init (&attr);
+  assert_perror (err);
+
+#define TEST1(foo, rv, v) \
+	err = pthread_attr_get##foo (&attr, rv); \
+	assert_perror (err); \
+	\
+	err = pthread_attr_set##foo (&attr, v); \
+	assert_perror (err);
+
+#define TEST(foo, rv, v) TEST1(foo, rv, v)
+
+  TEST(inheritsched, &i, i);
+  TEST(schedparam, &sp, &sp);
+  TEST(schedpolicy, &i, i);
+  TEST(scope, &i, i);
+  TEST(stackaddr, &p, p);
+  TEST(detachstate, &i, i);
+  TEST(guardsize, &sz, sz);
+  TEST(stacksize, &sz, sz);
+
+  err = pthread_attr_getstack (&attr, &p, &sz);
+  assert_perror (err);
+
+  err = pthread_attr_setstack (&attr, p, sz);
+  assert_perror (err);
+
+  return 0;
+}
diff --git a/htl/tests/test-4.c b/htl/tests/test-4.c
new file mode 100644
index 0000000..de9c8fe
--- /dev/null
+++ b/htl/tests/test-4.c
@@ -0,0 +1,86 @@
+/* Test the stack guard.  */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+size_t stacksize;
+
+void *
+thr (void *arg)
+{
+  int i;
+  char *foo;
+
+  foo = alloca (3 * stacksize / 4);
+  for (i = 0; i < sizeof foo; i ++)
+    foo[i] = -1;
+
+  return (void *) 1;
+}
+
+int
+main (int argc, char *argv[])
+{
+  error_t err;
+  pid_t child;
+
+  child = fork ();
+  switch (child)
+    {
+    case -1:
+      error (1, errno, "fork");
+      break;
+
+    case 0:
+      {
+	pthread_attr_t attr;
+	pthread_t tid;
+	void *ret;
+
+	err = pthread_attr_init (&attr);
+	assert_perror (err);
+
+	err = pthread_attr_getstacksize (&attr, &stacksize);
+	assert_perror (err);
+
+	err = pthread_attr_setguardsize (&attr, stacksize / 2);
+	if (err == ENOTSUP)
+	  {
+	    printf ("Stack guard attribute not supported.\n");
+	    return 1;
+	  }
+	assert_perror (err);
+
+	err = pthread_create (&tid, &attr, thr, 0);
+	assert_perror (err);
+
+	err = pthread_attr_destroy (&attr);
+	assert_perror (err);
+
+	err = pthread_join (tid, &ret);
+	/* Should never be successful.  */
+	printf ("Thread did not segfault!?!\n");
+	assert_perror (err);
+	return 0;
+      }
+
+    default:
+      {
+	pid_t pid;
+	int status;
+
+	pid = waitpid (child, &status, 0);
+	printf ("pid = %d; child = %d; status = %d\n", pid, child, status);
+	assert (pid == child);
+	assert (status != 0);
+      }
+    }
+
+  return 0;
+}
diff --git a/htl/tests/test-5.c b/htl/tests/test-5.c
new file mode 100644
index 0000000..0f5000b
--- /dev/null
+++ b/htl/tests/test-5.c
@@ -0,0 +1,75 @@
+/* Test signals.  */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <error.h>
+#include <assert.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
+
+void *
+thr (void *arg)
+{
+  * (int *)0 = 0;
+  return 0;
+}
+
+int foobar;
+
+int
+main (int argc, char *argv[])
+{
+  error_t err;
+  pid_t child;
+
+  struct rlimit limit;
+
+  limit.rlim_cur = 0;
+  limit.rlim_max = 0;
+
+  err = setrlimit (RLIMIT_CORE, &limit);
+  if (err)
+    error (1, err, "setrlimit");
+
+  child = fork ();
+  switch (child)
+    {
+    case -1:
+      error (1, errno, "fork");
+      break;
+
+    case 0:
+      {
+	pthread_t tid;
+	void *ret;
+
+	err = pthread_create (&tid, 0, thr, 0);
+	if (err)
+	  error (1, err, "pthread_create");
+
+	err = pthread_join (tid, &ret);
+	assert_perror (err);
+
+	/* Should have never returned.  Our parent expects us to fail
+	   thus we succeed and indicate the error.  */
+	return 0;
+      }
+
+    default:
+      {
+	pid_t pid;
+	int status;
+
+	pid = waitpid (child, &status, 0);
+	printf ("pid = %d; child = %d; status = %d\n", pid, child, status);
+	assert (pid == child);
+	assert (status != 0);
+      }
+    }
+
+  return 0;
+}
diff --git a/htl/tests/test-6.c b/htl/tests/test-6.c
new file mode 100644
index 0000000..edf2919
--- /dev/null
+++ b/htl/tests/test-6.c
@@ -0,0 +1,96 @@
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <stdio.h>
+#include <error.h>
+#include <assert.h>
+#include <errno.h>
+
+#define THREADS 500
+#define WAITS 3
+
+void *
+dowait (void *arg)
+{
+  pthread_barrier_t *barrier = arg;
+  int ret;
+
+  ret = pthread_barrier_wait (barrier);
+  printf ("%d ", pthread_self ());
+  return (void *) ret;
+}
+
+int
+main (int argc, char **argv)
+{
+  pthread_barrierattr_t attr;
+  pthread_barrier_t barrier;
+
+  int i, j;
+  error_t err;
+  pthread_t tid[THREADS];
+
+  int havesyncs;
+
+  err = pthread_barrierattr_init (&attr);
+  if (err)
+    error (1, err, "pthread_barrierattr_init");
+
+  err = pthread_barrierattr_getpshared (&attr, &i);
+  if (err)
+    error (1, err, "pthread_barrierattr_getpshared");
+  assert (i == PTHREAD_PROCESS_PRIVATE || i == PTHREAD_PROCESS_SHARED);
+
+  err = pthread_barrierattr_setpshared (&attr, PTHREAD_PROCESS_PRIVATE);
+  if (err)
+    error (1, err, "pthread_barrierattr_setpshared");
+
+  err = pthread_barrier_init (&barrier, &attr, THREADS + 1);
+  if (err)
+    error (1, err, "pthread_barrier_init");
+
+  for (j = 0; j < WAITS; j ++)
+    {    
+
+      for (i = 0; i < THREADS; i ++)
+	{
+	  err = pthread_create (&tid[i], 0, dowait, &barrier);
+	  if (err)
+	    error (1, err, "pthread_create (%d)", i);
+	}
+
+      printf ("Manager will now call pthread_barrier_wait.\n");
+
+      havesyncs
+	= pthread_barrier_wait (&barrier) == PTHREAD_BARRIER_SERIAL_THREAD
+	? 1 : 0;
+
+      for (i = THREADS - 1; i >= 0; i --)
+	{
+	  void *ret;
+	  err = pthread_join (tid[i], &ret);
+	  if (err)
+	    error (1, err, "pthread_join");
+
+	  switch ((int) ret)
+	    {
+	    case 0:
+	      break;
+
+	    case PTHREAD_BARRIER_SERIAL_THREAD:
+	      havesyncs ++;
+	      break;
+
+	    default:
+	      assert (! "Unknown value returned from pthread_barrier_wait.");
+	      break;
+	    }
+	}
+
+      printf ("\n");
+
+      assert (havesyncs == 1);
+    }
+
+  return 0;
+}
diff --git a/htl/tests/test-7.c b/htl/tests/test-7.c
new file mode 100644
index 0000000..22fb1ca
--- /dev/null
+++ b/htl/tests/test-7.c
@@ -0,0 +1,70 @@
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <stdio.h>
+#include <error.h>
+#include <errno.h>
+
+#define THREADS 10
+#define KEYS 400
+
+pthread_key_t key[KEYS];
+
+void *
+thr (void *arg)
+{
+  error_t err;
+  int i;
+
+  for (i = 0; i < KEYS; i ++)
+    {
+      printf ("pthread_getspecific(%d).\n", key[i]);
+      assert (pthread_getspecific (key[i]) == NULL);
+      printf ("pthread_setspecific(%d, %d).\n", key[i], pthread_self ());
+      err = pthread_setspecific (key[i], (void *) pthread_self ());
+      printf ("pthread_setspecific(%d, %d) => %d.\n", key[i], pthread_self (), err);      
+      assert_perror (err);
+    }
+
+  return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+  error_t err;
+  int i;
+  pthread_t tid[THREADS];
+
+  void des (void *val)
+    {
+      assert ((pthread_t) val == pthread_self ());
+    }
+
+  assert (pthread_getspecific ((pthread_key_t) 0) == NULL);
+  assert (pthread_setspecific ((pthread_key_t) 0, (void *) 0x1) == EINVAL);
+
+  for (i = 0; i < KEYS; i ++)
+    err = pthread_key_create (&key[i], des);
+
+  for (i = 0; i < THREADS; i ++)
+    {
+      err = pthread_create (&tid[i], 0, thr, 0);
+      if (err)
+	error (1, err, "pthread_create (%d)", i);
+    }
+
+  for (i = 0; i < THREADS; i ++)
+    {
+      void *ret;
+
+      err = pthread_join (tid[i], &ret);
+      if (err)
+	error (1, err, "pthread_join");
+
+      assert (ret == 0);
+    }
+
+  return 0;
+}
diff --git a/htl/tests/test-8.c b/htl/tests/test-8.c
new file mode 100644
index 0000000..85a7f8f
--- /dev/null
+++ b/htl/tests/test-8.c
@@ -0,0 +1,60 @@
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+
+#define THREADS 10
+
+pthread_once_t inc_var_once = PTHREAD_ONCE_INIT;
+int var;
+
+void
+inc_var (void)
+{
+  var ++;
+}
+
+void *
+thr (void *arg)
+{
+  int i;
+
+  for (i = 0; i < 500; i ++)
+    pthread_once (&inc_var_once, inc_var);
+
+  return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+  error_t err;
+  int i;
+  pthread_t tid[THREADS];
+
+  for (i = 0; i < THREADS; i ++)
+    {
+      err = pthread_create (&tid[i], 0, thr, 0);
+      if (err)
+	error (1, err, "pthread_create (%d)", i);
+    }
+
+  assert (thr (0) == 0);
+
+  for (i = 0; i < THREADS; i ++)
+    {
+      void *ret;
+
+      err = pthread_join (tid[i], &ret);
+      if (err)
+	error (1, err, "pthread_join");
+
+      assert (ret == 0);
+    }
+
+  assert (var == 1);
+
+  return 0;
+}
diff --git a/htl/tests/test-9.c b/htl/tests/test-9.c
new file mode 100644
index 0000000..8205157
--- /dev/null
+++ b/htl/tests/test-9.c
@@ -0,0 +1,88 @@
+/* Test recursive mutexes.  */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+
+#define THREADS 10
+
+int foo;
+
+void *
+thr (void *arg)
+{
+  int i;
+
+  pthread_mutex_lock (arg);
+
+  foo = pthread_self ();
+
+  for (i = 0; i < 500; i ++)
+    pthread_mutex_lock (arg);
+  for (i = 0; i < 500; i ++)
+    pthread_mutex_unlock (arg);
+
+  assert (foo == pthread_self ());
+
+  pthread_mutex_unlock (arg);
+
+  return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+  error_t err;
+  int i;
+  pthread_t tid[THREADS];
+  pthread_mutexattr_t mattr;
+  pthread_mutex_t mutex;
+
+  err = pthread_mutexattr_init (&mattr);
+  if (err)
+    error (1, err, "pthread_mutexattr_init");
+
+  err = pthread_mutexattr_settype (&mattr, PTHREAD_MUTEX_RECURSIVE);
+  if (err)
+    error (1, err, "pthread_mutexattr_settype");
+
+  err = pthread_mutex_init (&mutex, &mattr);
+  if (err)
+    error (1, err, "pthread_mutex_init");
+
+  err = pthread_mutexattr_destroy (&mattr);
+  if (err)
+    error (1, err, "pthread_mutexattr_destroy");
+
+  pthread_mutex_lock (&mutex);
+  pthread_mutex_lock (&mutex);
+  pthread_mutex_unlock (&mutex);
+  pthread_mutex_unlock (&mutex);
+
+  for (i = 0; i < THREADS; i ++)
+    {
+      err = pthread_create (&tid[i], 0, thr, &mutex);
+      if (err)
+	error (1, err, "pthread_create (%d)", i);
+    }
+
+  for (i = 0; i < THREADS; i ++)
+    {
+      void *ret;
+
+      err = pthread_join (tid[i], &ret);
+      if (err)
+	error (1, err, "pthread_join");
+
+      assert (ret == 0);
+    }
+
+  err = pthread_mutex_destroy (&mutex);
+  if (err)
+    error (1, err, "pthread_mutex_destroy");
+
+  return 0;
+}
diff --git a/htl/tests/test-__pthread_destroy_specific-skip.c b/htl/tests/test-__pthread_destroy_specific-skip.c
new file mode 100644
index 0000000..b2c4c0b
--- /dev/null
+++ b/htl/tests/test-__pthread_destroy_specific-skip.c
@@ -0,0 +1,83 @@
+/* Check that __pthread_destroy_specific works correctly if it has to skip
+   unused slots.  */
+
+#define _GNU_SOURCE
+
+#include <error.h>
+#include <pthread.h>
+#include <stdio.h>
+
+
+#define N_k 42
+
+static volatile int v;
+
+static void
+d (void *x)
+{
+  int *i = (int *) x;
+
+  if (v != *i)
+    error (1, 0, "FAILED %d %d", v, *i);
+  v += 2;
+
+  printf ("%s %d\n", __FUNCTION__, *i);
+  fflush (stdout);
+}
+
+static void *
+test (void *x)
+{
+  pthread_key_t k[N_k];
+  static int k_v[N_k];
+
+  int err, i;
+
+  for (i = 0; i < N_k; i += 1)
+    {
+      err = pthread_key_create (&k[i], &d);
+      if (err != 0)
+        error (1, err, "pthread_key_create %d", i);
+    }
+
+  for (i = 0; i < N_k; i += 1)
+    {
+      k_v[i] = i;
+      err = pthread_setspecific (k[i], &k_v[i]);
+      if (err != 0)
+        error (1, err, "pthread_setspecific %d", i);
+    }
+
+  /* Delete every even key.  */
+  for (i = 0; i < N_k; i += 2)
+    {
+      err = pthread_key_delete (k[i]);
+      if (err != 0)
+        error (1, err, "pthread_key_delete %d", i);
+    }
+
+  v = 1;
+  pthread_exit (NULL);
+
+  return NULL;
+}
+
+
+int main(void)
+{
+  pthread_t tid;
+  int err;
+
+  err = pthread_create (&tid, 0, test, NULL);
+  if (err != 0)
+    error (1, err, "pthread_create");
+
+  err = pthread_join(tid, NULL);
+  if (err)
+    error (1, err, "pthread_join");
+
+  if (v != N_k + 1)
+    error (1, 0, "FAILED END %d %d", v, N_k + 1);
+
+  return 0;
+}

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=e6aedfe2aab055fdba3af4480096ea86f3620f34

commit e6aedfe2aab055fdba3af4480096ea86f3620f34
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Wed Jan 24 02:09:41 2018 +0100

    t/gnumach
    
    Build stubs for new gnumach.defs
    
    * mach/Makefile (user-interfaces): Add mach/gnumach.
    * sysdeps/mach/configure.ac (mach_interface_list): Add gnumach.
    * sysdeps/mach/configure (mach_interface_list): Regenerate.
    
    Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

diff --git a/mach/Makefile b/mach/Makefile
index 6d068b3..0d65249 100644
--- a/mach/Makefile
+++ b/mach/Makefile
@@ -116,7 +116,7 @@ ifndef mach-shortcuts
 # $(mach-shortcuts) will be set, and that will change how
 # mach_interface.defs is processed: it will get the -D flags below.
 user-interfaces := $(filter-out $(mach-interface-list:%=mach/%) \
-				mach/mach_port mach/mach_host mach/mach4 \
+				mach/mach_port mach/mach_host mach/mach4 mach/gnumach \
 				device/device_request,\
 				$(user-interfaces))
 endif
diff --git a/sysdeps/mach/configure b/sysdeps/mach/configure
index 632a9c9..c6ea9be 100644
--- a/sysdeps/mach/configure
+++ b/sysdeps/mach/configure
@@ -282,7 +282,7 @@ if test $libc_cv_mach_task_creation_time = no; then
 fi
 
 mach_interface_list=
-for ifc in mach mach4 \
+for ifc in mach mach4 gnumach \
 	   clock clock_priv host_priv host_security ledger lock_set \
 	   processor processor_set task task_notify thread_act vm_map \
 	   memory_object memory_object_default default_pager \
diff --git a/sysdeps/mach/configure.ac b/sysdeps/mach/configure.ac
index 3033fec..cadecae 100644
--- a/sysdeps/mach/configure.ac
+++ b/sysdeps/mach/configure.ac
@@ -59,7 +59,7 @@ dnl but we don't do a check for that here because in a bare
 dnl environment the compile against those headers will fail.
 dnl
 mach_interface_list=
-for ifc in mach mach4 \
+for ifc in mach mach4 gnumach \
 	   clock clock_priv host_priv host_security ledger lock_set \
 	   processor processor_set task task_notify thread_act vm_map \
 	   memory_object memory_object_default default_pager \

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=54e99e2c372d3514d7554be8943c51febb92cc79

commit 54e99e2c372d3514d7554be8943c51febb92cc79
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Wed Jan 24 01:56:34 2018 +0100

    Really import t/extern_inline

diff --git a/hurd/hurd.h b/hurd/hurd.h
index 7cf23b5..5b2e7a8 100644
--- a/hurd/hurd.h
+++ b/hurd/hurd.h
@@ -46,6 +46,9 @@
 #define _HURD_H_EXTERN_INLINE __extern_inline
 #endif
 
+int __hurd_fail (error_t err);
+
+#ifdef __USE_EXTERN_INLINES
 _HURD_H_EXTERN_INLINE int
 __hurd_fail (error_t err)
 {
@@ -75,6 +78,7 @@ __hurd_fail (error_t err)
   errno = err;
   return -1;
 }
+#endif
 
 /* Basic ports and info, initialized by startup.  */
 
diff --git a/hurd/hurd/fd.h b/hurd/hurd/fd.h
index 809a73f..8d95265 100644
--- a/hurd/hurd/fd.h
+++ b/hurd/hurd/fd.h
@@ -59,6 +59,10 @@ extern struct mutex _hurd_dtable_lock; /* Locks those two variables.  */
    NULL.  The cell is unlocked; when ready to use it, lock it and check for
    it being unused.  */
 
+struct hurd_fd *_hurd_fd_get (int fd);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+#  if IS_IN (libc)
 _HURD_FD_H_EXTERN_INLINE struct hurd_fd *
 _hurd_fd_get (int fd)
 {
@@ -91,6 +95,8 @@ _hurd_fd_get (int fd)
 
   return descriptor;
 }
+#  endif
+#endif
 
 
 /* Evaluate EXPR with the variable `descriptor' bound to a pointer to the
@@ -138,6 +144,9 @@ _hurd_fd_get (int fd)
 /* Check if ERR should generate a signal.
    Returns the signal to take, or zero if none.  */
 
+int _hurd_fd_error_signal (error_t err);
+
+#ifdef __USE_EXTERN_INLINES
 _HURD_FD_H_EXTERN_INLINE int
 _hurd_fd_error_signal (error_t err)
 {
@@ -154,11 +163,15 @@ _hurd_fd_error_signal (error_t err)
       return 0;
     }
 }
+#endif
 
 /* Handle an error from an RPC on a file descriptor's port.  You should
    always use this function to handle errors from RPCs made on file
    descriptor ports.  Some errors are translated into signals.  */
 
+error_t _hurd_fd_error (int fd, error_t err);
+
+#ifdef __USE_EXTERN_INLINES
 _HURD_FD_H_EXTERN_INLINE error_t
 _hurd_fd_error (int fd, error_t err)
 {
@@ -171,20 +184,28 @@ _hurd_fd_error (int fd, error_t err)
     }
   return err;
 }
+#endif
 
 /* Handle error code ERR from an RPC on file descriptor FD's port.
    Set `errno' to the appropriate error code, and always return -1.  */
 
+int __hurd_dfail (int fd, error_t err);
+
+#ifdef __USE_EXTERN_INLINES
 _HURD_FD_H_EXTERN_INLINE int
 __hurd_dfail (int fd, error_t err)
 {
   errno = _hurd_fd_error (fd, err);
   return -1;
 }
+#endif
 
 /* Likewise, but do not raise SIGPIPE on EPIPE if flags contain
    MSG_NOSIGNAL.  */
 
+int __hurd_sockfail (int fd, int flags, error_t err);
+
+#ifdef __USE_EXTERN_INLINES
 _HURD_FD_H_EXTERN_INLINE int
 __hurd_sockfail (int fd, int flags, error_t err)
 {
@@ -193,6 +214,7 @@ __hurd_sockfail (int fd, int flags, error_t err)
   errno = err;
   return -1;
 }
+#endif
 
 /* Set up *FD to have PORT its server port, doing appropriate ctty magic.
    Does no locking or unlocking.  */
@@ -258,6 +280,8 @@ extern int _hurd_select (int nfds, struct pollfd *pollfds,
 /* Apply AT_FLAGS on FLAGS, in preparation for calling
    __hurd_file_name_lookup.  */
 
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+#  if IS_IN (libc)
 _HURD_FD_H_EXTERN_INLINE error_t
 __hurd_at_flags (int *at_flags, int *flags)
 {
@@ -274,6 +298,8 @@ __hurd_at_flags (int *at_flags, int *flags)
 
   return 0;
 }
+#  endif
+#endif
 
 /* Variant of file_name_lookup used in *at function implementations.
    AT_FLAGS may only contain AT_SYMLINK_FOLLOW or AT_SYMLINK_NOFOLLOW,
diff --git a/hurd/hurd/port.h b/hurd/hurd/port.h
index 78053e6..c1a899b 100644
--- a/hurd/hurd/port.h
+++ b/hurd/hurd/port.h
@@ -60,6 +60,10 @@ struct hurd_port
 
 /* Initialize *PORT to INIT.  */
 
+void _hurd_port_init (struct hurd_port *port, mach_port_t init);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+#  if IS_IN (libc)
 _HURD_PORT_H_EXTERN_INLINE void
 _hurd_port_init (struct hurd_port *port, mach_port_t init)
 {
@@ -67,6 +71,8 @@ _hurd_port_init (struct hurd_port *port, mach_port_t init)
   port->users = NULL;
   port->port = init;
 }
+#  endif
+#endif
 
 
 /* Cleanup function for non-local exits.  */
@@ -75,6 +81,12 @@ extern void _hurd_port_cleanup (void *, jmp_buf, int);
 /* Get a reference to *PORT, which is locked.
    Pass return value and LINK to _hurd_port_free when done.  */
 
+mach_port_t
+_hurd_port_locked_get (struct hurd_port *port,
+		       struct hurd_userlink *link);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+#  if IS_IN (libc)
 _HURD_PORT_H_EXTERN_INLINE mach_port_t
 _hurd_port_locked_get (struct hurd_port *port,
 		       struct hurd_userlink *link)
@@ -90,9 +102,17 @@ _hurd_port_locked_get (struct hurd_port *port,
   __spin_unlock (&port->lock);
   return result;
 }
+#  endif
+#endif
 
 /* Same, but locks PORT first.  */
 
+mach_port_t
+_hurd_port_get (struct hurd_port *port,
+		struct hurd_userlink *link);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+#  if IS_IN (libc)
 _HURD_PORT_H_EXTERN_INLINE mach_port_t
 _hurd_port_get (struct hurd_port *port,
 		struct hurd_userlink *link)
@@ -104,10 +124,19 @@ _hurd_port_get (struct hurd_port *port,
   HURD_CRITICAL_END;
   return result;
 }
+#  endif
+#endif
 
 
 /* Free a reference gotten with `USED_PORT = _hurd_port_get (PORT, LINK);' */
 
+void
+_hurd_port_free (struct hurd_port *port,
+		 struct hurd_userlink *link,
+		 mach_port_t used_port);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+#  if IS_IN (libc)
 _HURD_PORT_H_EXTERN_INLINE void
 _hurd_port_free (struct hurd_port *port,
 		 struct hurd_userlink *link,
@@ -127,11 +156,17 @@ _hurd_port_free (struct hurd_port *port,
   if (dealloc)
     __mach_port_deallocate (__mach_task_self (), used_port);
 }
+#  endif
+#endif
 
 
 /* Set *PORT's port to NEWPORT.  NEWPORT's reference is consumed by PORT->port.
    PORT->lock is locked.  */
 
+void _hurd_port_locked_set (struct hurd_port *port, mach_port_t newport);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+#  if IS_IN (libc)
 _HURD_PORT_H_EXTERN_INLINE void
 _hurd_port_locked_set (struct hurd_port *port, mach_port_t newport)
 {
@@ -142,9 +177,15 @@ _hurd_port_locked_set (struct hurd_port *port, mach_port_t newport)
   if (old != MACH_PORT_NULL)
     __mach_port_deallocate (__mach_task_self (), old);
 }
+#  endif
+#endif
 
 /* Same, but locks PORT first.  */
 
+void _hurd_port_set (struct hurd_port *port, mach_port_t newport);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+#  if IS_IN (libc)
 _HURD_PORT_H_EXTERN_INLINE void
 _hurd_port_set (struct hurd_port *port, mach_port_t newport)
 {
@@ -153,6 +194,8 @@ _hurd_port_set (struct hurd_port *port, mach_port_t newport)
   _hurd_port_locked_set (port, newport);
   HURD_CRITICAL_END;
 }
+#  endif
+#endif
 
 
 #endif	/* hurd/port.h */
diff --git a/hurd/hurd/signal.h b/hurd/hurd/signal.h
index e7d3654..b0911ae 100644
--- a/hurd/hurd/signal.h
+++ b/hurd/hurd/signal.h
@@ -133,6 +133,8 @@ extern struct hurd_sigstate *_hurd_self_sigstate (void)
 #define _HURD_SIGNAL_H_EXTERN_INLINE __extern_inline
 #endif
 
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+#  if IS_IN (libc)
 _HURD_SIGNAL_H_EXTERN_INLINE struct hurd_sigstate *
 _hurd_self_sigstate (void)
 {
@@ -140,6 +142,8 @@ _hurd_self_sigstate (void)
     THREAD_SELF->_hurd_sigstate = _hurd_thread_sigstate (__mach_thread_self ());
   return THREAD_SELF->_hurd_sigstate;
 }
+#  endif
+#endif
 
 /* Thread listening on our message port; also called the "signal thread".  */
 
@@ -166,6 +170,10 @@ extern int _hurd_core_limit;
    interrupted lest the signal handler try to take the same lock and
    deadlock result.  */
 
+void *_hurd_critical_section_lock (void);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+#  if IS_IN (libc)
 _HURD_SIGNAL_H_EXTERN_INLINE void *
 _hurd_critical_section_lock (void)
 {
@@ -196,7 +204,13 @@ _hurd_critical_section_lock (void)
      _hurd_critical_section_unlock to unlock it.  */
   return ss;
 }
+#  endif
+#endif
+
+void _hurd_critical_section_unlock (void *our_lock);
 
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+#  if IS_IN (libc)
 _HURD_SIGNAL_H_EXTERN_INLINE void
 _hurd_critical_section_unlock (void *our_lock)
 {
@@ -219,6 +233,8 @@ _hurd_critical_section_unlock (void *our_lock)
 	__msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ());
     }
 }
+#  endif
+#endif
 
 /* Convenient macros for simple uses of critical sections.
    These two must be used as a pair at the same C scoping level.  */
diff --git a/hurd/hurd/userlink.h b/hurd/hurd/userlink.h
index 6acfaa8..77f92f4 100644
--- a/hurd/hurd/userlink.h
+++ b/hurd/hurd/userlink.h
@@ -76,6 +76,12 @@ struct hurd_userlink
 
 /* Attach LINK to the chain of users at *CHAINP.  */
 
+void
+_hurd_userlink_link (struct hurd_userlink **chainp,
+		     struct hurd_userlink *link);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+#  if IS_IN (libc)
 _HURD_USERLINK_H_EXTERN_INLINE void
 _hurd_userlink_link (struct hurd_userlink **chainp,
 		     struct hurd_userlink *link)
@@ -96,11 +102,17 @@ _hurd_userlink_link (struct hurd_userlink **chainp,
   link->thread.prevp = thread_chainp;
   *thread_chainp = link;
 }
+#  endif
+#endif
 
 
 /* Detach LINK from its chain.  Returns nonzero iff this was the
    last user of the resource and it should be deallocated.  */
 
+int _hurd_userlink_unlink (struct hurd_userlink *link);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+#  if IS_IN (libc)
 _HURD_USERLINK_H_EXTERN_INLINE int
 _hurd_userlink_unlink (struct hurd_userlink *link)
 {
@@ -123,6 +135,8 @@ _hurd_userlink_unlink (struct hurd_userlink *link)
 
   return dealloc;
 }
+#  endif
+#endif
 
 
 /* Clear all users from *CHAINP.  Call this when the resource *CHAINP
@@ -131,6 +145,10 @@ _hurd_userlink_unlink (struct hurd_userlink *link)
    value is zero, someone is still using the resource and they will
    deallocate it when they are finished.  */
 
+int _hurd_userlink_clear (struct hurd_userlink **chainp);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+#  if IS_IN (libc)
 _HURD_USERLINK_H_EXTERN_INLINE int
 _hurd_userlink_clear (struct hurd_userlink **chainp)
 {
@@ -143,5 +161,7 @@ _hurd_userlink_clear (struct hurd_userlink **chainp)
   *chainp = NULL;
   return 0;
 }
+#  endif
+#endif
 
 #endif	/* hurd/userlink.h */
diff --git a/mach/mach/mig_support.h b/mach/mach/mig_support.h
index e876c09..56ec6df 100644
--- a/mach/mach/mig_support.h
+++ b/mach/mach/mig_support.h
@@ -66,6 +66,8 @@ extern void mig_reply_setup (const mach_msg_header_t *__request,
 /* Idiocy support function.  */
 extern vm_size_t mig_strncpy (char *__dst, const char *__src, vm_size_t __len);
 extern vm_size_t __mig_strncpy (char *__dst, const char *__src, vm_size_t);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
 __extern_inline vm_size_t
 __mig_strncpy (char *__dst, const char *__src, vm_size_t __len)
 {
@@ -76,6 +78,7 @@ mig_strncpy (char *__dst, const char *__src, vm_size_t __len)
 {
   return __mig_strncpy (__dst, __src, __len);
 }
+#endif
 
 
 
diff --git a/mach/spin-lock.c b/mach/spin-lock.c
index aaebc55..1b1e69c 100644
--- a/mach/spin-lock.c
+++ b/mach/spin-lock.c
@@ -1,3 +1,4 @@
+#define __USE_EXTERN_INLINES 1
 #define _EXTERN_INLINE /* Empty to define the real functions.  */
 #include "spin-lock.h"
 
diff --git a/sysdeps/generic/machine-lock.h b/sysdeps/generic/machine-lock.h
index 4aa2287..c518c0f 100644
--- a/sysdeps/generic/machine-lock.h
+++ b/sysdeps/generic/machine-lock.h
@@ -34,14 +34,21 @@ typedef volatile int __spin_lock_t;
 
 /* Unlock LOCK.  */
 
+void __spin_unlock (__spin_lock_t *__lock);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
 _EXTERN_INLINE void
 __spin_unlock (__spin_lock_t *__lock)
 {
   *__lock = 0;
 }
+#endif
 
 /* Try to lock LOCK; return nonzero if we locked it, zero if another has.  */
 
+int __spin_try_lock (__spin_lock_t *__lock);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
 _EXTERN_INLINE int
 __spin_try_lock (__spin_lock_t *__lock)
 {
@@ -50,14 +57,19 @@ __spin_try_lock (__spin_lock_t *__lock)
   *__lock = 1;
   return 1;
 }
+#endif
 
 /* Return nonzero if LOCK is locked.  */
 
+int __spin_lock_locked (__spin_lock_t *__lock);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
 _EXTERN_INLINE int
 __spin_lock_locked (__spin_lock_t *__lock)
 {
   return *__lock != 0;
 }
+#endif
 
 
 #endif /* machine-lock.h */
diff --git a/sysdeps/generic/machine-sp.h b/sysdeps/generic/machine-sp.h
index dc56ce4..94a89d9 100644
--- a/sysdeps/generic/machine-sp.h
+++ b/sysdeps/generic/machine-sp.h
@@ -25,11 +25,15 @@
 #define _EXTERN_INLINE __extern_inline
 #endif
 
+void * __thread_stack_pointer (void);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
 _EXTERN_INLINE void *
 __thread_stack_pointer (void)
 {
   register void *__sp__ ("{STACK-POINTER}");
   return __sp__;
 }
+#endif
 
 #endif	/* machine-sp.h */
diff --git a/sysdeps/mach/i386/machine-lock.h b/sysdeps/mach/i386/machine-lock.h
index 8a6a9ee..5ba4781 100644
--- a/sysdeps/mach/i386/machine-lock.h
+++ b/sysdeps/mach/i386/machine-lock.h
@@ -34,6 +34,9 @@ typedef volatile int __spin_lock_t;
 
 /* Unlock LOCK.  */
 
+void __spin_unlock (__spin_lock_t *__lock);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
 _EXTERN_INLINE void
 __spin_unlock (__spin_lock_t *__lock)
 {
@@ -42,9 +45,13 @@ __spin_unlock (__spin_lock_t *__lock)
 		       : "=&r" (__unlocked), "=m" (*__lock) : "0" (0)
 		       : "memory");
 }
+#endif
 
 /* Try to lock LOCK; return nonzero if we locked it, zero if another has.  */
 
+int __spin_try_lock (__spin_lock_t *__lock);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
 _EXTERN_INLINE int
 __spin_try_lock (__spin_lock_t *__lock)
 {
@@ -54,14 +61,19 @@ __spin_try_lock (__spin_lock_t *__lock)
 		      : "memory");
   return !__locked;
 }
+#endif
 
 /* Return nonzero if LOCK is locked.  */
 
+int __spin_lock_locked (__spin_lock_t *__lock);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
 _EXTERN_INLINE int
 __spin_lock_locked (__spin_lock_t *__lock)
 {
   return *__lock != 0;
 }
+#endif
 
 
 #endif /* machine-lock.h */

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=3fb802eba59680cea651ca40ef20487545551e76

commit 3fb802eba59680cea651ca40ef20487545551e76
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Wed Jan 24 00:04:16 2018 +0100

    fix prototype

diff --git a/mach/lock-intern.h b/mach/lock-intern.h
index 1542bcd..9a51837 100644
--- a/mach/lock-intern.h
+++ b/mach/lock-intern.h
@@ -35,7 +35,7 @@ typedef unsigned int __spin_lock_t;
 
 /* Initialize LOCK.  */
 
-void __spin_lock_init (__spin_lock_t *__lock)
+void __spin_lock_init (__spin_lock_t *__lock);
 
 #if defined __USE_EXTERN_INLINES && defined _LIBC
 _EXTERN_INLINE void

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=0cab338523e3213e83462de2270b413928c6a180

commit 0cab338523e3213e83462de2270b413928c6a180
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Wed Jan 24 00:04:16 2018 +0100

    fix prototypes

diff --git a/mach/lock-intern.h b/mach/lock-intern.h
index 3e9fc99..1542bcd 100644
--- a/mach/lock-intern.h
+++ b/mach/lock-intern.h
@@ -48,7 +48,7 @@ __spin_lock_init (__spin_lock_t *__lock)
 
 /* Lock the spin lock LOCK.  */
 
-void __spin_lock (__spin_lock_t *__lock)
+void __spin_lock (__spin_lock_t *__lock);
 
 #if defined __USE_EXTERN_INLINES && defined _LIBC
 _EXTERN_INLINE void
@@ -98,7 +98,7 @@ extern void __mutex_init (void *__lock);
 
 /* Lock the mutex lock LOCK.  */
 
-void __mutex_lock (void *__lock)
+void __mutex_lock (void *__lock);
 
 #if defined __USE_EXTERN_INLINES && defined _LIBC
 _EXTERN_INLINE void
@@ -110,7 +110,7 @@ __mutex_lock (void *__lock)
 
 /* Unlock the mutex lock LOCK.  */
 
-void __mutex_unlock (void *__lock)
+void __mutex_unlock (void *__lock);
 
 #if defined __USE_EXTERN_INLINES && defined _LIBC
 _EXTERN_INLINE void
@@ -121,7 +121,7 @@ __mutex_unlock (void *__lock)
 #endif
 
 
-int __mutex_trylock (void *__lock)
+int __mutex_trylock (void *__lock);
 
 #if defined __USE_EXTERN_INLINES && defined _LIBC
 _EXTERN_INLINE int

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=f89adbfd4ef825d39a6197500c193be220d45f9a

commit f89adbfd4ef825d39a6197500c193be220d45f9a
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Tue Jan 23 22:59:11 2018 +0100

    Add missing hooks from t/extern_inline

diff --git a/mach/lock-intern.h b/mach/lock-intern.h
index 34175f5..3e9fc99 100644
--- a/mach/lock-intern.h
+++ b/mach/lock-intern.h
@@ -35,20 +35,28 @@ typedef unsigned int __spin_lock_t;
 
 /* Initialize LOCK.  */
 
+void __spin_lock_init (__spin_lock_t *__lock)
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
 _EXTERN_INLINE void
 __spin_lock_init (__spin_lock_t *__lock)
 {
   *__lock = LLL_INITIALIZER;
 }
+#endif
 
 
 /* Lock the spin lock LOCK.  */
 
+void __spin_lock (__spin_lock_t *__lock)
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
 _EXTERN_INLINE void
 __spin_lock (__spin_lock_t *__lock)
 {
   lll_lock (__lock, 0);
 }
+#endif
 
 /* Unlock LOCK. */
 void __spin_unlock (__spin_lock_t *__lock);
@@ -90,25 +98,37 @@ extern void __mutex_init (void *__lock);
 
 /* Lock the mutex lock LOCK.  */
 
+void __mutex_lock (void *__lock)
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
 _EXTERN_INLINE void
 __mutex_lock (void *__lock)
 {
   __spin_lock ((__spin_lock_t *)__lock);
 }
+#endif
 
 /* Unlock the mutex lock LOCK.  */
 
+void __mutex_unlock (void *__lock)
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
 _EXTERN_INLINE void
 __mutex_unlock (void *__lock)
 {
   __spin_unlock ((__spin_lock_t *)__lock);
 }
+#endif
 
 
+int __mutex_trylock (void *__lock)
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
 _EXTERN_INLINE int
 __mutex_trylock (void *__lock)
 {
   return (__spin_try_lock ((__spin_lock_t *)__lock));
 }
+#endif
 
 #endif /* lock-intern.h */

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=bcbe87e4404a8b05c46e794573f0420e41e79371

commit bcbe87e4404a8b05c46e794573f0420e41e79371
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Mon Jan 22 01:19:36 2018 +0100

    Update from t/gsync-libc

diff --git a/sysdeps/mach/Makefile b/sysdeps/mach/Makefile
index 95b83d8..2fa6698 100644
--- a/sysdeps/mach/Makefile
+++ b/sysdeps/mach/Makefile
@@ -62,6 +62,7 @@ else ifeq (nis,$(subdir))
 else ifeq (nss,$(subdir))
   LDLIBS-nss.so += $(objdir)/mach/libmachuser.so
   LDLIBS-nss_files.so += $(objdir)/mach/libmachuser.so
+  LDLIBS-nss_db.so += $(objdir)/mach/libmachuser.so
   LDLIBS-nss_compat.so += $(objdir)/mach/libmachuser.so
 else ifeq (hesiod,$(subdir))
   LDLIBS-nss_hesiod.so += $(objdir)/mach/libmachuser.so

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=473cc8a984531495bfd6975bd7ac3f5f0bfa7a83

commit 473cc8a984531495bfd6975bd7ac3f5f0bfa7a83
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Sun Jan 21 21:51:47 2018 +0100

    Update t2.26/sigsetops.h

diff --git a/hurd/hurd/signal.h b/hurd/hurd/signal.h
index 0e6a969..e7d3654 100644
--- a/hurd/hurd/signal.h
+++ b/hurd/hurd/signal.h
@@ -42,7 +42,7 @@
 #include <spin-lock.h>
 struct hurd_signal_preemptor;	/* <hurd/sigpreempt.h> */
 #if defined __USE_EXTERN_INLINES && defined _LIBC
-#  if IS_IN (libc)
+#  if IS_IN (libc) || IS_IN (libpthread)
 #    include <sigsetops.h>
 #  endif
 #endif

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=c638d6d41567fc693e16f5ef8a575f7d76193038

commit c638d6d41567fc693e16f5ef8a575f7d76193038
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Fri Jan 19 03:00:07 2018 +0100

    Add missing bit for t/gsync-libc

diff --git a/manual/errno.texi b/manual/errno.texi
index 73272fd..8917ccc 100644
--- a/manual/errno.texi
+++ b/manual/errno.texi
@@ -882,6 +882,16 @@ the normal result is for the operations affected to complete with this
 error; @pxref{Cancel AIO Operations}.
 @end deftypevr
 
+@deftypevr Macro int EOWNERDEAD
+@standards{GNU, errno.h}
+@errno{EOWNERDEAD, 120, Owner died}
+@end deftypevr
+
+@deftypevr Macro int ENOTRECOVERABLE
+@standards{GNU, errno.h}
+@errno{ENOTRECOVERABLE, 121, State not recoverable}
+@end deftypevr
+
 
 @emph{The following error codes are defined by the Linux/i386 kernel.
 They are not yet documented.}

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=3919602699bdddbe93107a48a147b2b24b8ebf82

commit 3919602699bdddbe93107a48a147b2b24b8ebf82
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Fri Jan 19 02:26:28 2018 +0100

    t/gsync-libc
    From: Agustina Arzille <avarzille@riseup.net>
    Subject: [PATCH] Introduce gsync-based locks to glibc.
    
    * hurd/Makefile: Add hurdlock.
    * hurd/Versions: Added new entry to export the above interface.
    * hurd/hurdlock.c: New file.
    * hurd/hurdlock.h: New file.
    * hurd/hurdpid.c: Include <lowlevellock.h>
      (_S_msg_proc_newids): Use lll_wait to synchronize.
    * hurd/hurdsig.c: (reauth_proc): Use __mutex_lock and __mutex_unlock.
    * hurd/setauth.c: Include <hurdlock.h>, use integer for synchronization.
    * hurd/sysvshm.c: Include <hurdlock.h>, use integer for synchronization.
    * mach/Makefile: Remove unneeded file
    * mach/lock-intern.h: Use lll to implement spinlocks.
    * mach/lowlevellock.h: New file
    * mach/mutex-init.c: Rewrite mutex initialization.
    * sysdeps/mach/Makefile: Add libmachuser as dependencies for some libs.
    * sysdeps/mach/libc-lock.h: Reimplemented libc internal locks
      with lll, cleanup routines now use gcc's cleanup attribute
    * sysdeps/mach/hurd/bits/errno.h: New errno values.
    * sysdeps/mach/hurd/libc-lock.h: Removed file.
    * sysdeps/mach/hurd/malloc-machine.h: Reimplemented malloc locks.
    * sysdeps/mach/hurd/setpgid.c: (setpgid): Use gsync for synchronization.
    * sysdeps/mach/hurd/setsid.c: (setsid): Likewise.
    
    t/libc_cleanup
    From: Agustina Arzille <avarzille@riseup.net>
    Subject: [PATCH] Use gcc's cleanup attributes
    
    cleanup routines now use gcc's cleanup attribute

diff --git a/hurd/Makefile b/hurd/Makefile
index f71dc36..fbb2f5c 100644
--- a/hurd/Makefile
+++ b/hurd/Makefile
@@ -54,6 +54,7 @@ routines = hurdstartup hurdinit \
 	   vpprintf \
 	   ports-get ports-set hurdports hurdmsg \
 	   errno-loc \
+	   hurdlock \
 	   $(sig) $(dtable) $(inlines) port-cleanup report-wait xattr
 sig	= hurdsig hurdfault siginfo hurd-raise preempt-sig \
 	  trampoline longjmp-ts catch-exc exc2signal hurdkill sigunwind \
diff --git a/hurd/Versions b/hurd/Versions
index 6db2a9c..fe20020 100644
--- a/hurd/Versions
+++ b/hurd/Versions
@@ -147,4 +147,12 @@ libc {
     cthread_keycreate; cthread_getspecific; cthread_setspecific;
     __libc_getspecific;
   }
+
+  GLIBC_PRIVATE {
+    # Used by other libs.
+    __lll_abstimed_wait; __lll_abstimed_xwait;
+    __lll_abstimed_lock; __lll_robust_lock;
+    __lll_robust_abstimed_lock; __lll_robust_trylock;
+    __lll_robust_unlock;
+  }
 }
diff --git a/hurd/hurdlock.c b/hurd/hurdlock.c
new file mode 100644
index 0000000..6ab180e
--- /dev/null
+++ b/hurd/hurdlock.c
@@ -0,0 +1,215 @@
+/* Copyright (C) 1999-2017 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include "hurdlock.h"
+#include <hurd.h>
+#include <time.h>
+#include <errno.h>
+
+/* Convert an absolute timeout in nanoseconds to a relative
+ * timeout in milliseconds. */
+static inline int __attribute__ ((gnu_inline))
+compute_reltime (const struct timespec *abstime, clockid_t clk)
+{
+  struct timespec ts;
+  __clock_gettime (clk, &ts);
+
+  ts.tv_sec = abstime->tv_sec - ts.tv_sec;
+  ts.tv_nsec = abstime->tv_nsec - ts.tv_nsec;
+
+  if (ts.tv_nsec < 0)
+    {
+      --ts.tv_sec;
+      ts.tv_nsec += 1000000000;
+    }
+
+  return (ts.tv_sec < 0 ? -1 :
+    (int)(ts.tv_sec * 1000 + ts.tv_nsec / 1000000));
+}
+
+int __lll_abstimed_wait (void *ptr, int val,
+  const struct timespec *tsp, int flags, int clk)
+{
+  int mlsec = compute_reltime (tsp, clk);
+  return (mlsec < 0 ? KERN_TIMEDOUT :
+    lll_timed_wait (ptr, val, mlsec, flags));
+}
+
+int __lll_abstimed_xwait (void *ptr, int lo, int hi,
+  const struct timespec *tsp, int flags, int clk)
+{
+  int mlsec = compute_reltime (tsp, clk);
+  return (mlsec < 0 ? KERN_TIMEDOUT :
+    lll_timed_xwait (ptr, lo, hi, mlsec, flags));
+}
+
+int __lll_abstimed_lock (void *ptr,
+  const struct timespec *tsp, int flags, int clk)
+{
+  if (lll_trylock (ptr) == 0)
+    return (0);
+
+  while (1)
+    {
+      if (atomic_exchange_acq ((int *)ptr, 2) == 0)
+        return (0);
+      else if (tsp->tv_nsec < 0 || tsp->tv_nsec >= 1000000000)
+        return (EINVAL);
+
+      int mlsec = compute_reltime (tsp, clk);
+      if (mlsec < 0 || lll_timed_wait (ptr,
+          2, mlsec, flags) == KERN_TIMEDOUT)
+        return (ETIMEDOUT);
+    }
+}
+
+/* Robust locks. */
+
+extern int __getpid (void) __attribute__ ((const));
+extern task_t __pid2task (int);
+
+/* Test if a given process id is still valid. */
+static inline int valid_pid (int pid)
+{
+  task_t task = __pid2task (pid);
+  if (task == MACH_PORT_NULL)
+    return (0);
+
+  __mach_port_deallocate (__mach_task_self (), task);
+  return (1);
+}
+
+/* Robust locks have currently no support from the kernel; they
+ * are simply implemented with periodic polling. When sleeping, the
+ * maximum blocking time is determined by this constant. */
+#define MAX_WAIT_TIME   1500
+
+int __lll_robust_lock (void *ptr, int flags)
+{
+  int *iptr = (int *)ptr;
+  int id = __getpid ();
+  int wait_time = 25;
+  unsigned int val;
+
+  /* Try to set the lock word to our PID if it's clear. Otherwise,
+   * mark it as having waiters. */
+  while (1)
+    {
+      val = *iptr;
+      if (!val && atomic_compare_and_exchange_bool_acq (iptr, id, 0) == 0)
+        return (0);
+      else if (atomic_compare_and_exchange_bool_acq (iptr,
+          val | LLL_WAITERS, val) == 0)
+        break;
+    }
+
+  for (id |= LLL_WAITERS ; ; )
+    {
+      val = *iptr;
+      if (!val && atomic_compare_and_exchange_bool_acq (iptr, id, 0) == 0)
+        return (0);
+      else if (val && !valid_pid (val & LLL_OWNER_MASK))
+        {
+          if (atomic_compare_and_exchange_bool_acq (iptr, id, val) == 0)
+            return (EOWNERDEAD);
+        }
+      else
+        {
+          lll_timed_wait (iptr, val, wait_time, flags);
+          if (wait_time < MAX_WAIT_TIME)
+            wait_time <<= 1;
+        }
+    }
+}
+
+int __lll_robust_abstimed_lock (void *ptr,
+  const struct timespec *tsp, int flags, int clk)
+{
+  int *iptr = (int *)ptr;
+  int id = __getpid ();
+  int wait_time = 25;
+  unsigned int val;
+
+  while (1)
+    {
+      val = *iptr;
+      if (!val && atomic_compare_and_exchange_bool_acq (iptr, id, 0) == 0)
+        return (0);
+      else if (atomic_compare_and_exchange_bool_acq (iptr,
+          val | LLL_WAITERS, val) == 0)
+        break;
+    }
+
+  for (id |= LLL_WAITERS ; ; )
+    {
+      val = *iptr;
+      if (!val && atomic_compare_and_exchange_bool_acq (iptr, id, 0) == 0)
+        return (0);
+      else if (val && !valid_pid (val & LLL_OWNER_MASK))
+        {
+          if (atomic_compare_and_exchange_bool_acq (iptr, id, val) == 0)
+            return (EOWNERDEAD);
+        }
+      else
+        {
+          int mlsec = compute_reltime (tsp, clk);
+          if (mlsec < 0)
+            return (ETIMEDOUT);
+          else if (mlsec > wait_time)
+            mlsec = wait_time;
+
+          int res = lll_timed_wait (iptr, val, mlsec, flags);
+          if (res == KERN_TIMEDOUT)
+            return (ETIMEDOUT);
+          else if (wait_time < MAX_WAIT_TIME)
+            wait_time <<= 1;
+        }
+    }
+}
+
+int __lll_robust_trylock (void *ptr)
+{
+  int *iptr = (int *)ptr;
+  int id = __getpid ();
+  unsigned int val = *iptr;
+
+  if (!val)
+    {
+      if (atomic_compare_and_exchange_bool_acq (iptr, id, 0) == 0)
+        return (0);
+    }
+  else if (!valid_pid (val & LLL_OWNER_MASK) &&
+      atomic_compare_and_exchange_bool_acq (iptr, id, val) == 0)
+    return (EOWNERDEAD);
+
+  return (EBUSY);
+}
+
+void __lll_robust_unlock (void *ptr, int flags)
+{
+  unsigned int val = atomic_load_relaxed((unsigned int *)ptr);
+  while (1)
+    {
+      if (val & LLL_WAITERS)
+        {
+          lll_set_wake (ptr, 0, flags);
+          break;
+        }
+      else if (atomic_compare_exchange_weak_release ((unsigned int *)ptr, &val, 0))
+        break;
+    }
+}
diff --git a/hurd/hurdlock.h b/hurd/hurdlock.h
new file mode 100644
index 0000000..e3e7369
--- /dev/null
+++ b/hurd/hurdlock.h
@@ -0,0 +1,124 @@
+/* Copyright (C) 1999-2017 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _HURD_LOCK_H
+#define _HURD_LOCK_H   1
+
+#include <mach/lowlevellock.h>
+
+struct timespec;
+
+/* Flags for robust locks. */
+#define LLL_WAITERS      (1U << 31)
+#define LLL_DEAD_OWNER   (1U << 30)
+
+#define LLL_OWNER_MASK   ~(LLL_WAITERS | LLL_DEAD_OWNER)
+
+/* Wait on 64-bit address PTR, without blocking if its contents
+ * are different from the pair <LO, HI>. */
+#define lll_xwait(ptr, lo, hi, flags) \
+  __gsync_wait (__mach_task_self (), \
+    (vm_offset_t)ptr, lo, hi, 0, flags | GSYNC_QUAD)
+
+/* Same as 'lll_wait', but only block for MLSEC milliseconds. */
+#define lll_timed_wait(ptr, val, mlsec, flags) \
+  __gsync_wait (__mach_task_self (), \
+    (vm_offset_t)ptr, val, 0, mlsec, flags | GSYNC_TIMED)
+
+/* Same as 'lll_xwait', but only block for MLSEC milliseconds. */
+#define lll_timed_xwait(ptr, lo, hi, mlsec, flags) \
+  __gsync_wait (__mach_task_self (), (vm_offset_t)ptr, \
+    lo, hi, mlsec, flags | GSYNC_TIMED | GSYNC_QUAD)
+
+/* Same as 'lll_wait', but only block until TSP elapses,
+ * using clock CLK. */
+extern int __lll_abstimed_wait (void *__ptr, int __val,
+  const struct timespec *__tsp, int __flags, int __clk);
+
+/* Same as 'lll_xwait', but only block until TSP elapses,
+ * using clock CLK. */
+extern int __lll_abstimed_xwait (void *__ptr, int __lo, int __hi,
+  const struct timespec *__tsp, int __flags, int __clk);
+
+/* Same as 'lll_lock', but return with an error if TSP elapses,
+ * using clock CLK. */
+extern int __lll_abstimed_lock (void *__ptr,
+  const struct timespec *__tsp, int __flags, int __clk);
+
+/* Acquire the lock at PTR, but return with an error if
+ * the process containing the owner thread dies. */
+extern int __lll_robust_lock (void *__ptr, int __flags);
+
+/* Same as '__lll_robust_lock', but only block until TSP
+ * elapses, using clock CLK. */
+extern int __lll_robust_abstimed_lock (void *__ptr,
+  const struct timespec *__tsp, int __flags, int __clk);
+
+/* Same as '__lll_robust_lock', but return with an error
+ * if the lock cannot be acquired without blocking. */
+extern int __lll_robust_trylock (void *__ptr);
+
+/* Wake one or more threads waiting on address PTR,
+ * setting its value to VAL before doing so. */
+#define lll_set_wake(ptr, val, flags) \
+  __gsync_wake (__mach_task_self (), \
+    (vm_offset_t)ptr, val, flags | GSYNC_MUTATE)
+
+/* Release the robust lock at PTR. */
+extern void __lll_robust_unlock (void *__ptr, int __flags);
+
+/* Rearrange threads waiting on address SRC to instead wait on
+ * DST, waking one of them if WAIT_ONE is non-zero. */
+#define lll_requeue(src, dst, wake_one, flags) \
+  __gsync_requeue (__mach_task_self (), (vm_offset_t)src, \
+    (vm_offset_t)dst, (boolean_t)wake_one, flags)
+
+/* The following are hacks that allow us to simulate optional
+ * parameters in C, to avoid having to pass the clock id for
+ * every one of these calls, defaulting to CLOCK_REALTIME if
+ * no argument is passed. */
+
+#define lll_abstimed_wait(ptr, val, tsp, flags, ...)   \
+  ({   \
+     const clockid_t __clk[] = { CLOCK_REALTIME, ##__VA_ARGS__ };   \
+     __lll_abstimed_wait ((ptr), (val), (tsp), (flags),   \
+       __clk[sizeof (__clk) / sizeof (__clk[0]) - 1]);   \
+   })
+
+#define lll_abstimed_xwait(ptr, lo, hi, tsp, flags, ...)   \
+  ({   \
+     const clockid_t __clk[] = { CLOCK_REALTIME, ##__VA_ARGS__ };   \
+     __lll_abstimed_xwait ((ptr), (lo), (hi), (tsp), (flags),   \
+       __clk[sizeof (__clk) / sizeof (__clk[0]) - 1]);   \
+   })
+
+#define lll_abstimed_lock(ptr, tsp, flags, ...)   \
+  ({   \
+     const clockid_t __clk[] = { CLOCK_REALTIME, ##__VA_ARGS__ };   \
+     __lll_abstimed_lock ((ptr), (tsp), (flags),   \
+       __clk[sizeof (__clk) / sizeof (__clk[0]) - 1]);   \
+   })
+
+#define lll_robust_abstimed_lock(ptr, tsp, flags, ...)   \
+  ({   \
+     const clockid_t __clk[] = { CLOCK_REALTIME, ##__VA_ARGS__ };   \
+     __lll_robust_abstimed_lock ((ptr), (tsp), (flags),   \
+       __clk[sizeof (__clk) / sizeof (__clk[0]) - 1]);   \
+   })
+
+
+#endif
diff --git a/hurd/hurdpid.c b/hurd/hurdpid.c
index e1dd093..33659cc 100644
--- a/hurd/hurdpid.c
+++ b/hurd/hurdpid.c
@@ -16,6 +16,8 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <hurd.h>
+#include <lowlevellock.h>
+
 pid_t _hurd_pid, _hurd_ppid, _hurd_pgrp;
 int _hurd_orphaned;
 
@@ -66,6 +68,7 @@ _S_msg_proc_newids (mach_port_t me,
 
   /* Notify any waiting user threads that the id change as been completed.  */
   ++_hurd_pids_changed_stamp;
+  lll_wake (&_hurd_pids_changed_stamp, GSYNC_BROADCAST);
 
   return 0;
 }
diff --git a/hurd/hurdsig.c b/hurd/hurdsig.c
index e215cf1..c6b8c63 100644
--- a/hurd/hurdsig.c
+++ b/hurd/hurdsig.c
@@ -1363,14 +1363,14 @@ reauth_proc (mach_port_t new)
   __mach_port_destroy (__mach_task_self (), ref);
 
   /* Set the owner of the process here too. */
-  mutex_lock (&_hurd_id.lock);
+  __mutex_lock (&_hurd_id.lock);
   if (!_hurd_check_ids ())
     HURD_PORT_USE (&_hurd_ports[INIT_PORT_PROC],
 		   __proc_setowner (port,
 				    (_hurd_id.gen.nuids
 				     ? _hurd_id.gen.uids[0] : 0),
 				    !_hurd_id.gen.nuids));
-  mutex_unlock (&_hurd_id.lock);
+  __mutex_unlock (&_hurd_id.lock);
 
   (void) &reauth_proc;		/* Silence compiler warning.  */
 }
diff --git a/hurd/setauth.c b/hurd/setauth.c
index deece20..025be58 100644
--- a/hurd/setauth.c
+++ b/hurd/setauth.c
@@ -18,14 +18,13 @@
 #include <hurd.h>
 #include <hurd/port.h>
 #include <hurd/id.h>
+#include <hurdlock.h>
 #include "set-hooks.h"
 
 /* Things in the library which want to be run when the auth port changes.  */
 DEFINE_HOOK (_hurd_reauth_hook, (auth_t new_auth));
 
-#include <cthreads.h>
-static struct mutex reauth_lock = MUTEX_INITIALIZER;
-
+static unsigned int reauth_lock = LLL_INITIALIZER;
 
 /* Set the auth port to NEW, and reauthenticate
    everything used by the library.  */
diff --git a/mach/Makefile b/mach/Makefile
index 50047c2..6d068b3 100644
--- a/mach/Makefile
+++ b/mach/Makefile
@@ -23,7 +23,7 @@ headers = mach_init.h mach.h mach_error.h mach-shortcuts.h mach/mach_traps.h \
 	  $(interface-headers) mach/mach.h mach/mig_support.h mach/error.h \
 	  $(lock-headers) machine-sp.h
 lock = spin-solid spin-lock mutex-init mutex-solid
-lock-headers = lock-intern.h machine-lock.h spin-lock.h
+lock-headers = lock-intern.h spin-lock.h
 routines = $(mach-syscalls) $(mach-shortcuts) \
 	   mach_init mig_strncpy msg \
 	   mig-alloc mig-dealloc mig-reply \
diff --git a/mach/lock-intern.h b/mach/lock-intern.h
index af28c3f..34175f5 100644
--- a/mach/lock-intern.h
+++ b/mach/lock-intern.h
@@ -19,62 +19,81 @@
 #define	_LOCK_INTERN_H
 
 #include <sys/cdefs.h>
-#include <machine-lock.h>
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+#include <lowlevellock.h>
+#endif
 
 #ifndef _EXTERN_INLINE
 #define _EXTERN_INLINE __extern_inline
 #endif
 
+/* The type of a spin lock variable. */
+typedef unsigned int __spin_lock_t;
+
+/* Static initializer for spinlocks. */
+#define __SPIN_LOCK_INITIALIZER   0
 
 /* Initialize LOCK.  */
 
 _EXTERN_INLINE void
 __spin_lock_init (__spin_lock_t *__lock)
 {
-  *__lock = __SPIN_LOCK_INITIALIZER;
+  *__lock = LLL_INITIALIZER;
 }
 
 
-/* Lock LOCK, blocking if we can't get it.  */
-extern void __spin_lock_solid (__spin_lock_t *__lock);
-
 /* Lock the spin lock LOCK.  */
 
 _EXTERN_INLINE void
 __spin_lock (__spin_lock_t *__lock)
 {
-  if (! __spin_try_lock (__lock))
-    __spin_lock_solid (__lock);
+  lll_lock (__lock, 0);
 }
-
-/* Name space-clean internal interface to mutex locks.
 
-   Code internal to the C library uses these functions to lock and unlock
-   mutex locks.  These locks are of type `struct mutex', defined in
-   <cthreads.h>.  The functions here are name space-clean.  If the program
-   is linked with the cthreads library, `__mutex_lock_solid' and
-   `__mutex_unlock_solid' will invoke the corresponding cthreads functions
-   to implement real mutex locks.  If not, simple stub versions just use
-   spin locks.  */
+/* Unlock LOCK. */
+void __spin_unlock (__spin_lock_t *__lock);
 
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+_EXTERN_INLINE void
+__spin_unlock (__spin_lock_t *__lock)
+{
+  lll_unlock (__lock, 0);
+}
+#endif
 
-/* Initialize the newly allocated mutex lock LOCK for further use.  */
-extern void __mutex_init (void *__lock);
+/* Try to lock LOCK; return nonzero if we locked it, zero if another has. */
+int __spin_try_lock (__spin_lock_t *__lock);
 
-/* Lock LOCK, blocking if we can't get it.  */
-extern void __mutex_lock_solid (void *__lock);
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+_EXTERN_INLINE int
+__spin_try_lock (__spin_lock_t *__lock)
+{
+  return (lll_trylock (__lock) == 0);
+}
+#endif
+
+/* Return nonzero if LOCK is locked. */
+int __spin_lock_locked (__spin_lock_t *__lock);
 
-/* Finish unlocking LOCK, after the spin lock LOCK->held has already been
-   unlocked.  This function will wake up any thread waiting on LOCK.  */
-extern void __mutex_unlock_solid (void *__lock);
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+_EXTERN_INLINE int
+__spin_lock_locked (__spin_lock_t *__lock)
+{
+  return (*(volatile __spin_lock_t *)__lock != 0);
+}
+#endif
+
+/* Name space-clean internal interface to mutex locks. */
+
+/* Initialize the newly allocated mutex lock LOCK for further use.  */
+extern void __mutex_init (void *__lock);
 
 /* Lock the mutex lock LOCK.  */
 
 _EXTERN_INLINE void
 __mutex_lock (void *__lock)
 {
-  if (! __spin_try_lock ((__spin_lock_t *) __lock))
-    __mutex_lock_solid (__lock);
+  __spin_lock ((__spin_lock_t *)__lock);
 }
 
 /* Unlock the mutex lock LOCK.  */
@@ -82,15 +101,14 @@ __mutex_lock (void *__lock)
 _EXTERN_INLINE void
 __mutex_unlock (void *__lock)
 {
-  __spin_unlock ((__spin_lock_t *) __lock);
-  __mutex_unlock_solid (__lock);
+  __spin_unlock ((__spin_lock_t *)__lock);
 }
 
 
 _EXTERN_INLINE int
 __mutex_trylock (void *__lock)
 {
-  return __spin_try_lock ((__spin_lock_t *) __lock);
+  return (__spin_try_lock ((__spin_lock_t *)__lock));
 }
 
 #endif /* lock-intern.h */
diff --git a/mach/lowlevellock.h b/mach/lowlevellock.h
new file mode 100644
index 0000000..f22910f
--- /dev/null
+++ b/mach/lowlevellock.h
@@ -0,0 +1,80 @@
+/* Copyright (C) 1994-2017 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef __MACH_LOWLEVELLOCK_H__
+#define __MACH_LOWLEVELLOCK_H__   1
+
+#include <mach/gnumach.h>
+#include <atomic.h>
+
+/* Gsync flags. */
+#ifndef GSYNC_SHARED
+  #define GSYNC_SHARED      0x01
+  #define GSYNC_QUAD        0x02
+  #define GSYNC_TIMED       0x04
+  #define GSYNC_BROADCAST   0x08
+  #define GSYNC_MUTATE      0x10
+#endif
+
+/* Static initializer for low-level locks. */
+#define LLL_INITIALIZER   0
+
+/* Wait on address PTR, without blocking if its contents
+ * are different from VAL. */
+#define lll_wait(ptr, val, flags)   \
+  __gsync_wait (__mach_task_self (),   \
+    (vm_offset_t)(ptr), (val), 0, 0, (flags))
+
+/* Wake one or more threads waiting on address PTR. */
+#define lll_wake(ptr, flags)   \
+  __gsync_wake (__mach_task_self (), (vm_offset_t)(ptr), 0, (flags))
+
+/* Acquire the lock at PTR. */
+#define lll_lock(ptr, flags)   \
+  ({   \
+     int *__iptr = (int *)(ptr);   \
+     int __flags = (flags);   \
+     if (*__iptr != 0 ||   \
+         atomic_compare_and_exchange_bool_acq (__iptr, 1, 0) != 0)   \
+       while (1)   \
+         {   \
+           if (atomic_exchange_acq (__iptr, 2) == 0)   \
+             break;   \
+           lll_wait (__iptr, 2, __flags);   \
+         }   \
+     (void)0;   \
+   })
+
+/* Try to acquire the lock at PTR, without blocking.
+ * Evaluates to zero on success. */
+#define lll_trylock(ptr)   \
+  ({   \
+     int *__iptr = (int *)(ptr);   \
+     *__iptr == 0 &&   \
+       atomic_compare_and_exchange_bool_acq (__iptr, 1, 0) == 0 ? 0 : -1;   \
+   })
+
+/* Release the lock at PTR. */
+#define lll_unlock(ptr, flags)   \
+  ({   \
+     int *__iptr = (int *)(ptr);   \
+     if (atomic_exchange_rel (__iptr, 0) == 2)   \
+       lll_wake (__iptr, (flags));   \
+     (void)0;   \
+   })
+
+#endif
diff --git a/mach/mutex-init.c b/mach/mutex-init.c
index cab0a86..776fec5 100644
--- a/mach/mutex-init.c
+++ b/mach/mutex-init.c
@@ -17,13 +17,10 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <lock-intern.h>
-#include <cthreads.h>
+#include <lowlevellock.h>
 
 void
 __mutex_init (void *lock)
 {
-  /* This happens to be name space-safe because it is a macro.
-     It invokes only spin_lock_init, which is a macro for __spin_lock_init;
-     and cthread_queue_init, which is a macro for some simple code.  */
-  mutex_init ((struct mutex *) lock);
+  *(int *)lock = LLL_INITIALIZER;
 }
diff --git a/sysdeps/mach/Makefile b/sysdeps/mach/Makefile
index 2b48b13..95b83d8 100644
--- a/sysdeps/mach/Makefile
+++ b/sysdeps/mach/Makefile
@@ -50,4 +50,25 @@ mach-before-compile:
 before-compile += $(mach-before-compile)
 endif
 
+ifeq (crypt,$(subdir))
+  LDLIBS-crypt.so += $(objdir)/mach/libmachuser.so
+else ifeq (dlfcn,$(subdir))
+  LDLIBS-dl.so += $(objdir)/mach/libmachuser.so
+else ifeq (nis,$(subdir))
+  LDLIBS-nsl.so += $(objdir)/mach/libmachuser.so
+  LDLIBS-nss_nis.so += $(objdir)/mach/libmachuser.so
+  LDLIBS-nss_nisplus.so += $(objdir)/mach/libmachuser.so
+  LDLIBS-nss_compat.so += $(objdir)/mach/libmachuser.so
+else ifeq (nss,$(subdir))
+  LDLIBS-nss.so += $(objdir)/mach/libmachuser.so
+  LDLIBS-nss_files.so += $(objdir)/mach/libmachuser.so
+  LDLIBS-nss_compat.so += $(objdir)/mach/libmachuser.so
+else ifeq (hesiod,$(subdir))
+  LDLIBS-nss_hesiod.so += $(objdir)/mach/libmachuser.so
+else ifeq (posix,$(subdir))
+  LDLIBS-tst-rfc3484 += $(objdir)/mach/libmachuser.so
+  LDLIBS-tst-rfc3484-2 += $(objdir)/mach/libmachuser.so
+  LDLIBS-tst-rfc3484-3 += $(objdir)/mach/libmachuser.so
+endif
+
 endif	# in-Makerules
diff --git a/sysdeps/mach/hurd/bits/errno.h b/sysdeps/mach/hurd/bits/errno.h
index f0a11af..1a9feda 100644
--- a/sysdeps/mach/hurd/bits/errno.h
+++ b/sysdeps/mach/hurd/bits/errno.h
@@ -127,6 +127,8 @@ enum __error_t_codes
   EPROTO                         = 0x40000074,	/* Protocol error */
   ETIME                          = 0x40000075,	/* Timer expired */
   ECANCELED                      = 0x40000077,	/* Operation canceled */
+  EOWNERDEAD                     = 0x40000078,	/* Robust mutex owner died */
+  ENOTRECOVERABLE                = 0x40000079,	/* Robust mutex irrecoverable */
 
 /* Errors from <mach/message.h>.  */
   EMACH_SEND_IN_PROGRESS         = 0x10000001,
@@ -330,6 +332,8 @@ typedef enum __error_t_codes error_t;
 #define EPROTO                         0x40000074
 #define ETIME                          0x40000075
 #define ECANCELED                      0x40000077
+#define EOWNERDEAD                     0x40000078
+#define ENOTRECOVERABLE                0x40000079
 
 /* Errors from <mach/message.h>.  */
 #define EMACH_SEND_IN_PROGRESS         0x10000001
@@ -413,6 +417,6 @@ typedef enum __error_t_codes error_t;
 #define ED_NO_MEMORY                   2508
 #define ED_READ_ONLY                   2509
 
-#define _HURD_ERRNOS 120
+#define _HURD_ERRNOS 122
 
 #endif /* bits/errno.h.  */
diff --git a/sysdeps/mach/hurd/libc-lock.h b/sysdeps/mach/hurd/libc-lock.h
deleted file mode 100644
index b7fffd0..0000000
--- a/sysdeps/mach/hurd/libc-lock.h
+++ /dev/null
@@ -1,219 +0,0 @@
-/* libc-internal interface for mutex locks.  Hurd version using Mach cthreads.
-   Copyright (C) 1996-2018 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, see
-   <http://www.gnu.org/licenses/>.  */
-
-#ifndef _LIBC_LOCK_H
-#define _LIBC_LOCK_H 1
-
-#if (_LIBC - 0) || (_CTHREADS_ - 0)
-# if (_LIBC - 0)
-#  include <tls.h>
-# endif
-#include <cthreads.h>
-
-/* The locking here is very inexpensive, even for inlining.  */
-#define _IO_lock_inexpensive  1
-
-typedef struct mutex __libc_lock_t;
-typedef struct
-{
-  struct mutex mutex;
-  void *owner;
-  int count;
-} __libc_lock_recursive_t;
-typedef __libc_lock_recursive_t __rtld_lock_recursive_t;
-
-extern char __libc_lock_self0[0];
-#define __libc_lock_owner_self() (__LIBC_NO_TLS() ? &__libc_lock_self0 : THREAD_SELF)
-
-#else
-typedef struct __libc_lock_opaque__ __libc_lock_t;
-typedef struct __libc_lock_recursive_opaque__ __libc_lock_recursive_t;
-#endif
-
-/* 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 an initialized lock variable NAME with storage class CLASS.  */
-#define _LIBC_LOCK_INITIALIZER MUTEX_INITIALIZER
-#define __libc_lock_define_initialized(CLASS,NAME) \
-  CLASS __libc_lock_t NAME = _LIBC_LOCK_INITIALIZER;
-
-/* Initialize the named lock variable, leaving it in a consistent, unlocked
-   state.  */
-#define __libc_lock_init(NAME) __mutex_init (&(NAME))
-
-/* 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.  */
-#define __libc_lock_fini(NAME) __mutex_unlock (&(NAME))
-#define __libc_lock_fini_recursive(NAME) __mutex_unlock (&(NAME).mutex)
-#define __rtld_lock_fini_recursive(NAME) __mutex_unlock (&(NAME).mutex)
-
-
-/* Lock the named lock variable.  */
-#define __libc_lock_lock(NAME) __mutex_lock (&(NAME))
-
-/* Lock the named lock variable.  */
-#define __libc_lock_trylock(NAME) (!__mutex_trylock (&(NAME)))
-
-/* Unlock the named lock variable.  */
-#define __libc_lock_unlock(NAME) __mutex_unlock (&(NAME))
-
-
-#define __libc_lock_define_recursive(CLASS,NAME) \
-  CLASS __libc_lock_recursive_t NAME;
-#define _LIBC_LOCK_RECURSIVE_INITIALIZER { MUTEX_INITIALIZER, 0, 0 }
-#define __libc_lock_define_initialized_recursive(CLASS,NAME) \
-  CLASS __libc_lock_recursive_t NAME = _LIBC_LOCK_RECURSIVE_INITIALIZER;
-
-#define __rtld_lock_define_recursive(CLASS,NAME) \
-  __libc_lock_define_recursive (CLASS, NAME)
-#define _RTLD_LOCK_RECURSIVE_INITIALIZER \
-  _LIBC_LOCK_RECURSIVE_INITIALIZER
-#define __rtld_lock_define_initialized_recursive(CLASS,NAME) \
-  __libc_lock_define_initialized_recursive (CLASS, NAME)
-
-#define __libc_lock_init_recursive(NAME) \
-  ({ __libc_lock_recursive_t *const __lock = &(NAME); \
-     __lock->owner = 0; mutex_init (&__lock->mutex); })
-
-#define __libc_lock_trylock_recursive(NAME)				      \
-  ({ __libc_lock_recursive_t *const __lock = &(NAME);			      \
-     void *__self = __libc_lock_owner_self ();				      \
-     __mutex_trylock (&__lock->mutex)					      \
-     ? (__lock->owner = __self, __lock->count = 1, 0)			      \
-     : __lock->owner == __self ? (++__lock->count, 0) : 1; })
-
-#define __libc_lock_lock_recursive(NAME)				      \
-  ({ __libc_lock_recursive_t *const __lock = &(NAME);			      \
-     void *__self = __libc_lock_owner_self ();				      \
-     if (__mutex_trylock (&__lock->mutex)				      \
-	 || (__lock->owner != __self					      \
-	     && (__mutex_lock (&__lock->mutex), 1)))			      \
-       __lock->owner = __self, __lock->count = 1;			      \
-     else								      \
-       ++__lock->count;							      \
-  })
-#define __libc_lock_unlock_recursive(NAME)				      \
-  ({ __libc_lock_recursive_t *const __lock = &(NAME);			      \
-     if (--__lock->count == 0)						      \
-       {								      \
-	 __lock->owner = 0;						      \
-	 __mutex_unlock (&__lock->mutex);				      \
-       }								      \
-  })
-
-
-#define __rtld_lock_initialize(NAME) \
-  (void) ((NAME) = (__rtld_lock_recursive_t) _RTLD_LOCK_RECURSIVE_INITIALIZER)
-#define __rtld_lock_trylock_recursive(NAME) \
-  __libc_lock_trylock_recursive (NAME)
-#define __rtld_lock_lock_recursive(NAME) \
-  __libc_lock_lock_recursive(NAME)
-#define __rtld_lock_unlock_recursive(NAME) \
-  __libc_lock_unlock_recursive (NAME)
-
-
-/* XXX for now */
-#define __libc_rwlock_define		__libc_lock_define
-#define __libc_rwlock_define_initialized __libc_lock_define_initialized
-#define __libc_rwlock_init		__libc_lock_init
-#define __libc_rwlock_fini		__libc_lock_fini
-#define __libc_rwlock_rdlock		__libc_lock_lock
-#define __libc_rwlock_wrlock		__libc_lock_lock
-#define __libc_rwlock_tryrdlock		__libc_lock_trylock
-#define __libc_rwlock_trywrlock		__libc_lock_trylock
-#define __libc_rwlock_unlock		__libc_lock_unlock
-
-
-/* Start a critical region with a cleanup function */
-#define __libc_cleanup_region_start(DOIT, FCT, ARG)			    \
-{									    \
-  typeof (***(FCT)) *__save_FCT = (DOIT) ? (FCT) : 0;			    \
-  typeof (ARG) __save_ARG = ARG;					    \
-  /* close brace is in __libc_cleanup_region_end below. */
-
-/* End a critical region started with __libc_cleanup_region_start. */
-#define __libc_cleanup_region_end(DOIT)					    \
-  if ((DOIT) && __save_FCT != 0)					    \
-    (*__save_FCT)(__save_ARG);						    \
-}
-
-/* Sometimes we have to exit the block in the middle.  */
-#define __libc_cleanup_end(DOIT)					    \
-  if ((DOIT) && __save_FCT != 0)					    \
-    (*__save_FCT)(__save_ARG);						    \
-
-#define __libc_cleanup_push(fct, arg) __libc_cleanup_region_start (1, fct, arg)
-#define __libc_cleanup_pop(execute) __libc_cleanup_region_end (execute)
-
-#if (_CTHREADS_ - 0)
-
-/* Use mutexes as once control variables. */
-
-struct __libc_once
-  {
-    __libc_lock_t lock;
-    int done;
-  };
-
-#define __libc_once_define(CLASS,NAME) \
-  CLASS struct __libc_once NAME = { MUTEX_INITIALIZER, 0 }
-
-/* Call handler iff the first call.  */
-#define __libc_once(ONCE_CONTROL, INIT_FUNCTION) \
-  do {									      \
-    __libc_lock_lock (ONCE_CONTROL.lock);				      \
-    if (!ONCE_CONTROL.done)						      \
-      (INIT_FUNCTION) ();						      \
-    ONCE_CONTROL.done = 1;						      \
-    __libc_lock_unlock (ONCE_CONTROL.lock);				      \
-  } while (0)
-
-/* Get once control variable.  */
-#define __libc_once_get(ONCE_CONTROL)	((ONCE_CONTROL).done != 0)
-
-#ifdef _LIBC
-/* We need portable names for some functions.  E.g., when they are
-   used as argument to __libc_cleanup_region_start.  */
-#define __libc_mutex_unlock __mutex_unlock
-#endif
-
-/* Type for key of thread specific data.  */
-typedef cthread_key_t __libc_key_t;
-
-#define __libc_key_create(KEY,DEST) cthread_keycreate (KEY)
-#define __libc_setspecific(KEY,VAL) cthread_setspecific (KEY, VAL)
-void *__libc_getspecific (__libc_key_t key);
-
-#endif /* _CTHREADS_ */
-
-/* Hide the definitions which are only supposed to be used inside libc in
-   a separate file.  This file is not present in the installation!  */
-#ifdef _LIBC
-# include <libc-lockP.h>
-#endif
-
-#endif	/* libc-lock.h */
diff --git a/sysdeps/mach/hurd/setpgid.c b/sysdeps/mach/hurd/setpgid.c
index 32186a2..98b1341 100644
--- a/sysdeps/mach/hurd/setpgid.c
+++ b/sysdeps/mach/hurd/setpgid.c
@@ -19,6 +19,7 @@
 #include <unistd.h>
 #include <hurd.h>
 #include <hurd/port.h>
+#include <lowlevellock.h>
 
 /* Set the process group ID of the process matching PID to PGID.
    If PID is zero, the current process's process group ID is set.
@@ -38,14 +39,7 @@ __setpgid (pid_t pid, pid_t pgid)
     /* Synchronize with the signal thread to make sure we have
        received and processed proc_newids before returning to the user.  */
     while (_hurd_pids_changed_stamp == stamp)
-      {
-#ifdef noteven
-	/* XXX we have no need for a mutex, but cthreads demands one.  */
-	__condition_wait (&_hurd_pids_changed_sync, NULL);
-#else
-	__swtch_pri(0);
-#endif
-      }
+      lll_wait (&_hurd_pids_changed_stamp, stamp, 0);
 
   return 0;
 
diff --git a/sysdeps/mach/hurd/setsid.c b/sysdeps/mach/hurd/setsid.c
index 0f6b24b..7b98936 100644
--- a/sysdeps/mach/hurd/setsid.c
+++ b/sysdeps/mach/hurd/setsid.c
@@ -21,6 +21,7 @@
 #include <hurd/port.h>
 #include <hurd/fd.h>
 #include <hurd/ioctl.h>
+#include <lowlevellock.h>
 
 /* Create a new session with the calling process as its leader.
    The process group IDs of the session and the calling process
@@ -55,14 +56,7 @@ __setsid (void)
 	 returned by `getpgrp ()' in other threads) has been updated before
 	 we return.  */
       while (_hurd_pids_changed_stamp == stamp)
-	{
-#ifdef noteven
-	  /* XXX we have no need for a mutex, but cthreads demands one.  */
-	  __condition_wait (&_hurd_pids_changed_sync, NULL);
-#else
-	  __swtch_pri (0);
-#endif
-	}
+        lll_wait (&_hurd_pids_changed_stamp, stamp, 0);
     }
 
   HURD_CRITICAL_END;
diff --git a/sysdeps/mach/libc-lock.h b/sysdeps/mach/libc-lock.h
index caeba47..767f45e 100644
--- a/sysdeps/mach/libc-lock.h
+++ b/sysdeps/mach/libc-lock.h
@@ -20,10 +20,31 @@
 #define _LIBC_LOCK_H 1
 
 #ifdef _LIBC
+
+#include <tls.h>
 #include <cthreads.h>
-#define __libc_lock_t struct mutex
+#include <lowlevellock.h>
+
+/* The locking here is very inexpensive, even for inlining. */
+#define _IO_lock_inexpensive   1
+
+typedef unsigned int __libc_lock_t;
+typedef struct
+{
+  __libc_lock_t lock;
+  int cnt;
+  void *owner;
+} __libc_lock_recursive_t;
+
+typedef __libc_lock_recursive_t __rtld_lock_recursive_t;
+
+extern char __libc_lock_self0[0];
+#define __libc_lock_owner_self()   \
+  (__LIBC_NO_TLS() ? (void *)&__libc_lock_self0 : THREAD_SELF)
+
 #else
 typedef struct __libc_lock_opaque__ __libc_lock_t;
+typedef struct __libc_lock_recursive_opaque__ __libc_lock_recursive_t;
 #endif
 
 /* Type for key of thread specific data.  */
@@ -40,27 +61,94 @@ typedef cthread_key_t __libc_key_t;
   CLASS __libc_lock_t NAME;
 
 /* Define an initialized lock variable NAME with storage class CLASS.  */
+#define _LIBC_LOCK_INITIALIZER LLL_INITIALIZER
 #define __libc_lock_define_initialized(CLASS,NAME) \
-  CLASS __libc_lock_t NAME = MUTEX_INITIALIZER;
+  CLASS __libc_lock_t NAME = LLL_INITIALIZER;
 
 /* Initialize the named lock variable, leaving it in a consistent, unlocked
    state.  */
-#define __libc_lock_init(NAME) __mutex_init (&(NAME))
+#define __libc_lock_init(NAME) (NAME) = LLL_INITIALIZER
 
 /* 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.  */
-#define __libc_lock_fini(NAME) __mutex_unlock (&(NAME))
+#define __libc_lock_fini             __libc_lock_unlock
+#define __libc_lock_fini_recursive   __libc_lock_unlock_recursive
+#define __rtld_lock_fini_recursive   __rtld_lock_unlock_recursive
 
 /* Lock the named lock variable.  */
-#define __libc_lock_lock(NAME) __mutex_lock (&(NAME))
+#define __libc_lock_lock(NAME)   \
+  ({ lll_lock (&(NAME), 0); 0; })
 
 /* Lock the named lock variable.  */
-#define __libc_lock_trylock(NAME) (!__mutex_trylock (&(NAME)))
+#define __libc_lock_trylock(NAME) lll_trylock (&(NAME))
 
 /* Unlock the named lock variable.  */
-#define __libc_lock_unlock(NAME) __mutex_unlock (&(NAME))
-
+#define __libc_lock_unlock(NAME)   \
+  ({ lll_unlock (&(NAME), 0); 0; })
+
+#define __libc_lock_define_recursive(CLASS,NAME) \
+  CLASS __libc_lock_recursive_t NAME;
+
+#define _LIBC_LOCK_RECURSIVE_INITIALIZER { LLL_INITIALIZER, 0, 0 }
+
+#define __libc_lock_define_initialized_recursive(CLASS,NAME) \
+  CLASS __libc_lock_recursive_t NAME = _LIBC_LOCK_RECURSIVE_INITIALIZER;
+
+#define __rtld_lock_define_recursive(CLASS,NAME) \
+  __libc_lock_define_recursive (CLASS, NAME)
+#define _RTLD_LOCK_RECURSIVE_INITIALIZER \
+  _LIBC_LOCK_RECURSIVE_INITIALIZER
+#define __rtld_lock_define_initialized_recursive(CLASS,NAME) \
+  __libc_lock_define_initialized_recursive (CLASS, NAME)
+
+#define __libc_lock_init_recursive(NAME)   \
+  ((NAME) = (__libc_lock_recursive_t)_LIBC_LOCK_RECURSIVE_INITIALIZER, 0)
+
+#define __libc_lock_trylock_recursive(NAME)   \
+  ({   \
+     __libc_lock_recursive_t *const __lock = &(NAME);   \
+     void *__self = __libc_lock_owner_self ();   \
+     int __r = 0;   \
+     if (__self == __lock->owner)   \
+       ++__lock->cnt;   \
+     else if ((__r = lll_trylock (&__lock->lock)) == 0)   \
+       __lock->owner = __self, __lock->cnt = 1;   \
+     __r;   \
+   })
+
+#define __libc_lock_lock_recursive(NAME)   \
+  ({   \
+     __libc_lock_recursive_t *const __lock = &(NAME);   \
+     void *__self = __libc_lock_owner_self ();   \
+     if (__self != __lock->owner)   \
+       {   \
+         lll_lock (&__lock->lock, 0);   \
+         __lock->owner = __self;   \
+       }   \
+     ++__lock->cnt;   \
+     (void)0;   \
+   })
+
+#define __libc_lock_unlock_recursive(NAME)   \
+  ({   \
+     __libc_lock_recursive_t *const __lock = &(NAME);   \
+     if (--__lock->cnt == 0)   \
+       {   \
+         __lock->owner = 0;   \
+         lll_unlock (&__lock->lock, 0);   \
+       }   \
+   })
+
+
+#define __rtld_lock_initialize(NAME) \
+  (void) ((NAME) = (__rtld_lock_recursive_t) _RTLD_LOCK_RECURSIVE_INITIALIZER)
+#define __rtld_lock_trylock_recursive(NAME) \
+  __libc_lock_trylock_recursive (NAME)
+#define __rtld_lock_lock_recursive(NAME) \
+  __libc_lock_lock_recursive(NAME)
+#define __rtld_lock_unlock_recursive(NAME) \
+  __libc_lock_unlock_recursive (NAME)
 
 /* XXX for now */
 #define __libc_rwlock_define		__libc_lock_define
@@ -73,25 +161,38 @@ typedef cthread_key_t __libc_key_t;
 #define __libc_rwlock_trywrlock		__libc_lock_trylock
 #define __libc_rwlock_unlock		__libc_lock_unlock
 
+struct __libc_cleanup_frame
+{
+  void (*__fct) (void *);
+  void *__argp;
+  int __doit;
+};
+
+__extern_inline void
+__libc_cleanup_fct (struct __libc_cleanup_frame *framep)
+{
+  if (framep->__doit)
+    framep->__fct (framep->__argp);
+}
 
 /* Start a critical region with a cleanup function */
-#define __libc_cleanup_region_start(DOIT, FCT, ARG)			    \
-{									    \
-  typeof (***(FCT)) *__save_FCT = (DOIT) ? (FCT) : 0;			    \
-  typeof (ARG) __save_ARG = ARG;					    \
-  /* close brace is in __libc_cleanup_region_end below. */
-
-/* End a critical region started with __libc_cleanup_region_start. */
-#define __libc_cleanup_region_end(DOIT)					    \
-  if ((DOIT) && __save_FCT != 0)					    \
-    (*__save_FCT)(__save_ARG);						    \
-}
+#define __libc_cleanup_region_start(DOIT, FCT, ARG)   \
+  do   \
+    {   \
+      struct __libc_cleanup_frame __cleanup   \
+        __attribute__ ((__cleanup__ (__libc_cleanup_fct))) =   \
+        { .__fct = (FCT), .__argp = (ARG), .__doit = (DOIT) };
+
+/* This one closes the brace above. */
+#define __libc_cleanup_region_end(DOIT)   \
+      __cleanup.__doit = (DOIT);   \
+    }   \
+  while (0)
 
-/* Sometimes we have to exit the block in the middle.  */
-#define __libc_cleanup_end(DOIT)					    \
-  if ((DOIT) && __save_FCT != 0)					    \
-    (*__save_FCT)(__save_ARG);						    \
+#define __libc_cleanup_end(DOIT)   __cleanup.__doit = (DOIT);
 
+#define __libc_cleanup_push(fct, arg) __libc_cleanup_region_start (1, fct, arg)
+#define __libc_cleanup_pop(execute) __libc_cleanup_region_end (execute)
 
 /* Use mutexes as once control variables. */
 
@@ -102,8 +203,7 @@ struct __libc_once
   };
 
 #define __libc_once_define(CLASS,NAME) \
-  CLASS struct __libc_once NAME = { MUTEX_INITIALIZER, 0 }
-
+  CLASS struct __libc_once NAME = { _LIBC_LOCK_INITIALIZER, 0 }
 
 /* Call handler iff the first call.  */
 #define __libc_once(ONCE_CONTROL, INIT_FUNCTION) \
@@ -121,25 +221,15 @@ struct __libc_once
 #ifdef _LIBC
 /* We need portable names for some functions.  E.g., when they are
    used as argument to __libc_cleanup_region_start.  */
-#define __libc_mutex_unlock __mutex_unlock
-#endif
+#define __libc_mutex_unlock __libc_lock_unlock
 
 #define __libc_key_create(KEY,DEST) cthread_keycreate (KEY)
 #define __libc_setspecific(KEY,VAL) cthread_setspecific (KEY, VAL)
 void *__libc_getspecific (__libc_key_t key);
 
-/* XXX until cthreads supports recursive locks */
-#define __libc_lock_define_initialized_recursive __libc_lock_define_initialized
-#define __libc_lock_init_recursive __libc_lock_init
-#define __libc_lock_fini_recursive __libc_lock_fini
-#define __libc_lock_trylock_recursive __libc_lock_trylock
-#define __libc_lock_unlock_recursive __libc_lock_unlock
-#define __libc_lock_lock_recursive __libc_lock_lock
-
-#define __rtld_lock_define_initialized_recursive __libc_lock_define_initialized
-#define __rtld_lock_fini_recursive __libc_lock_fini
-#define __rtld_lock_trylock_recursive __libc_lock_trylock
-#define __rtld_lock_unlock_recursive __libc_lock_unlock
-#define __rtld_lock_lock_recursive __libc_lock_lock
+/* Hide the definitions which are only supposed to be used inside libc in
+   a separate file.  This file is not present in the installation!  */
+# include <libc-lockP.h>
+#endif
 
 #endif	/* libc-lock.h */

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=4db8125dbce40f169d57153b80e2b14b735a276f

commit 4db8125dbce40f169d57153b80e2b14b735a276f
Author: Thomas Schwinge <thomas@schwinge.name>
Date:   Fri Jan 19 02:18:09 2018 +0100

    t/tls-threadvar
    
    replace the custom threadvar mechanism with generic TLS.
    That will fix sigaltstack.
    
    Note: the added reply_port and _hurd_sigstate fields should be kept last.

diff --git a/hurd/Versions b/hurd/Versions
index 8b84f73..6db2a9c 100644
--- a/hurd/Versions
+++ b/hurd/Versions
@@ -4,14 +4,9 @@ libc {
     _end;
 
     # variables used in macros & inline functions
-    __hurd_sigthread_stack_base; __hurd_sigthread_stack_end;
-    __hurd_sigthread_variables;
     __hurd_threadvar_max;
     __hurd_threadvar_stack_mask; __hurd_threadvar_stack_offset;
 
-    # functions used in macros & inline functions
-    __hurd_errno_location;
-
     # functions used in libmachuser and libhurduser
     _S_catch_exception_raise;
     _S_catch_exception_raise_state;
@@ -143,6 +138,7 @@ libc {
   HURD_CTHREADS_0.3 {
     # weak refs to libthreads functions that libc calls iff libthreads in use
     cthread_fork; cthread_detach;
+    pthread_getattr_np; pthread_attr_getstack;
 
     # variables used for detecting cthreads
     _cthread_exit_routine; _cthread_init_routine;
diff --git a/hurd/hurd/signal.h b/hurd/hurd/signal.h
index 233d10f..0e6a969 100644
--- a/hurd/hurd/signal.h
+++ b/hurd/hurd/signal.h
@@ -40,7 +40,6 @@
 #include <cthreads.h>		/* For `struct mutex'.  */
 #include <setjmp.h>		/* For `jmp_buf'.  */
 #include <spin-lock.h>
-#include <hurd/threadvar.h>	/* We cache sigstate in a threadvar.  */
 struct hurd_signal_preemptor;	/* <hurd/sigpreempt.h> */
 #if defined __USE_EXTERN_INLINES && defined _LIBC
 #  if IS_IN (libc)
@@ -137,11 +136,9 @@ extern struct hurd_sigstate *_hurd_self_sigstate (void)
 _HURD_SIGNAL_H_EXTERN_INLINE struct hurd_sigstate *
 _hurd_self_sigstate (void)
 {
-  struct hurd_sigstate **location = (struct hurd_sigstate **)
-    (void *) __hurd_threadvar_location (_HURD_THREADVAR_SIGSTATE);
-  if (*location == NULL)
-    *location = _hurd_thread_sigstate (__mach_thread_self ());
-  return *location;
+  if (THREAD_SELF->_hurd_sigstate == NULL)
+    THREAD_SELF->_hurd_sigstate = _hurd_thread_sigstate (__mach_thread_self ());
+  return THREAD_SELF->_hurd_sigstate;
 }
 
 /* Thread listening on our message port; also called the "signal thread".  */
@@ -172,16 +169,22 @@ extern int _hurd_core_limit;
 _HURD_SIGNAL_H_EXTERN_INLINE void *
 _hurd_critical_section_lock (void)
 {
-  struct hurd_sigstate **location = (struct hurd_sigstate **)
-    (void *) __hurd_threadvar_location (_HURD_THREADVAR_SIGSTATE);
-  struct hurd_sigstate *ss = *location;
+  struct hurd_sigstate *ss;
+
+#ifdef __LIBC_NO_TLS
+  if (__LIBC_NO_TLS())
+    /* TLS is currently initializing, no need to enter critical section.  */
+    return NULL;
+#endif
+
+  ss = THREAD_SELF->_hurd_sigstate;
   if (ss == NULL)
     {
       /* The thread variable is unset; this must be the first time we've
 	 asked for it.  In this case, the critical section flag cannot
 	 possible already be set.  Look up our sigstate structure the slow
 	 way.  */
-      ss = *location = _hurd_thread_sigstate (__mach_thread_self ());
+      ss = THREAD_SELF->_hurd_sigstate = _hurd_thread_sigstate (__mach_thread_self ());
     }
 
   if (! __spin_try_lock (&ss->critical_section_lock))
diff --git a/hurd/hurd/threadvar.h b/hurd/hurd/threadvar.h
index 1727dac..0887a17 100644
--- a/hurd/hurd/threadvar.h
+++ b/hurd/hurd/threadvar.h
@@ -20,6 +20,7 @@
 #define	_HURD_THREADVAR_H
 
 #include <features.h>
+#include <tls.h>
 
 /* The per-thread variables are found by ANDing this mask
    with the value of the stack pointer and then adding this offset.
@@ -30,87 +31,24 @@
    __hurd_threadvar_stack_offset to a small offset that skips the data
    cthreads itself maintains at the base of each thread's stack.
 
-   In the single-threaded case, __hurd_threadvar_stack_mask is zero, so the
-   stack pointer is ignored; and __hurd_threadvar_stack_offset gives the
-   address of a small allocated region which contains the variables for the
-   single thread.  */
+   In the single-threaded or libpthread case, __hurd_threadvar_stack_mask is
+   zero, so the stack pointer is ignored. */
 
 extern unsigned long int __hurd_threadvar_stack_mask;
 extern unsigned long int __hurd_threadvar_stack_offset;
 
-/* A special case must always be made for the signal thread.  Even when there
-   is only one user thread and an allocated region can be used for the user
-   thread's variables, the signal thread needs to have its own location for
-   per-thread variables.  The variables __hurd_sigthread_stack_base and
+/* The variables __hurd_sigthread_stack_base and
    __hurd_sigthread_stack_end define the bounds of the stack used by the
    signal thread, so that thread can always be specifically identified.  */
 
 extern unsigned long int __hurd_sigthread_stack_base;
 extern unsigned long int __hurd_sigthread_stack_end;
-extern unsigned long int *__hurd_sigthread_variables;
 
 
-/* At the location described by the two variables above,
-   there are __hurd_threadvar_max `unsigned long int's of per-thread data.  */
+/* We do not use threadvars any more, this is kept as zero for compatibility with cthreads */
 extern unsigned int __hurd_threadvar_max;
 
-/* These values are the indices for the standard per-thread variables.  */
-enum __hurd_threadvar_index
-  {
-    _HURD_THREADVAR_MIG_REPLY,	/* Reply port for MiG user stub functions.  */
-    _HURD_THREADVAR_ERRNO,	/* `errno' value for this thread.  */
-    _HURD_THREADVAR_SIGSTATE,	/* This thread's `struct hurd_sigstate'.  */
-    _HURD_THREADVAR_DYNAMIC_USER, /* Dynamically-assigned user variables.  */
-    _HURD_THREADVAR_MALLOC,	/* For use of malloc.  */
-    _HURD_THREADVAR_DL_ERROR,	/* For use of -ldl and dynamic linker.  */
-    _HURD_THREADVAR_RPC_VARS,	/* For state of RPC functions.  */
-    _HURD_THREADVAR_LOCALE,	/* For thread-local locale setting.  */
-    _HURD_THREADVAR_CTYPE_B,	/* Cache of thread-local locale data.  */
-    _HURD_THREADVAR_CTYPE_TOLOWER, /* Cache of thread-local locale data.  */
-    _HURD_THREADVAR_CTYPE_TOUPPER, /* Cache of thread-local locale data.  */
-    _HURD_THREADVAR_MAX		/* Default value for __hurd_threadvar_max.  */
-  };
-
-
-#ifndef _HURD_THREADVAR_H_EXTERN_INLINE
-#define _HURD_THREADVAR_H_EXTERN_INLINE __extern_inline
-#endif
-
-/* Return the location of the value for the per-thread variable with index
-   INDEX used by the thread whose stack pointer is SP.  */
-
-extern unsigned long int *__hurd_threadvar_location_from_sp
-  (enum __hurd_threadvar_index __index, void *__sp);
-_HURD_THREADVAR_H_EXTERN_INLINE unsigned long int *
-__hurd_threadvar_location_from_sp (enum __hurd_threadvar_index __index,
-				   void *__sp)
-{
-  unsigned long int __stack = (unsigned long int) __sp;
-  return &((__stack >= __hurd_sigthread_stack_base &&
-	    __stack < __hurd_sigthread_stack_end)
-	   ? __hurd_sigthread_variables
-	   : (unsigned long int *) ((__stack & __hurd_threadvar_stack_mask) +
-				    __hurd_threadvar_stack_offset))[__index];
-}
-
-#include <machine-sp.h>		/* Define __thread_stack_pointer.  */
-
-/* Return the location of the current thread's value for the
-   per-thread variable with index INDEX.  */
-
-extern unsigned long int *
-__hurd_threadvar_location (enum __hurd_threadvar_index __index) __THROW
-     /* This declaration tells the compiler that the value is constant
-	given the same argument.  We assume this won't be called twice from
-	the same stack frame by different threads.  */
-     __attribute__ ((__const__));
-
-_HURD_THREADVAR_H_EXTERN_INLINE unsigned long int *
-__hurd_threadvar_location (enum __hurd_threadvar_index __index)
-{
-  return __hurd_threadvar_location_from_sp (__index,
-					    __thread_stack_pointer ());
-}
-
+extern mach_port_t __hurd_reply_port0;
+#define __hurd_local_reply_port (*(__LIBC_NO_TLS() ? &__hurd_reply_port0 : &THREAD_SELF->reply_port))
 
 #endif	/* hurd/threadvar.h */
diff --git a/hurd/hurdsig.c b/hurd/hurdsig.c
index 3e587a4..e215cf1 100644
--- a/hurd/hurdsig.c
+++ b/hurd/hurdsig.c
@@ -20,6 +20,7 @@
 #include <string.h>
 
 #include <cthreads.h>		/* For `struct mutex'.  */
+#include <pthread.h>
 #include <mach.h>
 #include <mach/thread_switch.h>
 
@@ -48,7 +49,6 @@ thread_t _hurd_sigthread;
 /* These are set up by _hurdsig_init.  */
 unsigned long int __hurd_sigthread_stack_base;
 unsigned long int __hurd_sigthread_stack_end;
-unsigned long int *__hurd_sigthread_variables;
 
 /* Linked-list of per-thread signal state.  */
 struct hurd_sigstate *_hurd_sigstates;
@@ -234,14 +234,14 @@ abort_thread (struct hurd_sigstate *ss, struct machine_thread_all_state *state,
    that this location can be set without faulting, or else return NULL.  */
 
 static mach_port_t *
-interrupted_reply_port_location (struct machine_thread_all_state *thread_state,
+interrupted_reply_port_location (thread_t thread,
+				 struct machine_thread_all_state *thread_state,
 				 int sigthread)
 {
-  mach_port_t *portloc = (mach_port_t *) __hurd_threadvar_location_from_sp
-    (_HURD_THREADVAR_MIG_REPLY, (void *) thread_state->basic.SP);
+  mach_port_t *portloc = &THREAD_TCB(thread, thread_state)->reply_port;
 
   if (sigthread && _hurdsig_catch_memory_fault (portloc))
-    /* Faulted trying to read the stack.  */
+    /* Faulted trying to read the TCB.  */
     return NULL;
 
   /* Fault now if this pointer is bogus.  */
@@ -323,7 +323,8 @@ _hurdsig_abort_rpcs (struct hurd_sigstate *ss, int signo, int sigthread,
 	   our nonzero return tells the trampoline code to finish the message
 	   receive operation before running the handler.  */
 
-	mach_port_t *reply = interrupted_reply_port_location (state,
+	mach_port_t *reply = interrupted_reply_port_location (ss->thread,
+							      state,
 							      sigthread);
 	error_t err = __interrupt_operation (intr_port, _hurdsig_interrupt_timeout);
 
@@ -835,7 +836,8 @@ _hurd_internal_post_signal (struct hurd_sigstate *ss,
 
 	    if (! machine_get_basic_state (ss->thread, &thread_state))
 	      goto sigbomb;
-	    loc = interrupted_reply_port_location (&thread_state, 1);
+	    loc = interrupted_reply_port_location (ss->thread,
+						   &thread_state, 1);
 	    if (loc && *loc != MACH_PORT_NULL)
 	      /* This is the reply port for the context which called
 		 sigreturn.  Since we are abandoning that context entirely
@@ -901,7 +903,8 @@ _hurd_internal_post_signal (struct hurd_sigstate *ss,
 	{
 	  /* Fetch the thread variable for the MiG reply port,
 	     and set it to MACH_PORT_NULL.  */
-	  mach_port_t *loc = interrupted_reply_port_location (&thread_state,
+	  mach_port_t *loc = interrupted_reply_port_location (ss->thread,
+							      &thread_state,
 							      1);
 	  if (loc)
 	    {
@@ -1255,7 +1258,11 @@ _hurdsig_init (const int *intarray, size_t intarraysize)
 
   /* Start the signal thread listening on the message port.  */
 
-  if (__hurd_threadvar_stack_mask == 0)
+#pragma weak cthread_fork
+#pragma weak cthread_detach
+#pragma weak pthread_getattr_np
+#pragma weak pthread_attr_getstack
+  if (!cthread_fork)
     {
       err = __thread_create (__mach_task_self (), &_hurd_msgport_thread);
       assert_perror (err);
@@ -1270,14 +1277,6 @@ _hurdsig_init (const int *intarray, size_t intarraysize)
       assert_perror (err);
 
       __hurd_sigthread_stack_end = __hurd_sigthread_stack_base + stacksize;
-      __hurd_sigthread_variables =
-	malloc (__hurd_threadvar_max * sizeof (unsigned long int));
-      if (__hurd_sigthread_variables == NULL)
-	__libc_fatal ("hurd: Can't allocate threadvars for signal thread\n");
-      memset (__hurd_sigthread_variables, 0,
-	      __hurd_threadvar_max * sizeof (unsigned long int));
-      __hurd_sigthread_variables[_HURD_THREADVAR_LOCALE]
-	= (unsigned long int) &_nl_global_locale;
 
       /* Reinitialize the MiG support routines so they will use a per-thread
 	 variable for the cached reply port.  */
@@ -1288,6 +1287,7 @@ _hurdsig_init (const int *intarray, size_t intarraysize)
     }
   else
     {
+      cthread_t thread;
       /* When cthreads is being used, we need to make the signal thread a
          proper cthread.  Otherwise it cannot use mutex_lock et al, which
          will be the cthreads versions.  Various of the message port RPC
@@ -1297,9 +1297,20 @@ _hurdsig_init (const int *intarray, size_t intarraysize)
          we'll let the signal thread's per-thread variables be found as for
          any normal cthread, and just leave the magic __hurd_sigthread_*
          values all zero so they'll be ignored.  */
-#pragma weak cthread_fork
-#pragma weak cthread_detach
-      cthread_detach (cthread_fork ((cthread_fn_t) &_hurd_msgport_receive, 0));
+      cthread_detach (thread = cthread_fork ((cthread_fn_t) &_hurd_msgport_receive, 0));
+
+      if (pthread_getattr_np)
+	{
+	  /* Record stack layout for fork() */
+	  pthread_attr_t attr;
+	  void *addr;
+	  size_t size;
+
+	  pthread_getattr_np ((pthread_t) thread, &attr);
+	  pthread_attr_getstack (&attr, &addr, &size);
+	  __hurd_sigthread_stack_base = (uintptr_t) addr;
+	  __hurd_sigthread_stack_end = __hurd_sigthread_stack_base + size;
+	}
 
       /* XXX We need the thread port for the signal thread further on
          in this thread (see hurdfault.c:_hurdsigfault_init).
diff --git a/hurd/hurdstartup.c b/hurd/hurdstartup.c
index bd9eca2..b148125 100644
--- a/hurd/hurdstartup.c
+++ b/hurd/hurdstartup.c
@@ -23,7 +23,6 @@
 #include <hurd.h>
 #include <hurd/exec_startup.h>
 #include <sysdep.h>
-#include <hurd/threadvar.h>
 #include <unistd.h>
 #include <elf.h>
 #include <set-hooks.h>
diff --git a/hurd/sigunwind.c b/hurd/sigunwind.c
index 4db9827..40e0f67 100644
--- a/hurd/sigunwind.c
+++ b/hurd/sigunwind.c
@@ -18,6 +18,7 @@
 
 #include <hurd.h>
 #include <thread_state.h>
+#include <hurd/threadvar.h>
 #include <jmpbuf-unwind.h>
 #include <assert.h>
 #include <stdint.h>
@@ -38,8 +39,7 @@ _hurdsig_longjmp_from_handler (void *data, jmp_buf env, int val)
     {
       /* Destroy the MiG reply port used by the signal handler, and restore
 	 the reply port in use by the thread when interrupted.  */
-      mach_port_t *reply_port =
-	(mach_port_t *) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY);
+      mach_port_t *reply_port = &__hurd_local_reply_port;
       if (*reply_port)
 	{
 	  mach_port_t port = *reply_port;
diff --git a/include/errno.h b/include/errno.h
index 89353aa..32c2f49 100644
--- a/include/errno.h
+++ b/include/errno.h
@@ -24,7 +24,7 @@ extern int rtld_errno attribute_hidden;
 
 #  include <tls.h>
 
-#  if !defined __GNU__
+#  if !(defined(__GNU__) && IS_IN (rtld))
 #   undef  errno
 #   if IS_IN (libc)
 #    define errno __libc_errno
diff --git a/sysdeps/mach/hurd/Versions b/sysdeps/mach/hurd/Versions
index 89e1906..7cab8e8 100644
--- a/sysdeps/mach/hurd/Versions
+++ b/sysdeps/mach/hurd/Versions
@@ -6,6 +6,7 @@ libc {
   GLIBC_PRIVATE {
     # Functions shared with the dynamic linker
     __libc_read; __libc_write; __libc_lseek64;
+    __libc_lock_self0;
 
     _dl_init_first;
   }
@@ -14,8 +15,6 @@ libc {
 ld {
   GLIBC_2.0 {
     # variables that must be shared with libc
-    __hurd_sigthread_stack_base; __hurd_sigthread_stack_end;
-    __hurd_sigthread_variables;
     __hurd_threadvar_stack_mask;  __hurd_threadvar_stack_offset;
 
     # functions that must be shared with libc
@@ -33,5 +32,6 @@ ld {
 
     # functions that must be shared with libc
     __libc_read; __libc_write; __libc_lseek64;
+    __libc_lock_self0;
   }
 }
diff --git a/sysdeps/mach/hurd/cthreads.c b/sysdeps/mach/hurd/cthreads.c
index e0cf4dd..2d61642 100644
--- a/sysdeps/mach/hurd/cthreads.c
+++ b/sysdeps/mach/hurd/cthreads.c
@@ -19,6 +19,8 @@
 #include <errno.h>
 #include <stdlib.h>
 
+char __libc_lock_self0[0];
+
 /* Placeholder for key creation routine from Hurd cthreads library.  */
 int
 weak_function
diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c
index c46342b..1815d2f 100644
--- a/sysdeps/mach/hurd/dl-sysdep.c
+++ b/sysdeps/mach/hurd/dl-sysdep.c
@@ -69,25 +69,6 @@ void *_dl_random attribute_relro = NULL;
 
 struct hurd_startup_data *_dl_hurd_data;
 
-/* This is used only within ld.so, via dl-minimal.c's __errno_location.  */
-#undef errno
-int errno attribute_hidden;
-
-/* Defining these variables here avoids the inclusion of hurdsig.c.  */
-unsigned long int __hurd_sigthread_stack_base;
-unsigned long int __hurd_sigthread_stack_end;
-unsigned long int *__hurd_sigthread_variables;
-
-/* Defining these variables here avoids the inclusion of init-first.c.
-   We need to provide temporary storage for the per-thread variables
-   of the main user thread here, since it is used for storing the
-   `errno' variable.  Note that this information is lost once we
-   relocate the dynamic linker.  */
-static unsigned long int threadvars[_HURD_THREADVAR_MAX];
-unsigned long int __hurd_threadvar_stack_offset
-  = (unsigned long int) &threadvars;
-unsigned long int __hurd_threadvar_stack_mask;
-
 #define FMH defined(__i386__)
 #if ! FMH
 # define fmh()		((void)0)
diff --git a/sysdeps/mach/hurd/errno-loc.c b/sysdeps/mach/hurd/errno-loc.c
index 7b1e7ce..903d65d 100644
--- a/sysdeps/mach/hurd/errno-loc.c
+++ b/sysdeps/mach/hurd/errno-loc.c
@@ -16,13 +16,21 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <hurd/threadvar.h>
-
-int *
+#if IS_IN (rtld)
+/*
+ * rtld can not access TLS too early, thus rtld_errno.
+ *
+ * Instead of making __open/__close pass errno from TLS to rtld_errno, simply
+ * use a weak __errno_location using rtld_errno, which will be overriden by the
+ * libc definition.
+ */
+static int rtld_errno;
+int * weak_function
 __errno_location (void)
 {
-  return (int *) __hurd_threadvar_location (_HURD_THREADVAR_ERRNO);
+  return &rtld_errno;
 }
-strong_alias (__errno_location, __hurd_errno_location)
-libc_hidden_def (__errno_location)
+libc_hidden_weak (__errno_location)
+#else
+#include <../../../csu/errno-loc.c>
+#endif
diff --git a/sysdeps/mach/hurd/errno.c b/sysdeps/mach/hurd/errno.c
deleted file mode 100644
index a29091b..0000000
--- a/sysdeps/mach/hurd/errno.c
+++ /dev/null
@@ -1 +0,0 @@
-/* No definition of `errno' variable on the Hurd.  */
diff --git a/sysdeps/mach/hurd/fork.c b/sysdeps/mach/hurd/fork.c
index 984ef60..14dd17c 100644
--- a/sysdeps/mach/hurd/fork.c
+++ b/sysdeps/mach/hurd/fork.c
@@ -19,6 +19,7 @@
 #include <unistd.h>
 #include <hurd.h>
 #include <hurd/signal.h>
+#include <hurd/threadvar.h>
 #include <setjmp.h>
 #include <thread_state.h>
 #include <sysdep.h>		/* For stack growth direction.  */
@@ -512,19 +513,17 @@ __fork (void)
 				    (natural_t *) &state, &statecount))
 	LOSE;
 #ifdef STACK_GROWTH_UP
-#define THREADVAR_SPACE (__hurd_threadvar_max \
-			 * sizeof *__hurd_sightread_variables)
       if (__hurd_sigthread_stack_base == 0)
 	{
 	  state.SP &= __hurd_threadvar_stack_mask;
-	  state.SP += __hurd_threadvar_stack_offset + THREADVAR_SPACE;
+	  state.SP += __hurd_threadvar_stack_offset;
 	}
       else
 	state.SP = __hurd_sigthread_stack_base;
 #else
       if (__hurd_sigthread_stack_end == 0)
 	{
-	  /* The signal thread has a normal stack assigned by cthreads.
+	  /* The signal thread has a stack assigned by cthreads.
 	     The threadvar_stack variables conveniently tell us how
 	     to get to the highest address in the stack, just below
 	     the per-thread variables.  */
diff --git a/sysdeps/mach/hurd/i386/init-first.c b/sysdeps/mach/hurd/i386/init-first.c
index d75f24c..7d0ea1b 100644
--- a/sysdeps/mach/hurd/i386/init-first.c
+++ b/sysdeps/mach/hurd/i386/init-first.c
@@ -147,15 +147,6 @@ init (int *data)
   char **argv = (void *) (data + 1);
   char **envp = &argv[argc + 1];
   struct hurd_startup_data *d;
-  unsigned long int threadvars[_HURD_THREADVAR_MAX];
-
-  /* Provide temporary storage for thread-specific variables on the
-     startup stack so the cthreads initialization code can use them
-     for malloc et al, or so we can use malloc below for the real
-     threadvars array.  */
-  memset (threadvars, 0, sizeof threadvars);
-  threadvars[_HURD_THREADVAR_LOCALE] = (unsigned long int) &_nl_global_locale;
-  __hurd_threadvar_stack_offset = (unsigned long int) threadvars;
 
   /* Since the cthreads initialization code uses malloc, and the
      malloc initialization code needs to get at the environment, make
@@ -203,13 +194,6 @@ init (int *data)
     __pthread_initialize_minimal ();
 #endif
 
-  /* The user might have defined a value for this, to get more variables.
-     Otherwise it will be zero on startup.  We must make sure it is set
-     properly before before cthreads initialization, so cthreads can know
-     how much space to leave for thread variables.  */
-  if (__hurd_threadvar_max < _HURD_THREADVAR_MAX)
-    __hurd_threadvar_max = _HURD_THREADVAR_MAX;
-
 
   /* After possibly switching stacks, call `init1' (above) with the user
      code as the return address, and the argument data immediately above
@@ -225,11 +209,6 @@ init (int *data)
 
       __libc_stack_end = newsp;
 
-      /* Copy per-thread variables from that temporary
-	 area onto the new cthread stack.  */
-      memcpy (__hurd_threadvar_location_from_sp (0, newsp),
-	      threadvars, sizeof threadvars);
-
       /* Copy the argdata from the old stack to the new one.  */
       newsp = memcpy (newsp - ((char *) &d[1] - (char *) data), data,
 		      (char *) d - (char *) data);
@@ -270,25 +249,10 @@ init (int *data)
     }
   else
     {
-      /* We are not using cthreads, so we will have just a single allocated
-	 area for the per-thread variables of the main user thread.  */
-      unsigned long int *array;
-      unsigned int i;
       int usercode;
 
       void call_init1 (void);
 
-      array = malloc (__hurd_threadvar_max * sizeof (unsigned long int));
-      if (array == NULL)
-	__libc_fatal ("Can't allocate single-threaded thread variables.");
-
-      /* Copy per-thread variables from the temporary array into the
-	 newly malloc'd space.  */
-      memcpy (array, threadvars, sizeof threadvars);
-      __hurd_threadvar_stack_offset = (unsigned long int) array;
-      for (i = _HURD_THREADVAR_MAX; i < __hurd_threadvar_max; ++i)
-	array[i] = 0;
-
       /* The argument data is just above the stack frame we will unwind by
 	 returning.  Mutate our own return address to run the code below.  */
       /* The following expression would typically be written as
diff --git a/sysdeps/mach/hurd/i386/sigreturn.c b/sysdeps/mach/hurd/i386/sigreturn.c
index 8ec1d4b..07633e1 100644
--- a/sysdeps/mach/hurd/i386/sigreturn.c
+++ b/sysdeps/mach/hurd/i386/sigreturn.c
@@ -68,7 +68,7 @@ __sigreturn (struct sigcontext *scp)
 
   if (scp->sc_onstack)
     {
-      ss->sigaltstack.ss_flags &= ~SS_ONSTACK; /* XXX threadvars */
+      ss->sigaltstack.ss_flags &= ~SS_ONSTACK;
       /* XXX cannot unlock until off sigstack */
       abort ();
     }
@@ -77,8 +77,7 @@ __sigreturn (struct sigcontext *scp)
 
   /* Destroy the MiG reply port used by the signal handler, and restore the
      reply port in use by the thread when interrupted.  */
-  reply_port =
-    (mach_port_t *) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY);
+  reply_port = &__hurd_local_reply_port;
   if (*reply_port)
     {
       mach_port_t port = *reply_port;
diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h
index 0ff0474..adaa580 100644
--- a/sysdeps/mach/hurd/i386/tls.h
+++ b/sysdeps/mach/hurd/i386/tls.h
@@ -43,6 +43,10 @@ typedef struct
   void *__private_tm[4];
   /* GCC split stack support.  */
   void *__private_ss;
+
+  /* Keep this field last */
+  mach_port_t reply_port;      /* This thread's reply port.  */
+  struct hurd_sigstate *_hurd_sigstate;
 } tcbhead_t;
 #endif
 
@@ -89,6 +93,17 @@ typedef struct
       | (((unsigned int) (tcb)) & 0xff000000) /* base 24..31 */		      \
     }
 
+# define HURD_DESC_TLS(desc)						      \
+  ({									      \
+   (tcbhead_t *) (   (desc->low_word >> 16)				      \
+                  | ((desc->high_word & 0xff) << 16)			      \
+                  |  (desc->high_word & 0xff000000)			      \
+     );})
+
+#define __LIBC_NO_TLS()							      \
+  ({ unsigned short ds, gs;						      \
+     asm ("movw %%ds,%w0; movw %%gs,%w1" : "=q" (ds), "=q" (gs));	      \
+     ds == gs; })
 
 static inline const char * __attribute__ ((unused))
 _hurd_tls_init (tcbhead_t *tcb)
@@ -139,6 +154,20 @@ _hurd_tls_init (tcbhead_t *tcb)
 	      : "i" (offsetof (tcbhead_t, tcb)));			      \
      __tcb;})
 
+/* Return the TCB address of a thread given its state.  */
+# define THREAD_TCB(thread, thread_state)				      \
+  ({ int __sel = (thread_state)->basic.gs;				      \
+     struct descriptor __desc, *___desc = &__desc;			      \
+     unsigned int __count = 1;						      \
+     kern_return_t __err;						      \
+     if (__builtin_expect (__sel, 0x48) & 4) /* LDT selector */		      \
+       __err = __i386_get_ldt ((thread), __sel, 1, &___desc, &__count);	      \
+     else								      \
+       __err = __i386_get_gdt ((thread), __sel, &__desc);		      \
+     assert_perror (__err);						      \
+     assert (__count == 1);						      \
+     HURD_DESC_TLS(___desc);})
+
 /* Install new dtv for current thread.  */
 # define INSTALL_NEW_DTV(dtvp)						      \
   ({ asm volatile ("movl %0,%%gs:%P1"					      \
diff --git a/sysdeps/mach/hurd/libc-lock.h b/sysdeps/mach/hurd/libc-lock.h
index 2811b64..b7fffd0 100644
--- a/sysdeps/mach/hurd/libc-lock.h
+++ b/sysdeps/mach/hurd/libc-lock.h
@@ -24,7 +24,6 @@
 #  include <tls.h>
 # endif
 #include <cthreads.h>
-#include <hurd/threadvar.h>
 
 /* The locking here is very inexpensive, even for inlining.  */
 #define _IO_lock_inexpensive  1
@@ -38,7 +37,8 @@ typedef struct
 } __libc_lock_recursive_t;
 typedef __libc_lock_recursive_t __rtld_lock_recursive_t;
 
-#define __libc_lock_owner_self() ((void *) __hurd_threadvar_location (0))
+extern char __libc_lock_self0[0];
+#define __libc_lock_owner_self() (__LIBC_NO_TLS() ? &__libc_lock_self0 : THREAD_SELF)
 
 #else
 typedef struct __libc_lock_opaque__ __libc_lock_t;
diff --git a/sysdeps/mach/hurd/libc-tsd.h b/sysdeps/mach/hurd/libc-tsd.h
deleted file mode 100644
index fa131a2..0000000
--- a/sysdeps/mach/hurd/libc-tsd.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/* libc-internal interface for thread-specific data.  Hurd version.
-   Copyright (C) 1998-2018 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, see
-   <http://www.gnu.org/licenses/>.  */
-
-#ifndef _LIBC_TSD_H
-#define _LIBC_TSD_H 1
-
-#include <hurd/threadvar.h>
-
-#define __libc_tsd_define(CLASS, TYPE, KEY) /* nothing, always have threadvars */
-
-#define __libc_tsd_address(TYPE, KEY) \
-  ((TYPE *) __hurd_threadvar_location (_HURD_THREADVAR_##KEY))
-
-#define __libc_tsd_get(TYPE, KEY) \
-  (*__libc_tsd_address (TYPE, KEY))
-#define __libc_tsd_set(TYPE, KEY, VALUE) \
-  (*__libc_tsd_address (TYPE, KEY) = (VALUE))
-
-#endif	/* libc-tsd.h */
diff --git a/sysdeps/mach/hurd/mig-reply.c b/sysdeps/mach/hurd/mig-reply.c
index ed3705d..ddad12e 100644
--- a/sysdeps/mach/hurd/mig-reply.c
+++ b/sysdeps/mach/hurd/mig-reply.c
@@ -18,26 +18,20 @@
 #include <mach.h>
 #include <hurd/threadvar.h>
 
-#define GETPORT \
-  mach_port_t *portloc = \
-    (mach_port_t *) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY)
-#define reply_port (*(use_threadvar ? portloc : &global_reply_port))
-
-static int use_threadvar;
-static mach_port_t global_reply_port;
-
 /* These functions are called by MiG-generated code.  */
 
+mach_port_t __hurd_reply_port0;
+
 /* Called by MiG to get a reply port.  */
 mach_port_t
 __mig_get_reply_port (void)
 {
-  GETPORT;
-
-  if (reply_port == MACH_PORT_NULL)
-    reply_port = __mach_reply_port ();
+  if (__hurd_local_reply_port == MACH_PORT_NULL ||
+      (&__hurd_local_reply_port != &__hurd_reply_port0
+       && __hurd_local_reply_port == __hurd_reply_port0))
+    __hurd_local_reply_port = __mach_reply_port ();
 
-  return reply_port;
+  return __hurd_local_reply_port;
 }
 weak_alias (__mig_get_reply_port, mig_get_reply_port)
 
@@ -45,12 +39,8 @@ weak_alias (__mig_get_reply_port, mig_get_reply_port)
 void
 __mig_dealloc_reply_port (mach_port_t arg)
 {
-  mach_port_t port;
-
-  GETPORT;
-
-  port = reply_port;
-  reply_port = MACH_PORT_NULL;	/* So the mod_refs RPC won't use it.  */
+  mach_port_t port = __hurd_local_reply_port;
+  __hurd_local_reply_port = MACH_PORT_NULL;	/* So the mod_refs RPC won't use it.  */
 
   if (MACH_PORT_VALID (port))
     __mach_port_mod_refs (__mach_task_self (), port,
@@ -73,15 +63,6 @@ weak_alias (__mig_put_reply_port, mig_put_reply_port)
 void
 __mig_init (void *stack)
 {
-  use_threadvar = stack != 0;
-
-  if (use_threadvar)
-    {
-      /* Recycle the reply port used before multithreading was enabled.  */
-      mach_port_t *portloc = (mach_port_t *)
-	__hurd_threadvar_location_from_sp (_HURD_THREADVAR_MIG_REPLY, stack);
-      *portloc = global_reply_port;
-      global_reply_port = MACH_PORT_NULL;
-    }
+  /* Do nothing.  */
 }
 weak_alias (__mig_init, mig_init)
diff --git a/sysdeps/mach/hurd/profil.c b/sysdeps/mach/hurd/profil.c
index 7206345..45f83a9 100644
--- a/sysdeps/mach/hurd/profil.c
+++ b/sysdeps/mach/hurd/profil.c
@@ -141,7 +141,7 @@ __profil (u_short *sample_buffer, size_t size, size_t offset, u_int scale)
 weak_alias (__profil, profil)
 
 /* Fetch PC samples.  This function must be very careful not to depend
-   on Hurd threadvar variables.  We arrange that by using a special
+   on Hurd TLS variables.  We arrange that by using a special
    stub arranged for at the end of this file. */
 static void
 fetch_samples (void)
@@ -177,7 +177,7 @@ fetch_samples (void)
 }
 
 
-/* This function must be very careful not to depend on Hurd threadvar
+/* This function must be very careful not to depend on Hurd TLS
    variables.  We arrange that by using special stubs arranged for at the
    end of this file. */
 static void
@@ -268,7 +268,7 @@ text_set_element (_hurd_fork_child_hook, fork_profil_child);
    are fatal in profile_waiter anyhow. */
 #define __mig_put_reply_port(foo)
 
-/* Use our static variable instead of the usual threadvar mechanism for
+/* Use our static variable instead of the usual TLS mechanism for
    this. */
 #define __mig_get_reply_port() profil_reply_port
 

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=57c6448970a3e6c54955d915e3bbbcc433902357

commit 57c6448970a3e6c54955d915e3bbbcc433902357
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Fri Jan 19 01:37:03 2018 +0100

    t2.26/sigsetops.h
    
    Include <sigsetops.h> from hurd/hurd/signal.h
    
    * hurd/hurd/signal.h [__USE_EXTERN_INLINES][_LIBC][IS_IN(libc)]: Include
    <sigsetops.h>.
    
    Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

diff --git a/hurd/hurd/signal.h b/hurd/hurd/signal.h
index 971a0e3..233d10f 100644
--- a/hurd/hurd/signal.h
+++ b/hurd/hurd/signal.h
@@ -42,6 +42,11 @@
 #include <spin-lock.h>
 #include <hurd/threadvar.h>	/* We cache sigstate in a threadvar.  */
 struct hurd_signal_preemptor;	/* <hurd/sigpreempt.h> */
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+#  if IS_IN (libc)
+#    include <sigsetops.h>
+#  endif
+#endif
 
 
 /* Full details of a signal.  */

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=8b83394a95641b4b4e22f845ab655958df8175e8

commit 8b83394a95641b4b4e22f845ab655958df8175e8
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Fri Jan 19 01:20:55 2018 +0100

    t2.26/sched_param
    
    Bring back __sched_param to bits/sched.h
    
    Upstream removed it because it doesn't use it, but we do: our pthread.h
    includes thread-attr.h to bring the pthread_attr_t type to applications,
    and thus needs the sched_param structure.
    
    Note: that uses __sched_param and not sched_param because thread-attr.h
    is also also brought in from sys/types.h, which should not expose
    sched_param if not requested to by applicationg defining _POSIX_SOURCE
    and alike.
    
    Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

diff --git a/bits/sched.h b/bits/sched.h
index 8d9f077..486473e 100644
--- a/bits/sched.h
+++ b/bits/sched.h
@@ -17,6 +17,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef __need_schedparam
+
 #ifndef _BITS_SCHED_H
 #define _BITS_SCHED_H 1
 
@@ -32,7 +34,20 @@
 /* Data structure to describe a process' schedulability.  */
 struct sched_param
 {
-  int sched_priority;
+  int __sched_priority;
 };
 
 #endif /* bits/sched.h */
+
+#endif	/* need schedparam */
+
+#if !defined __defined_schedparam \
+    && (defined __need_schedparam || defined _SCHED_H)
+# define __defined_schedparam	1
+/* Data structure to describe a process' schedulability.  */
+struct __sched_param
+  {
+    int __sched_priority;
+  };
+# undef __need_schedparam
+#endif
diff --git a/posix/sched.h b/posix/sched.h
index 619b3b3..67691a1 100644
--- a/posix/sched.h
+++ b/posix/sched.h
@@ -43,9 +43,8 @@ typedef __pid_t pid_t;
 #include <bits/sched.h>
 #include <bits/cpu-set.h>
 
-/* Backward compatibility.  */
-#define sched_priority    sched_priority
-#define __sched_priority  sched_priority
+/* Define the real names for the elements of `struct sched_param'.  */
+#define sched_priority    __sched_priority
 
 
 __BEGIN_DECLS

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=c46271c54a76da97aea48a80965381dff94774d6

commit c46271c54a76da97aea48a80965381dff94774d6
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Thu Jan 18 23:53:22 2018 +0100

    t2.25/tls
    
    Fix tls support for glibc 2.25
    
    * csu/libc-start.c (LIBC_START_MAIN) [__GNU__]: Do not call
    __libc_setup_tls.
    * sysdeps/mach/hurd/i386/init-first.c (init): Call __libc_setup_tls.
    
    Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

diff --git a/csu/libc-start.c b/csu/libc-start.c
index 605222f..8e92cc0 100644
--- a/csu/libc-start.c
+++ b/csu/libc-start.c
@@ -193,8 +193,10 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
   /* Perform IREL{,A} relocations.  */
   ARCH_SETUP_IREL ();
 
+#ifndef __GNU__
   /* The stack guard goes into the TCB, so initialize it early.  */
   __libc_setup_tls ();
+#endif
 
   /* In some architectures, IREL{,A} relocations happen after TLS setup in
      order to let IFUNC resolvers benefit from TCB information, e.g. powerpc's
diff --git a/sysdeps/mach/hurd/i386/init-first.c b/sysdeps/mach/hurd/i386/init-first.c
index 82b9cb2..d75f24c 100644
--- a/sysdeps/mach/hurd/i386/init-first.c
+++ b/sysdeps/mach/hurd/i386/init-first.c
@@ -196,7 +196,8 @@ init (int *data)
       assert (d->phdrsz % sizeof (ElfW(Phdr)) == 0);
     }
 
-  /* We need to setup TLS before starting the signal thread.  */
+  /* We need to setup TLS before starting sigthread and set stack guard.  */
+  __libc_setup_tls ();
   extern void __pthread_initialize_minimal (void);
   if (__pthread_initialize_minimal != NULL)
     __pthread_initialize_minimal ();

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=e3ffb01283e9c8e30a3cd4736ed5f090ef0aeca3

commit e3ffb01283e9c8e30a3cd4736ed5f090ef0aeca3
Author: Samuel Thibault <samuel.thibault@gnu.org>
Date:   Thu Jan 18 23:49:53 2018 +0100

    t/tls
    
    hurd: add TLS support
    
    2009-07-30  Samuel Thibault  <samuel.thibault@gnu.org>
    
    	Add TLS support: __mach_setup_tls allocates and sets
    	architecture state for the TLS area.  i386 fork needs to
    	propagate the segment kernel definitions.
    
    	* sysdeps/mach/hurd/bits/libc-lock.h [_LIBC - 0]: Include <tls.h>
    	* sysdeps/mach/hurd/tls.h: Include <stdint.h> and <sysdep.h>
    	* include/errno.h (__GNU__): Do not define TLS errno for now.
    
    	* sysdeps/generic/thread_state.h (MACHINE_NEW_THREAD_STATE_FLAVOR): New
    	macro.
    	* sysdeps/mach/thread_state.h (MACHINE_THREAD_STATE_FIX_NEW): New macro.
    	* sysdeps/mach/i386/thread_state.h (MACHINE_NEW_THREAD_STATE_FLAVOR):
    	New macro, defined to i386_THREAD_STATE.
    	(MACHINE_THREAD_STATE_FLAVOR): Define to i386_REGS_SEGS_STATE instead
    	of i386_THREAD_STATE.
    	(MACHINE_THREAD_STATE_FIX_NEW): New macro, reads segments.
    
    	* sysdeps/mach/hurd/i386/trampoline.c (_hurd_setup_sighandler): Use
    	i386_REGS_SEGS_STATE instead of i386_THREAD_STATE.
    
    	* sysdeps/mach/hurd/i386/tls.h (__i386_selector_is_ldt): New
    	macro.
    	(_hurd_tls_init): Use kern_return_t error type.  Use
    	__i386_selector_is_ldt to test for LDT segment type.
    	(_hurd_tls_fork): Use kern_return_t error type.  Duplicate existing LDT
    	descriptor instead of creating a new one.
    	(_hurd_tls_new): New function, creates a new descriptor and updates tcb.
    
    	* mach/mach.h (__mach_setup_tls,mach_setup_tls): Add declarations.
    	* mach/setup-thread.c: Include <ldsodefs.h>.
    	(__mach_setup_thread): Use MACHINE_NEW_THREAD_STATE_FLAVOR instead of
    	MACHINE_THREAD_STATE_FLAVOR.
    	(__mach_setup_tls): New function.
    	* hurd/hurdfault.c (_hurdsig_fault_init): Call
    	MACHINE_THREAD_STATE_FIX_NEW.
    
    	* sysdeps/mach/hurd/profil.c (update_waiter): Call __mach_setup_tls.
    	* sysdeps/mach/hurd/setitimer.c (setitimer_locked): Call
    	__mach_setup_tls.
    	* hurd/hurdsig.c (_hurdsig_init): Call __mach_setup_tls.
    	* sysdeps/mach/hurd/fork.c (__fork): Call _hurd_tls_fork for
    	sigthread.  Pass kernel thread to _hurd_tls_fork.
    	* sysdeps/mach/hurd/i386/init-first.c (init): Move ELF header parsing
    	after getting up the environment pointer.  Call
    	__pthread_initialize_minimal.
    	* csu/libc-start.c (LIBC_START_MAIN) [__GNU__]: Do not call
    	__pthread_initialize_minimal.

diff --git a/hurd/hurdfault.c b/hurd/hurdfault.c
index b5a4056..794def7 100644
--- a/hurd/hurdfault.c
+++ b/hurd/hurdfault.c
@@ -204,6 +204,8 @@ _hurdsig_fault_init (void)
   /* This state will be restored when we fault.
      It runs the function above.  */
   memset (&state, 0, sizeof state);
+
+  MACHINE_THREAD_STATE_FIX_NEW (&state);
   MACHINE_THREAD_STATE_SET_PC (&state, faulted);
   MACHINE_THREAD_STATE_SET_SP (&state, faultstack, sizeof faultstack);
 
diff --git a/hurd/hurdsig.c b/hurd/hurdsig.c
index 4f5bb9a..3e587a4 100644
--- a/hurd/hurdsig.c
+++ b/hurd/hurdsig.c
@@ -1266,6 +1266,8 @@ _hurdsig_init (const int *intarray, size_t intarraysize)
 				 (vm_address_t *) &__hurd_sigthread_stack_base,
 				 &stacksize);
       assert_perror (err);
+      err = __mach_setup_tls (_hurd_msgport_thread);
+      assert_perror (err);
 
       __hurd_sigthread_stack_end = __hurd_sigthread_stack_base + stacksize;
       __hurd_sigthread_variables =
diff --git a/include/errno.h b/include/errno.h
index 3c3d228..89353aa 100644
--- a/include/errno.h
+++ b/include/errno.h
@@ -24,13 +24,15 @@ extern int rtld_errno attribute_hidden;
 
 #  include <tls.h>
 
-#  undef  errno
-#  if IS_IN (libc)
-#   define errno __libc_errno
-#  else
-#   define errno errno		/* For #ifndef errno tests.  */
-#  endif
+#  if !defined __GNU__
+#   undef  errno
+#   if IS_IN (libc)
+#    define errno __libc_errno
+#   else
+#    define errno errno		/* For #ifndef errno tests.  */
+#   endif
 extern __thread int errno attribute_tls_model_ie;
+#  endif
 
 # endif	/* IS_IN_LIB */
 
diff --git a/mach/mach.h b/mach/mach.h
index 684be91..93398b0 100644
--- a/mach/mach.h
+++ b/mach/mach.h
@@ -96,5 +96,8 @@ kern_return_t mach_setup_thread (task_t task, thread_t thread, void *pc,
 				 vm_address_t *stack_base,
 				 vm_size_t *stack_size);
 
+/* Give THREAD a TLS area.  */
+kern_return_t __mach_setup_tls (thread_t thread);
+kern_return_t mach_setup_tls (thread_t thread);
 
 #endif	/* mach.h */
diff --git a/mach/setup-thread.c b/mach/setup-thread.c
index 2eeacc2..972b355 100644
--- a/mach/setup-thread.c
+++ b/mach/setup-thread.c
@@ -19,6 +19,7 @@
 #include <thread_state.h>
 #include <string.h>
 #include <mach/machine/vm_param.h>
+#include <ldsodefs.h>
 #include "sysdep.h"		/* Defines stack direction.  */
 
 #define	STACK_SIZE	(16 * 1024 * 1024) /* 16MB, arbitrary.  */
@@ -72,8 +73,35 @@ __mach_setup_thread (task_t task, thread_t thread, void *pc,
   if (error = __vm_protect (task, stack, __vm_page_size, 0, VM_PROT_NONE))
     return error;
 
-  return __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
+  return __thread_set_state (thread, MACHINE_NEW_THREAD_STATE_FLAVOR,
 			     (natural_t *) &ts, tssize);
 }
 
 weak_alias (__mach_setup_thread, mach_setup_thread)
+
+/* Give THREAD a TLS area.  */
+kern_return_t
+__mach_setup_tls (thread_t thread)
+{
+  kern_return_t error;
+  struct machine_thread_state ts;
+  mach_msg_type_number_t tssize = MACHINE_THREAD_STATE_COUNT;
+  tcbhead_t *tcb;
+
+  if (error = __thread_get_state (thread, MACHINE_THREAD_STATE_FLAVOR,
+			     (natural_t *) &ts, &tssize))
+    return error;
+  assert (tssize == MACHINE_THREAD_STATE_COUNT);
+
+  tcb = _dl_allocate_tls (NULL);
+  if (tcb == NULL)
+    return KERN_RESOURCE_SHORTAGE;
+
+  _hurd_tls_new (thread, &ts, tcb);
+
+  error = __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
+			     (natural_t *) &ts, tssize);
+  return error;
+}
+
+weak_alias (__mach_setup_tls, mach_setup_tls)
diff --git a/sysdeps/generic/thread_state.h b/sysdeps/generic/thread_state.h
index 32994c3..7c61dbc 100644
--- a/sysdeps/generic/thread_state.h
+++ b/sysdeps/generic/thread_state.h
@@ -22,6 +22,7 @@
 
 /* Replace <machine> with "i386" or "mips" or whatever.  */
 
+#define MACHINE_NEW_THREAD_STATE_FLAVOR	<machine>_NEW_THREAD_STATE
 #define MACHINE_THREAD_STATE_FLAVOR	<machine>_THREAD_STATE
 #define MACHINE_THREAD_STATE_COUNT	<machine>_THREAD_STATE_COUNT
 
diff --git a/sysdeps/mach/hurd/fork.c b/sysdeps/mach/hurd/fork.c
index fe3f544..984ef60 100644
--- a/sysdeps/mach/hurd/fork.c
+++ b/sysdeps/mach/hurd/fork.c
@@ -536,6 +536,11 @@ __fork (void)
 #endif
       MACHINE_THREAD_STATE_SET_PC (&state,
 				   (unsigned long int) _hurd_msgport_receive);
+
+      /* Do special thread setup for TLS if needed.  */
+      if (err = _hurd_tls_fork (sigthread, _hurd_msgport_thread, &state))
+	LOSE;
+
       if (err = __thread_set_state (sigthread, MACHINE_THREAD_STATE_FLAVOR,
 				    (natural_t *) &state, statecount))
 	LOSE;
@@ -546,7 +551,7 @@ __fork (void)
       _hurd_longjmp_thread_state (&state, env, 1);
 
       /* Do special thread setup for TLS if needed.  */
-      if (err = _hurd_tls_fork (thread, &state))
+      if (err = _hurd_tls_fork (thread, ss->thread, &state))
 	LOSE;
 
       if (err = __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
diff --git a/sysdeps/mach/hurd/i386/init-first.c b/sysdeps/mach/hurd/i386/init-first.c
index 965b53c..82b9cb2 100644
--- a/sysdeps/mach/hurd/i386/init-first.c
+++ b/sysdeps/mach/hurd/i386/init-first.c
@@ -109,32 +109,10 @@ init1 (int argc, char *arg0, ...)
      then after the environment pointers there is no Hurd
      data block; the argument strings start there.  */
   if ((void *) d == argv[0])
-    {
-#ifndef SHARED
-      /* With a new enough linker (binutils-2.23 or better),
-         the magic __ehdr_start symbol will be available and
-         __libc_start_main will have done this that way already.  */
-      if (_dl_phdr == NULL)
-        {
-          /* We may need to see our own phdrs, e.g. for TLS setup.
-             Try the usual kludge to find the headers without help from
-             the exec server.  */
-          extern const void __executable_start;
-          const ElfW(Ehdr) *const ehdr = &__executable_start;
-          _dl_phdr = (const void *) ehdr + ehdr->e_phoff;
-          _dl_phnum = ehdr->e_phnum;
-          assert (ehdr->e_phentsize == sizeof (ElfW(Phdr)));
-        }
-#endif
-      return;
-    }
+    return;
 
 #ifndef SHARED
   __libc_enable_secure = d->flags & EXEC_SECURE;
-
-  _dl_phdr = (ElfW(Phdr) *) d->phdr;
-  _dl_phnum = d->phdrsz / sizeof (ElfW(Phdr));
-  assert (d->phdrsz % sizeof (ElfW(Phdr)) == 0);
 #endif
 
   _hurd_init_dtable = d->dtable;
@@ -190,6 +168,40 @@ init (int *data)
     ++envp;
   d = (void *) ++envp;
 
+#ifndef SHARED
+  /* If we are the bootstrap task started by the kernel,
+     then after the environment pointers there is no Hurd
+     data block; the argument strings start there.  */
+  if ((void *) d == argv[0])
+    {
+      /* With a new enough linker (binutils-2.23 or better),
+	 the magic __ehdr_start symbol will be available and
+	 __libc_start_main will have done this that way already.  */
+      if (_dl_phdr == NULL)
+        {
+	  /* We may need to see our own phdrs, e.g. for TLS setup.
+	     Try the usual kludge to find the headers without help from
+	     the exec server.  */
+	  extern const void __executable_start;
+	  const ElfW(Ehdr) *const ehdr = &__executable_start;
+	  _dl_phdr = (const void *) ehdr + ehdr->e_phoff;
+	  _dl_phnum = ehdr->e_phnum;
+	  assert (ehdr->e_phentsize == sizeof (ElfW(Phdr)));
+        }
+    }
+  else
+    {
+      _dl_phdr = (ElfW(Phdr) *) d->phdr;
+      _dl_phnum = d->phdrsz / sizeof (ElfW(Phdr));
+      assert (d->phdrsz % sizeof (ElfW(Phdr)) == 0);
+    }
+
+  /* We need to setup TLS before starting the signal thread.  */
+  extern void __pthread_initialize_minimal (void);
+  if (__pthread_initialize_minimal != NULL)
+    __pthread_initialize_minimal ();
+#endif
+
   /* The user might have defined a value for this, to get more variables.
      Otherwise it will be zero on startup.  We must make sure it is set
      properly before before cthreads initialization, so cthreads can know
diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h
index b194a49..0ff0474 100644
--- a/sysdeps/mach/hurd/i386/tls.h
+++ b/sysdeps/mach/hurd/i386/tls.h
@@ -52,6 +52,15 @@ typedef struct
 #define TLS_TCB_AT_TP	1
 #define TLS_DTV_AT_TP	0
 
+/* Alignment requirement for TCB.
+
+   Some processors such as Intel Atom pay a big penalty on every
+   access using a segment override if that segment's base is not
+   aligned to the size of a cache line.  (See Intel 64 and IA-32
+   Architectures Optimization Reference Manual, section 13.3.3.3,
+   "Segment Base".)  On such machines, a cache line is 64 bytes.  */
+#define TCB_ALIGNMENT		64
+
 #ifndef __ASSEMBLER__
 
 /* Use i386-specific RPCs to arrange that %gs segment register prefix
@@ -62,6 +71,8 @@ typedef struct
 #  define __i386_set_gdt(thr, sel, desc) ((void) (thr), (void) (sel), (void) (desc), MIG_BAD_ID)
 # endif
 
+#define __i386_selector_is_ldt(sel) (!!((sel) & 4))
+
 # include <errno.h>
 # include <assert.h>
 
@@ -93,7 +104,7 @@ _hurd_tls_init (tcbhead_t *tcb)
 
   /* Get the first available selector.  */
   int sel = -1;
-  error_t err = __i386_set_gdt (tcb->self, &sel, desc);
+  kern_return_t err = __i386_set_gdt (tcb->self, &sel, desc);
   if (err == MIG_BAD_ID)
     {
       /* Old kernel, use a per-thread LDT.  */
@@ -141,9 +152,40 @@ _hurd_tls_init (tcbhead_t *tcb)
 
 # include <mach/machine/thread_status.h>
 
-/* Set up TLS in the new thread of a fork child, copying from our own.  */
-static inline error_t __attribute__ ((unused))
-_hurd_tls_fork (thread_t child, struct i386_thread_state *state)
+/* Set up TLS in the new thread of a fork child, copying from the original.  */
+static inline kern_return_t __attribute__ ((unused))
+_hurd_tls_fork (thread_t child, thread_t orig, struct i386_thread_state *state)
+{
+  /* Fetch the selector set by _hurd_tls_init.  */
+  int sel;
+  asm ("mov %%gs, %w0" : "=q" (sel) : "0" (0));
+  if (sel == state->ds)		/* _hurd_tls_init was never called.  */
+    return 0;
+
+  struct descriptor desc, *_desc = &desc;
+  kern_return_t err;
+  unsigned int count = 1;
+
+  if (__glibc_unlikely (__i386_selector_is_ldt(sel)))
+    err = __i386_get_ldt (orig, sel, 1, &_desc, &count);
+  else
+    err = __i386_get_gdt (orig, sel, &desc);
+
+  assert_perror (err);
+  if (err)
+    return err;
+
+  if (__glibc_unlikely (__i386_selector_is_ldt(sel)))
+    err = __i386_set_ldt (child, sel, &desc, 1);
+  else
+    err = __i386_set_gdt (child, &sel, desc);
+
+  state->gs = sel;
+  return err;
+}
+
+static inline kern_return_t __attribute__ ((unused))
+_hurd_tls_new (thread_t child, struct i386_thread_state *state, tcbhead_t *tcb)
 {
   /* Fetch the selector set by _hurd_tls_init.  */
   int sel;
@@ -151,11 +193,13 @@ _hurd_tls_fork (thread_t child, struct i386_thread_state *state)
   if (sel == state->ds)		/* _hurd_tls_init was never called.  */
     return 0;
 
-  tcbhead_t *const tcb = THREAD_SELF;
   HURD_TLS_DESC_DECL (desc, tcb);
-  error_t err;
+  kern_return_t err;
+
+  tcb->tcb = tcb;
+  tcb->self = child;
 
-  if (__builtin_expect (sel, 0x50) & 4) /* LDT selector */
+  if (__glibc_unlikely (__i386_selector_is_ldt(sel)))
     err = __i386_set_ldt (child, sel, &desc, 1);
   else
     err = __i386_set_gdt (child, &sel, desc);
diff --git a/sysdeps/mach/hurd/i386/trampoline.c b/sysdeps/mach/hurd/i386/trampoline.c
index d240ca7..0c68759 100644
--- a/sysdeps/mach/hurd/i386/trampoline.c
+++ b/sysdeps/mach/hurd/i386/trampoline.c
@@ -62,7 +62,7 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler,
 		  sizeof (state->basic));
 	  memcpy (&state->fpu, &ss->context->sc_i386_float_state,
 		  sizeof (state->fpu));
-	  state->set |= (1 << i386_THREAD_STATE) | (1 << i386_FLOAT_STATE);
+	  state->set |= (1 << i386_REGS_SEGS_STATE) | (1 << i386_FLOAT_STATE);
 	}
     }
 
diff --git a/sysdeps/mach/hurd/libc-lock.h b/sysdeps/mach/hurd/libc-lock.h
index 371912e..2811b64 100644
--- a/sysdeps/mach/hurd/libc-lock.h
+++ b/sysdeps/mach/hurd/libc-lock.h
@@ -20,6 +20,9 @@
 #define _LIBC_LOCK_H 1
 
 #if (_LIBC - 0) || (_CTHREADS_ - 0)
+# if (_LIBC - 0)
+#  include <tls.h>
+# endif
 #include <cthreads.h>
 #include <hurd/threadvar.h>
 
diff --git a/sysdeps/mach/hurd/profil.c b/sysdeps/mach/hurd/profil.c
index 1323457..7206345 100644
--- a/sysdeps/mach/hurd/profil.c
+++ b/sysdeps/mach/hurd/profil.c
@@ -70,6 +70,8 @@ update_waiter (u_short *sample_buffer, size_t size, size_t offset, u_int scale)
       if (! err)
 	err = __mach_setup_thread (__mach_task_self (), profile_thread,
 				   &profile_waiter, NULL, NULL);
+      if (! err)
+	err = __mach_setup_tls (profile_thread);
     }
   else
     err = 0;
diff --git a/sysdeps/mach/hurd/setitimer.c b/sysdeps/mach/hurd/setitimer.c
index a0d2941..ab18028 100644
--- a/sysdeps/mach/hurd/setitimer.c
+++ b/sysdeps/mach/hurd/setitimer.c
@@ -221,11 +221,12 @@ setitimer_locked (const struct itimerval *new, struct itimerval *old,
 	    goto out;
 	  _hurd_itimer_thread_stack_base = 0; /* Anywhere.  */
 	  _hurd_itimer_thread_stack_size = __vm_page_size; /* Small stack.  */
-	  if (err = __mach_setup_thread (__mach_task_self (),
+	  if ((err = __mach_setup_thread (__mach_task_self (),
 					 _hurd_itimer_thread,
 					 &timer_thread,
 					 &_hurd_itimer_thread_stack_base,
 					 &_hurd_itimer_thread_stack_size))
+	      || (err = __mach_setup_tls (_hurd_itimer_thread)))
 	    {
 	      __thread_terminate (_hurd_itimer_thread);
 	      _hurd_itimer_thread = MACH_PORT_NULL;
diff --git a/sysdeps/mach/i386/thread_state.h b/sysdeps/mach/i386/thread_state.h
index 56d91df..45910f5 100644
--- a/sysdeps/mach/i386/thread_state.h
+++ b/sysdeps/mach/i386/thread_state.h
@@ -21,7 +21,8 @@
 
 #include <mach/machine/thread_status.h>
 
-#define MACHINE_THREAD_STATE_FLAVOR	i386_THREAD_STATE
+#define MACHINE_NEW_THREAD_STATE_FLAVOR	i386_THREAD_STATE
+#define MACHINE_THREAD_STATE_FLAVOR	i386_REGS_SEGS_STATE
 #define MACHINE_THREAD_STATE_COUNT	i386_THREAD_STATE_COUNT
 
 #define machine_thread_state i386_thread_state
@@ -30,6 +31,14 @@
 #define SP uesp
 #define SYSRETURN eax
 
+#define MACHINE_THREAD_STATE_FIX_NEW(ts) do { \
+	asm ("mov %%cs, %w0" : "=q" ((ts)->cs)); \
+	asm ("mov %%ds, %w0" : "=q" ((ts)->ds)); \
+	asm ("mov %%es, %w0" : "=q" ((ts)->es)); \
+	asm ("mov %%fs, %w0" : "=q" ((ts)->fs)); \
+	asm ("mov %%gs, %w0" : "=q" ((ts)->gs)); \
+} while(0)
+
 struct machine_thread_all_state
   {
     int set;			/* Mask of bits (1 << FLAVOR).  */
diff --git a/sysdeps/mach/thread_state.h b/sysdeps/mach/thread_state.h
index bc4feef..b1c4e88 100644
--- a/sysdeps/mach/thread_state.h
+++ b/sysdeps/mach/thread_state.h
@@ -37,6 +37,9 @@
   ((ts)->SP = (unsigned long int) (stack) + (size))
 #endif
 #endif
+#ifndef MACHINE_THREAD_STATE_FIX_NEW
+# define MACHINE_THREAD_STATE_FIX_NEW(ts)
+#endif
 
 /* These functions are of use in machine-dependent signal trampoline
    implementations.  */

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=a985053e4e0b91944048b0be01d54e5360546a2f

commit a985053e4e0b91944048b0be01d54e5360546a2f
Author: Thomas Schwinge <thomas@schwinge.name>
Date:   Thu Jan 18 23:43:58 2018 +0100

    t/tlsdesc.sym
    
    i386 version of tlsdesc.sym for GNU Hurd.

diff --git a/sysdeps/mach/hurd/i386/tlsdesc.sym b/sysdeps/mach/hurd/i386/tlsdesc.sym
new file mode 100644
index 0000000..a358f7e
--- /dev/null
+++ b/sysdeps/mach/hurd/i386/tlsdesc.sym
@@ -0,0 +1,19 @@
+#include <stddef.h>
+#include <sysdep.h>
+#include <tls.h>
+#include <link.h>
+#include <dl-tlsdesc.h>
+
+--
+
+-- We have to override sysdeps/i386/tlsdesc.sym to adapt to our libpthread.
+
+-- Abuse tls.h macros to derive offsets relative to the thread register.
+
+DTV_OFFSET			offsetof(tcbhead_t, dtv)
+
+TLSDESC_ARG			offsetof(struct tlsdesc, arg)
+
+TLSDESC_GEN_COUNT		offsetof(struct tlsdesc_dynamic_arg, gen_count)
+TLSDESC_MODID			offsetof(struct tlsdesc_dynamic_arg, tlsinfo.ti_module)
+TLSDESC_MODOFF			offsetof(struct tlsdesc_dynamic_arg, tlsinfo.ti_offset)

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=45b377af53afecfa28d2fad0b05981f86dc17637

commit 45b377af53afecfa28d2fad0b05981f86dc17637
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Thu Jan 18 23:42:17 2018 +0100

    t/gai_misc
    
    Add a hurd version of threaded gai_misc.h
    
    Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

diff --git a/sysdeps/mach/hurd/gai_misc.h b/sysdeps/mach/hurd/gai_misc.h
new file mode 100644
index 0000000..ee8117f
--- /dev/null
+++ b/sysdeps/mach/hurd/gai_misc.h
@@ -0,0 +1,44 @@
+#include <signal.h>
+#include <pthread.h>
+
+#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);
+  sigprocmask(SIG_SETMASK, &ss, NULL);
+}
+
+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, 0x10000);
+
+  /* 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);
+  sigprocmask(SIG_SETMASK, &ss, &oss);
+
+  int ret = pthread_create (threadp, &attr, tf, arg);
+
+  /* Restore the signal mask.  */
+  sigprocmask(SIG_SETMASK, &oss, NULL);
+
+  (void) pthread_attr_destroy (&attr);
+  return ret;
+}
+
+#include_next <gai_misc.h>

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=210ac25cf1457f66534a60d348f60dd701ce4219

commit 210ac25cf1457f66534a60d348f60dd701ce4219
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Thu Jan 18 23:41:29 2018 +0100

    t/allocalim
    
    hurd: Fix allocalim build
    
    * sysdeps/pthread/allocalim.h [!PTHREAD_STACK_MIN]: Do not check size
    against PTHREAD_STACK_MIN.
    
    Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

diff --git a/sysdeps/pthread/allocalim.h b/sysdeps/pthread/allocalim.h
index b265d6f..4b42172 100644
--- a/sysdeps/pthread/allocalim.h
+++ b/sysdeps/pthread/allocalim.h
@@ -24,6 +24,9 @@ extern __always_inline
 int
 __libc_use_alloca (size_t size)
 {
-  return (__builtin_expect (size <= PTHREAD_STACK_MIN / 4, 1)
-	  || __builtin_expect (__libc_alloca_cutoff (size), 1));
+  return (
+#ifdef PTHREAD_STACK_MIN
+        __builtin_expect (size <= PTHREAD_STACK_MIN / 4, 1) ||
+#endif
+         __builtin_expect (__libc_alloca_cutoff (size), 1));
 }

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=0c7c687ec66a192e246c9eaa296ce2f6f7b1e579

commit 0c7c687ec66a192e246c9eaa296ce2f6f7b1e579
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Thu Jan 18 23:39:27 2018 +0100

    t/no-hp-timing
    
    We don't have support for hp timing for now, even the i686 variant, which needs
    to know the CPU speed.
    Copied from sysdeps/generic/hp-timing.h
    
    2010-08-21  Samuel Thibault  <samuel.thibault@ens-lyon.org>
    
    	* sysdeps/mach/hurd/hp-timing.h: New file.

diff --git a/sysdeps/mach/hurd/hp-timing.h b/sysdeps/mach/hurd/hp-timing.h
new file mode 100644
index 0000000..1246e21
--- /dev/null
+++ b/sysdeps/mach/hurd/hp-timing.h
@@ -0,0 +1,42 @@
+/* High precision, low overhead timing functions.  Generic version.
+   Copyright (C) 1998-2015 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along 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 _HP_TIMING_H
+#define _HP_TIMING_H	1
+
+/* We don't have support for high precision timing for now. */
+
+/* Provide dummy definitions.  */
+#define HP_TIMING_AVAIL		(0)
+#define HP_SMALL_TIMING_AVAIL	(0)
+#define HP_TIMING_INLINE	(0)
+typedef int hp_timing_t;
+#define HP_TIMING_ZERO(Var)
+#define HP_TIMING_NOW(var)
+#define HP_TIMING_DIFF_INIT()
+#define HP_TIMING_DIFF(Diff, Start, End)
+#define HP_TIMING_ACCUM(Sum, Diff)
+#define HP_TIMING_ACCUM_NT(Sum, Diff)
+#define HP_TIMING_PRINT(Buf, Len, Val)
+
+/* Since this implementation is not available we tell the user about it.  */
+#define HP_TIMING_NONAVAIL	1
+
+#endif	/* hp-timing.h */

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=203aabc697bafaccab48a1a4927e8ff7e43f3b4f

commit 203aabc697bafaccab48a1a4927e8ff7e43f3b4f
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Thu Jan 18 23:38:57 2018 +0100

    t/posix_thread
    
    Declare that we have a libpthread.
    
    The additional version in Versions.def should be updated when we'd
    actually get the libpthread commited into glibc (as well as in
    libpthread/Versions).
    
    Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

diff --git a/sysdeps/mach/hurd/Makefile b/sysdeps/mach/hurd/Makefile
index f0d3373..f9adbcf 100644
--- a/sysdeps/mach/hurd/Makefile
+++ b/sysdeps/mach/hurd/Makefile
@@ -170,6 +170,10 @@ $(objpfx)librtld.map: $(rpcuserlibs:.so=_pic.a)
 CFLAGS-dl-load.c = -DEXTERNAL_MAP_FROM_FD
 endif
 
+ifeq ($(subdir),posix)
+CFLAGS-confstr.c += -DLIBPTHREAD_VERSION='"libpthread 0.3"'
+endif
+
 # Override the generic Makeconfig values so we link against the RPC libs.
 link-libc-static := -Wl,--start-group \
 		    $(patsubst %,$(common-objpfx)%.a,\
diff --git a/sysdeps/mach/hurd/bits/local_lim.h b/sysdeps/mach/hurd/bits/local_lim.h
index 8a1af91..97f87ad 100644
--- a/sysdeps/mach/hurd/bits/local_lim.h
+++ b/sysdeps/mach/hurd/bits/local_lim.h
@@ -32,3 +32,12 @@
    suitable, and `sysconf' will return a number at least as large.  */
 
 #define NGROUPS_MAX	256
+
+/* The number of data keys per process.  */
+#define _POSIX_THREAD_KEYS_MAX	128
+
+/* Controlling the iterations of destructors for thread-specific data.  */
+#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS	4
+
+/* The number of threads per process.  */
+#define _POSIX_THREAD_THREADS_MAX	64
diff --git a/sysdeps/mach/hurd/bits/posix_opt.h b/sysdeps/mach/hurd/bits/posix_opt.h
index f299e3f..5f08319 100644
--- a/sysdeps/mach/hurd/bits/posix_opt.h
+++ b/sysdeps/mach/hurd/bits/posix_opt.h
@@ -71,24 +71,38 @@
 /* XPG4.2 shared memory is not supported.  */
 #undef	_XOPEN_SHM
 
-/* We do not have the POSIX threads interface.  */
-#define _POSIX_THREADS	-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	200809L
 
-/* These are all things that won't be supported when _POSIX_THREADS is not.  */
+/* We do not provide priority scheduling for threads.  */
 #define _POSIX_THREAD_PRIORITY_SCHEDULING	-1
-#define _POSIX_THREAD_ATTR_STACKSIZE		-1
-#define _POSIX_THREAD_ATTR_STACKADDR		-1
+
+/* We support user-defined stack sizes.  */
+#define _POSIX_THREAD_ATTR_STACKSIZE	200112L
+
+/* We support user-defined stacks.  */
+#define _POSIX_THREAD_ATTR_STACKADDR	200112L
+
+/* We do not support priority inheritence.  */
 #define _POSIX_THREAD_PRIO_INHERIT		-1
+
+/* We do not support priority protection.  */
 #define _POSIX_THREAD_PRIO_PROTECT		-1
+
 #ifdef __USE_XOPEN2K8
+/* We do not support priority inheritence for robust mutexes.  */
 # define _POSIX_THREAD_ROBUST_PRIO_INHERIT	-1
+
+/* We do not support priority protection for robust mutexes.  */
 # define _POSIX_THREAD_ROBUST_PRIO_PROTECT	-1
 #endif
-#define _POSIX_SEMAPHORES			-1
+
+/* We support POSIX.1b semaphores.  */
+#define _POSIX_SEMAPHORES			200112L
 
 /* Real-time signals are not yet supported.  */
 #define _POSIX_REALTIME_SIGNALS	-1
@@ -121,17 +135,17 @@
 /* GNU libc provides regular expression handling.  */
 #define _POSIX_REGEXP	1
 
-/* Reader/Writer locks are not available.  */
-#define _POSIX_READER_WRITER_LOCKS	-1
+/* Reader/Writer locks are available.  */
+#define _POSIX_READER_WRITER_LOCKS	200112L
 
 /* We have a POSIX shell.  */
 #define _POSIX_SHELL	1
 
-/* We cannot support the Timeouts option without _POSIX_THREADS.  */
-#define _POSIX_TIMEOUTS	-1
+/* We support the Timeouts option.  */
+#define _POSIX_TIMEOUTS	200112L
 
-/* We do not support spinlocks.  */
-#define _POSIX_SPIN_LOCKS	-1
+/* We support spinlocks.  */
+#define _POSIX_SPIN_LOCKS	200112L
 
 /* The `spawn' function family is supported.  */
 #define _POSIX_SPAWN	200809L
@@ -139,8 +153,8 @@
 /* We do not have POSIX timers, but could in future without ABI change.  */
 #define _POSIX_TIMERS	0
 
-/* The barrier functions are not available.  */
-#define _POSIX_BARRIERS	-1
+/* We support barrier functions.  */
+#define _POSIX_BARRIERS	200112L
 
 /* POSIX message queues could be available in future.  */
 #define	_POSIX_MESSAGE_PASSING	0

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=5452cef36a9e84618c893fab60a8dac6e03f1157

commit 5452cef36a9e84618c893fab60a8dac6e03f1157
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Thu Jan 18 23:38:29 2018 +0100

    t/libpthread_depends
    
    libpthread needs to be built before modules which need it.
    
    Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

diff --git a/nscd/Depend b/nscd/Depend
index 6c1aa44..c29ffb5 100644
--- a/nscd/Depend
+++ b/nscd/Depend
@@ -1 +1,2 @@
 nptl
+libpthread
diff --git a/resolv/Depend b/resolv/Depend
index 6c1aa44..c29ffb5 100644
--- a/resolv/Depend
+++ b/resolv/Depend
@@ -1 +1,2 @@
 nptl
+libpthread
diff --git a/rt/Depend b/rt/Depend
index 6c1aa44..c29ffb5 100644
--- a/rt/Depend
+++ b/rt/Depend
@@ -1 +1,2 @@
 nptl
+libpthread

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=8be3ddd815c27ead65f3a06cd7d7cc6d0732fbef

commit 8be3ddd815c27ead65f3a06cd7d7cc6d0732fbef
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Thu Jan 18 23:35:12 2018 +0100

    t/timer_routines
    
    support timer routines
    
    TODO: this is just browntape-fixing...
    
    * sysdeps/pthread/timer_routines.c: Do not include nptl/pthreadP.h
    Do not define some unused or unsupported functions.

diff --git a/sysdeps/pthread/timer_routines.c b/sysdeps/pthread/timer_routines.c
index f059beb..0f2de79 100644
--- a/sysdeps/pthread/timer_routines.c
+++ b/sysdeps/pthread/timer_routines.c
@@ -29,7 +29,7 @@
 #include <sys/syscall.h>
 
 #include "posix-timer.h"
-#include <nptl/pthreadP.h>
+//#include <nptl/pthreadP.h>
 
 
 /* Number of threads used.  */
@@ -395,6 +395,9 @@ thread_func (void *arg)
 		    {
 		      timespec_add (&timer->expirytime, &timer->expirytime,
 				    &timer->value.it_interval);
+#ifndef DELAYTIMER_MAX
+#define DELAYTIMER_MAX INT_MAX
+#endif
 		      if (timer->overrun_count < DELAYTIMER_MAX)
 			++timer->overrun_count;
 		    }
@@ -481,7 +484,7 @@ __timer_thread_wakeup (struct thread_node *thread)
   pthread_cond_broadcast (&thread->cond);
 }
 
-
+#if 0
 /* 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
@@ -506,6 +509,7 @@ thread_attr_compare (const pthread_attr_t *left, const pthread_attr_t *right)
 		  && memcmp (ileft->cpuset, iright->cpuset,
 			     ileft->cpusetsize) == 0)));
 }
+#endif
 
 
 /* Search the list of active threads and find one which has matching
@@ -514,6 +518,7 @@ struct thread_node *
 __timer_thread_find_matching (const pthread_attr_t *desired_attr,
 			      clockid_t desired_clock_id)
 {
+#if 0
   struct list_head *iter = list_first (&thread_active_list);
 
   while (iter != list_null (&thread_active_list))
@@ -526,6 +531,7 @@ __timer_thread_find_matching (const pthread_attr_t *desired_attr,
 
       iter = list_next (iter);
     }
+#endif
 
   return NULL;
 }

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=bf3116a0db2d942d7699170774c01dece22781e0

commit bf3116a0db2d942d7699170774c01dece22781e0
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Thu Jan 18 23:32:42 2018 +0100

    t/extern_inline
    
    hurd: take __USE_EXTERN_INLINES into account
    
    * hurd/hurd.h (__hurd_fail): Always declare function, and provide inline
    version only if __USE_EXTERN_INLINES is defined.
    * hurd/hurd/fd.h (_hurd_fd_get, _hurd_fd_error_signal, _hurd_fd_error,
    __hurd_dfail, __hurd_sockfail): Likewise.
    * mach/lock-intern.h (__spin_lock_init, __spin_lock, __mutex_lock,
    __mutex_unlock, __mutex_trylock): Likewise.
    * mach/mach/mig_support.h (__mig_strncpy): Likewise.
    * sysdeps/generic/machine-lock.h (__spin_unlock, __spin_try_lock,
    __spin_lock_locked): Likewise.
    * sysdeps/generic/machine-sp.h (__thread_stack_pointer): Likewise.
    * sysdeps/mach/i386/machine-lock.h (__spin_unlock, __spin_try_lock,
    __spin_lock_locked): Likewise.
    
    * hurd/hurd/port.h (_hurd_port_init, _hurd_port_locked_get,
    _hurd_port_get, _hurd_port_free, _hurd_port_locked_set,
    _hurd_port_set): Always declare functions, and provide inline version
    only if __USE_EXTERN_INLINES is defined and _LIBC is defined and
    NOT_IN_libc is not defined.
    * hurd/hurd/signal.h (_hurd_self_sigstate, _hurd_critical_section_lock,
    _hurd_critical_section_unlock): Likewise.
    * hurd/hurd/threadvar.h (__hurd_threadvar_location_from_sp,
    * __hurd_threadvar_location): Likewise.
    * hurd/hurd/userlink.h (_hurd_userlink_link, _hurd_userlink_unlink,
    _hurd_userlink_clear): Likewise.
    
    * mach/spin-lock.c (__USE_EXTERN_INLINES): Define to 1.
    
    * hurd/Versions (libc: GLIBC_2.19): Add _hurd_fd_error_signal,
    _hurd_fd_error, __hurd_dfail, __hurd_sockfail,
    __hurd_threadvar_location_from_sp, __hurd_threadvar_location,
    _hurd_userlink_link, _hurd_userlink_unlink, _hurd_userlink_clear.

diff --git a/hurd/Versions b/hurd/Versions
index b059405..8b84f73 100644
--- a/hurd/Versions
+++ b/hurd/Versions
@@ -132,6 +132,12 @@ libc {
   GLIBC_2.27 {
     # "quasi-internal" functions
     _hurd_exec_paths;
+    # These always existed as inlines but the real functions were not exported.
+    _hurd_fd_error_signal; _hurd_fd_error;
+    __hurd_dfail; __hurd_sockfail;
+    __hurd_threadvar_location_from_sp;
+    __hurd_threadvar_location;
+    _hurd_userlink_link; _hurd_userlink_unlink; _hurd_userlink_clear;
   }
 
   HURD_CTHREADS_0.3 {

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=18b64d4c98656e4d57d7c68acd53c6565ab9d0f0

commit 18b64d4c98656e4d57d7c68acd53c6565ab9d0f0
Author: Thomas Schwinge <thomas@schwinge.name>
Date:   Thu Jan 18 23:25:13 2018 +0100

    t/grantpt
    
        /media/Stalin/tmp/glibc.hurd.gnu-2/libc_pic.os: In function `pts_name':
        /media/data/home/thomas/tmp/source/glibc/git/glibc.hurd/login/../sysdeps/unix/grantpt.c:52: undefined reference to `__ptsname_internal'
        collect2: ld returned 1 exit status
        make[1]: *** [/media/Stalin/tmp/glibc.hurd.gnu-2/libc.so] Error 1
    
    Cf. aa9890239a2aef81e64f3f22a31c7e01b6501f69
    
    Need any of the checks (stat, etc.) that Linux' __ptsname_internal does?
    
    Implement close_all_fds as in 139ee080b6b428240bf49f3e6361f3ac729f891a?

diff --git a/sysdeps/mach/hurd/ptsname.c b/sysdeps/mach/hurd/ptsname.c
index 08748a3..c25794d 100644
--- a/sysdeps/mach/hurd/ptsname.c
+++ b/sysdeps/mach/hurd/ptsname.c
@@ -18,6 +18,7 @@
 
 #include <errno.h>
 #include <string.h>
+#include <sys/stat.h>
 #include <hurd.h>
 #include <hurd/fd.h>
 #include <hurd/term.h>
@@ -38,11 +39,10 @@ ptsname (int fd)
 }
 
 
-/* Store at most BUFLEN characters of the pathname of the slave pseudo
-   terminal associated with the master FD is open on in BUF.
-   Return 0 on success, otherwise an error number.  */
+/* We can't make use of STP, but do it that way for conformity with the Linux
+   version...  */
 int
-__ptsname_r (int fd, char *buf, size_t buflen)
+__ptsname_internal (int fd, char *buf, size_t buflen, struct stat64 *stp)
 {
   string_t peername;
   size_t len;
@@ -61,4 +61,14 @@ __ptsname_r (int fd, char *buf, size_t buflen)
   memcpy (buf, peername, len);
   return 0;
 }
+
+
+/* Store at most BUFLEN characters of the pathname of the slave pseudo
+   terminal associated with the master FD is open on in BUF.
+   Return 0 on success, otherwise an error number.  */
+int
+__ptsname_r (int fd, char *buf, size_t buflen)
+{
+  return __ptsname_internal (fd, buf, buflen, NULL);
+}
 weak_alias (__ptsname_r, ptsname_r)

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=33569b7b90912512f8130398e77763dd12bc5a7f

commit 33569b7b90912512f8130398e77763dd12bc5a7f
Author: Thomas Schwinge <thomas@schwinge.name>
Date:   Thu Jan 18 23:22:59 2018 +0100

    t/gscope
    
    Minimal gscope stuff.
    
    glibc-2.8/debian/patches/hurd-i386/local-gscope.diff 3085
    
    Written by Samuel Thibault.
    
    ---
    
    I think that's the corresponding error message:
    
        /media/Stalin/tmp/glibc.hurd.gnu-2/elf/librtld.os: In function `add_dependency':
        /media/data/home/thomas/tmp/source/glibc/git/glibc.hurd/elf/dl-lookup.c:106: undefined reference to `atomic_forced_read'
        /media/data/home/thomas/tmp/source/glibc/git/glibc.hurd/elf/dl-lookup.c:109: undefined reference to `atomic_read_barrier'
        /media/data/home/thomas/tmp/source/glibc/git/glibc.hurd/elf/dl-lookup.c:113: undefined reference to `atomic_forced_read'
        /media/data/home/thomas/tmp/source/glibc/git/glibc.hurd/elf/dl-lookup.c:141: undefined reference to `THREAD_GSCOPE_RESET_FLAG'
        /media/data/home/thomas/tmp/source/glibc/git/glibc.hurd/elf/dl-lookup.c:147: undefined reference to `atomic_forced_read'
        /media/data/home/thomas/tmp/source/glibc/git/glibc.hurd/elf/dl-lookup.c:284: undefined reference to `THREAD_GSCOPE_SET_FLAG'
        /media/data/home/thomas/tmp/source/glibc/git/glibc.hurd/elf/dl-lookup.c:261: undefined reference to `atomic_write_barrier'
        /media/data/home/thomas/tmp/source/glibc/git/glibc.hurd/elf/dl-lookup.c:250: undefined reference to `atomic_write_barrier'
        /media/Stalin/tmp/glibc.hurd.gnu-2/elf/librtld.os: In function `add_to_global':
        /media/data/home/thomas/tmp/source/glibc/git/glibc.hurd/elf/dl-open.c:162: undefined reference to `atomic_write_barrier'
        /media/Stalin/tmp/glibc.hurd.gnu-2/elf/librtld.os: In function `dl_open_worker':
        /media/data/home/thomas/tmp/source/glibc/git/glibc.hurd/elf/dl-open.c:478: undefined reference to `atomic_write_barrier'
        collect2: ld returned 1 exit status
        make[2]: *** [/media/Stalin/tmp/glibc.hurd.gnu-2/elf/ld.so] Error 1

diff --git a/elf/dl-support.c b/elf/dl-support.c
index b5ba0d1..51bb649 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -188,6 +188,7 @@ int (*_dl_make_stack_executable_hook) (void **) = _dl_make_stack_executable;
 /* Function in libpthread to wait for termination of lookups.  */
 void (*_dl_wait_lookup_done) (void);
 
+int volatile _dl_thread_gscope_count;
 struct dl_scope_free_list *_dl_scope_free_list;
 
 #ifdef NEED_DL_SYSINFO
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 0ea2786..bc7eaad 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -435,6 +435,7 @@ struct rtld_global
     size_t count;
     void *list[50];
   } *_dl_scope_free_list;
+  EXTERN volatile int _dl_thread_gscope_count;
 #ifdef SHARED
 };
 # define __rtld_global_attribute__
diff --git a/sysdeps/mach/hurd/sysdep-cancel.h b/sysdeps/mach/hurd/sysdep-cancel.h
new file mode 100644
index 0000000..ec55c73
--- /dev/null
+++ b/sysdeps/mach/hurd/sysdep-cancel.h
@@ -0,0 +1,9 @@
+#include <sysdep.h>
+
+/* Always multi-thread (since there's at least the sig handler), but no
+   handling enabled.  */
+#define SINGLE_THREAD_P (0)
+#define RTLD_SINGLE_THREAD_P (0)
+#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.  */
diff --git a/sysdeps/mach/hurd/tls.h b/sysdeps/mach/hurd/tls.h
index faff87c..dd303dc 100644
--- a/sysdeps/mach/hurd/tls.h
+++ b/sysdeps/mach/hurd/tls.h
@@ -53,5 +53,18 @@
 
 #endif /* !ASSEMBLER */
 
+#ifndef __ASSEMBLER__
+#include <mach/mach_traps.h>
+#include <atomic.h>
+/* Temporary poor-man's global scope switch support: just busy-waits */
+#define THREAD_GSCOPE_SET_FLAG() \
+	asm volatile ("lock incl %0":"=m"(GL(dl_thread_gscope_count)))
+#define THREAD_GSCOPE_RESET_FLAG() \
+	asm volatile ("lock decl %0":"=m"(GL(dl_thread_gscope_count)))
+#define THREAD_GSCOPE_WAIT() \
+  while (GL(dl_thread_gscope_count)) { \
+    __swtch_pri (0); \
+  }
+#endif
 
 #endif /* tls.h */

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=2d343d75b0ef56f2e3dcdd2b660ed8c59d1dd2cb

commit 2d343d75b0ef56f2e3dcdd2b660ed8c59d1dd2cb
Author: Thomas Schwinge <thomas@schwinge.name>
Date:   Thu Jan 18 23:21:19 2018 +0100

    t/_dl_random
    
    _dl_random
    
    ---
    
        /media/Stalin/tmp/glibc.hurd.gnu-2/elf/librtld.os: In function `security_init':
        /media/data/home/thomas/tmp/source/glibc/git/glibc.hurd/elf/rtld.c:844: undefined reference to `_dl_random'
        /media/data/home/thomas/tmp/gnu-2/bin/../lib/gcc/i586-pc-gnu/4.3.3/../../../../i586-pc-gnu/bin/ld: /media/Stalin/tmp/glibc.hurd.gnu-2/elf/librtld.os: relocation R_386_GOTOFF against undefined hidden symbol `_dl_random' can not be used when making a shared object
        /media/data/home/thomas/tmp/gnu-2/bin/../lib/gcc/i586-pc-gnu/4.3.3/../../../../i586-pc-gnu/bin/ld: final link failed: Bad value
        collect2: ld returned 1 exit status
        make[2]: *** [/media/Stalin/tmp/glibc.hurd.gnu-2/elf/ld.so] Error 1

diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c
index 7f2ba8c..c46342b 100644
--- a/sysdeps/mach/hurd/dl-sysdep.c
+++ b/sysdeps/mach/hurd/dl-sysdep.c
@@ -64,6 +64,8 @@ rtld_hidden_data_def(__libc_stack_end)
 hp_timing_t _dl_cpuclock_offset;
 #endif
 
+/* TODO: this is never properly initialized in here.  */
+void *_dl_random attribute_relro = NULL;
 
 struct hurd_startup_data *_dl_hurd_data;
 

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=c590725a1a679b4ffd56c3ff88d3e243af415c64

commit c590725a1a679b4ffd56c3ff88d3e243af415c64
Author: Thomas Schwinge <thomas@schwinge.name>
Date:   Thu Jan 18 23:20:41 2018 +0100

    t/pagesize
    
    WIP.  id:"87mxd9hl2n.fsf@kepler.schwinge.homeip.net"

diff --git a/elf/dl-support.c b/elf/dl-support.c
index 114f77a..b5ba0d1 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -136,7 +136,7 @@ hp_timing_t _dl_cpuclock_offset;
 
 void (*_dl_init_static_tls) (struct link_map *) = &_dl_nothread_init_static_tls;
 
-size_t _dl_pagesize = EXEC_PAGESIZE;
+size_t _dl_pagesize = /* EXEC_PAGESIZE */ 4096;
 
 int _dl_inhibit_cache;
 
diff --git a/elf/rtld.c b/elf/rtld.c
index 453f56e..25dc95d 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -271,7 +271,7 @@ struct rtld_global_ro _rtld_global_ro attribute_relro =
 #endif
     ._dl_lazy = 1,
     ._dl_fpu_control = _FPU_DEFAULT,
-    ._dl_pagesize = EXEC_PAGESIZE,
+    ._dl_pagesize = /* EXEC_PAGESIZE */ 4096,
     ._dl_inhibit_cache = 0,
 
     /* Function pointers.  */

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=e6a152a7946f6c1a85dfdafcf27a48b809cbd665

commit e6a152a7946f6c1a85dfdafcf27a48b809cbd665
Author: Thomas Schwinge <thomas@schwinge.name>
Date:   Thu Jan 18 23:19:02 2018 +0100

    t/verify.h
    
    2008-12-18  Thomas Schwinge  <tschwinge@gnu.org>
    
    	* include/verify.h: New file, from gnulib.
    
    TODO: Use it in all sensible places.

diff --git a/include/verify.h b/include/verify.h
new file mode 100644
index 0000000..3470500
--- /dev/null
+++ b/include/verify.h
@@ -0,0 +1,140 @@
+/* Compile-time assert-like macros.
+
+   Copyright (C) 2005-2015 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paul Eggert, Bruno Haible, and Jim Meyering.  */
+
+#ifndef VERIFY_H
+# define VERIFY_H 1
+
+/* Each of these macros verifies that its argument R is nonzero.  To
+   be portable, R should be an integer constant expression.  Unlike
+   assert (R), there is no run-time overhead.
+
+   There are two macros, since no single macro can be used in all
+   contexts in C.  verify_true (R) is for scalar contexts, including
+   integer constant expression contexts.  verify (R) is for declaration
+   contexts, e.g., the top level.
+
+   Symbols ending in "__" are private to this header.
+
+   The code below uses several ideas.
+
+   * The first step is ((R) ? 1 : -1).  Given an expression R, of
+     integral or boolean or floating-point type, this yields an
+     expression of integral type, whose value is later verified to be
+     constant and nonnegative.
+
+   * Next this expression W is wrapped in a type
+     struct verify_type__ { unsigned int verify_error_if_negative_size__: W; }.
+     If W is negative, this yields a compile-time error.  No compiler can
+     deal with a bit-field of negative size.
+
+     One might think that an array size check would have the same
+     effect, that is, that the type struct { unsigned int dummy[W]; }
+     would work as well.  However, inside a function, some compilers
+     (such as C++ compilers and GNU C) allow local parameters and
+     variables inside array size expressions.  With these compilers,
+     an array size check would not properly diagnose this misuse of
+     the verify macro:
+
+       void function (int n) { verify (n < 0); }
+
+   * For the verify macro, the struct verify_type__ will need to
+     somehow be embedded into a declaration.  To be portable, this
+     declaration must declare an object, a constant, a function, or a
+     typedef name.  If the declared entity uses the type directly,
+     such as in
+
+       struct dummy {...};
+       typedef struct {...} dummy;
+       extern struct {...} *dummy;
+       extern void dummy (struct {...} *);
+       extern struct {...} *dummy (void);
+
+     two uses of the verify macro would yield colliding declarations
+     if the entity names are not disambiguated.  A workaround is to
+     attach the current line number to the entity name:
+
+       #define GL_CONCAT0(x, y) x##y
+       #define GL_CONCAT(x, y) GL_CONCAT0 (x, y)
+       extern struct {...} * GL_CONCAT(dummy,__LINE__);
+
+     But this has the problem that two invocations of verify from
+     within the same macro would collide, since the __LINE__ value
+     would be the same for both invocations.
+
+     A solution is to use the sizeof operator.  It yields a number,
+     getting rid of the identity of the type.  Declarations like
+
+       extern int dummy [sizeof (struct {...})];
+       extern void dummy (int [sizeof (struct {...})]);
+       extern int (*dummy (void)) [sizeof (struct {...})];
+
+     can be repeated.
+
+   * Should the implementation use a named struct or an unnamed struct?
+     Which of the following alternatives can be used?
+
+       extern int dummy [sizeof (struct {...})];
+       extern int dummy [sizeof (struct verify_type__ {...})];
+       extern void dummy (int [sizeof (struct {...})]);
+       extern void dummy (int [sizeof (struct verify_type__ {...})]);
+       extern int (*dummy (void)) [sizeof (struct {...})];
+       extern int (*dummy (void)) [sizeof (struct verify_type__ {...})];
+
+     In the second and sixth case, the struct type is exported to the
+     outer scope; two such declarations therefore collide.  GCC warns
+     about the first, third, and fourth cases.  So the only remaining
+     possibility is the fifth case:
+
+       extern int (*dummy (void)) [sizeof (struct {...})];
+
+   * This implementation exploits the fact that GCC does not warn about
+     the last declaration mentioned above.  If a future version of GCC
+     introduces a warning for this, the problem could be worked around
+     by using code specialized to GCC, e.g.,:
+
+       #if 4 <= __GNUC__
+       # define verify(R) \
+	   extern int (* verify_function__ (void)) \
+		      [__builtin_constant_p (R) && (R) ? 1 : -1]
+       #endif
+
+   * In C++, any struct definition inside sizeof is invalid.
+     Use a template type to work around the problem.  */
+
+
+/* Verify requirement R at compile-time, as an integer constant expression.
+   Return 1.  */
+
+# ifdef __cplusplus
+template <int w>
+  struct verify_type__ { unsigned int verify_error_if_negative_size__: w; };
+#  define verify_true(R) \
+     (!!sizeof (verify_type__<(R) ? 1 : -1>))
+# else
+#  define verify_true(R) \
+     (!!sizeof \
+      (struct { unsigned int verify_error_if_negative_size__: (R) ? 1 : -1; }))
+# endif
+
+/* Verify requirement R at compile-time, as a declaration without a
+   trailing ';'.  */
+
+# define verify(R) extern int (* verify_function__ (void)) [verify_true (R)]
+
+#endif

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=e36d978a0e424fad844a2f185c508c918f69ebfd

commit e36d978a0e424fad844a2f185c508c918f69ebfd
Author: Thomas Schwinge <thomas@schwinge.name>
Date:   Thu Jan 18 23:18:00 2018 +0100

    t/fcntl-internal.h
    
    2008-12-18  Thomas Schwinge  <tschwinge@gnu.org>
    
    	* hurd/fcntl-internal.h: New file.

diff --git a/hurd/fcntl-internal.h b/hurd/fcntl-internal.h
new file mode 100644
index 0000000..5cd4542
--- /dev/null
+++ b/hurd/fcntl-internal.h
@@ -0,0 +1,60 @@
+/* Copyright (C) 2008-2015 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 <fcntl.h>
+#include <sys/socket.h>
+#include <verify.h>
+
+/* Do some compile-time checks for the SOCK_* constants, which we rely on.  */
+verify (SOCK_CLOEXEC == O_CLOEXEC);
+verify ((SOCK_MAX | SOCK_TYPE_MASK) == SOCK_TYPE_MASK);
+verify ((SOCK_CLOEXEC & SOCK_TYPE_MASK) == 0);
+verify ((SOCK_NONBLOCK & SOCK_TYPE_MASK) == 0);
+
+
+/* Helper functions for translating between O_* and SOCK_* flags.  */
+
+__extern_always_inline
+int
+sock_to_o_flags (int in)
+{
+  int out = 0;
+
+  if (in & SOCK_NONBLOCK)
+    out |= O_NONBLOCK;
+  /* Others are passed through unfiltered.  */
+  out |= in & ~(SOCK_NONBLOCK);
+
+  return out;
+}
+
+__extern_always_inline
+int
+o_to_sock_flags (int in)
+{
+  int out = 0;
+
+  if (in & O_NONBLOCK)
+    out |= SOCK_NONBLOCK;
+  /* Others are passed through unfiltered.  */
+  out |= in & ~(O_NONBLOCK);
+
+  return out;
+}

-----------------------------------------------------------------------


hooks/post-receive
-- 
GNU C Library master sources


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]