summaryrefslogtreecommitdiff
path: root/sysdeps/nptl
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2018-12-27 19:01:57 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2018-12-27 19:01:57 +0000
commitcab56836b146bc129f1ad43f0393d95a9deca63a (patch)
tree4f4e655319bbac78fca170da05275c127429b460 /sysdeps/nptl
parent04ac1241a4cd004872282c2c82ec37fa33925292 (diff)
parent82dd75a7f436a19047325d62182590c9f9e23a78 (diff)
Merge branch 't/tls' into refs/top-bases/t/tls-threadvar
Diffstat (limited to 'sysdeps/nptl')
-rw-r--r--sysdeps/nptl/Makeconfig11
-rw-r--r--sysdeps/nptl/Makefile2
-rw-r--r--sysdeps/nptl/aio_misc.h2
-rw-r--r--sysdeps/nptl/allocrtsig.c2
-rw-r--r--sysdeps/nptl/bits/pthreadtypes.h121
-rw-r--r--sysdeps/nptl/bits/thread-shared-types.h178
-rw-r--r--sysdeps/nptl/fork.c190
-rw-r--r--sysdeps/nptl/fork.h33
-rw-r--r--sysdeps/nptl/futex-internal.h4
-rw-r--r--sysdeps/nptl/gai_misc.h2
-rw-r--r--sysdeps/nptl/internaltypes.h21
-rw-r--r--sysdeps/nptl/jmp-unwind.c2
-rw-r--r--sysdeps/nptl/libc-lock.h2
-rw-r--r--sysdeps/nptl/libc-lockP.h4
-rw-r--r--sysdeps/nptl/librt-cancellation.c2
-rw-r--r--sysdeps/nptl/lowlevellock-futex.h2
-rw-r--r--sysdeps/nptl/lowlevellock.h87
-rw-r--r--sysdeps/nptl/malloc-machine.h37
-rw-r--r--sysdeps/nptl/nptl-signals.h22
-rw-r--r--sysdeps/nptl/pthread-functions.h4
-rw-r--r--sysdeps/nptl/pthread.h7
-rw-r--r--sysdeps/nptl/setxid.h2
-rw-r--r--sysdeps/nptl/shm-directory.h2
-rw-r--r--sysdeps/nptl/sigfillset.c20
-rw-r--r--sysdeps/nptl/stdio-lock.h7
-rw-r--r--sysdeps/nptl/sys/procfs.h2
-rw-r--r--sysdeps/nptl/threads.h207
-rw-r--r--sysdeps/nptl/timer_routines.h51
-rw-r--r--sysdeps/nptl/unwind-forcedunwind.c7
29 files changed, 683 insertions, 350 deletions
diff --git a/sysdeps/nptl/Makeconfig b/sysdeps/nptl/Makeconfig
index 2f4918d112..ce8998bbf5 100644
--- a/sysdeps/nptl/Makeconfig
+++ b/sysdeps/nptl/Makeconfig
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2016 Free Software Foundation, Inc.
+# Copyright (C) 2002-2018 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
@@ -16,17 +16,12 @@
# License along with the GNU C Library; if not, see
# <http://www.gnu.org/licenses/>.
-# Makeconfig fragment for NPTL add-on.
+# Makeconfig fragment for NPTL.
# This gets included at the end of the main glibc Makeconfig.
have-thread-library = yes
-shared-thread-library = $(common-objpfx)nptl/libpthread_nonshared.a \
- $(common-objpfx)nptl/libpthread.so
+shared-thread-library = $(common-objpfx)nptl/libpthread.so
static-thread-library = $(common-objpfx)nptl/libpthread.a
rpath-dirs += nptl
-
-# This makes for ptw-*.? object rules in sysd-rules.
-ptw-CPPFLAGS := -DPTW
-sysd-rules-patterns += ptw-%:%
diff --git a/sysdeps/nptl/Makefile b/sysdeps/nptl/Makefile
index 0dbbd72b27..6b87b82759 100644
--- a/sysdeps/nptl/Makefile
+++ b/sysdeps/nptl/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2016 Free Software Foundation, Inc.
+# Copyright (C) 2002-2018 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
diff --git a/sysdeps/nptl/aio_misc.h b/sysdeps/nptl/aio_misc.h
index a7a8a12060..206d8e193d 100644
--- a/sysdeps/nptl/aio_misc.h
+++ b/sysdeps/nptl/aio_misc.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2006-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2006-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
diff --git a/sysdeps/nptl/allocrtsig.c b/sysdeps/nptl/allocrtsig.c
index ead2832d75..2039d62a83 100644
--- a/sysdeps/nptl/allocrtsig.c
+++ b/sysdeps/nptl/allocrtsig.c
@@ -1,5 +1,5 @@
/* Handle real-time signal allocation. NPTL version.
- Copyright (C) 2015-2016 Free Software Foundation, Inc.
+ Copyright (C) 2015-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
diff --git a/sysdeps/nptl/bits/pthreadtypes.h b/sysdeps/nptl/bits/pthreadtypes.h
new file mode 100644
index 0000000000..70ce0a0448
--- /dev/null
+++ b/sysdeps/nptl/bits/pthreadtypes.h
@@ -0,0 +1,121 @@
+/* Declaration of common pthread types for all architectures.
+ Copyright (C) 2017-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 _BITS_PTHREADTYPES_COMMON_H
+# define _BITS_PTHREADTYPES_COMMON_H 1
+
+/* For internal mutex and condition variable definitions. */
+#include <bits/thread-shared-types.h>
+
+/* Thread identifiers. The structure of the attribute type is not
+ exposed on purpose. */
+typedef unsigned long int pthread_t;
+
+
+/* Data structures for mutex handling. The structure of the attribute
+ type is not exposed on purpose. */
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_MUTEXATTR_T];
+ int __align;
+} pthread_mutexattr_t;
+
+
+/* Data structure for condition variable handling. The structure of
+ the attribute type is not exposed on purpose. */
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_CONDATTR_T];
+ int __align;
+} pthread_condattr_t;
+
+
+/* Keys for thread-specific data */
+typedef unsigned int pthread_key_t;
+
+
+/* Once-only execution */
+typedef int __ONCE_ALIGNMENT pthread_once_t;
+
+
+union pthread_attr_t
+{
+ char __size[__SIZEOF_PTHREAD_ATTR_T];
+ long int __align;
+};
+#ifndef __have_pthread_attr_t
+typedef union pthread_attr_t pthread_attr_t;
+# define __have_pthread_attr_t 1
+#endif
+
+
+typedef union
+{
+ struct __pthread_mutex_s __data;
+ char __size[__SIZEOF_PTHREAD_MUTEX_T];
+ long int __align;
+} pthread_mutex_t;
+
+
+typedef union
+{
+ struct __pthread_cond_s __data;
+ char __size[__SIZEOF_PTHREAD_COND_T];
+ __extension__ long long int __align;
+} pthread_cond_t;
+
+
+#if defined __USE_UNIX98 || defined __USE_XOPEN2K
+/* Data structure for reader-writer lock variable handling. The
+ structure of the attribute type is deliberately not exposed. */
+typedef union
+{
+ struct __pthread_rwlock_arch_t __data;
+ char __size[__SIZEOF_PTHREAD_RWLOCK_T];
+ long int __align;
+} pthread_rwlock_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_RWLOCKATTR_T];
+ long int __align;
+} pthread_rwlockattr_t;
+#endif
+
+
+#ifdef __USE_XOPEN2K
+/* POSIX spinlock data type. */
+typedef volatile int pthread_spinlock_t;
+
+
+/* POSIX barriers data type. The structure of the type is
+ deliberately not exposed. */
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_BARRIER_T];
+ long int __align;
+} pthread_barrier_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_BARRIERATTR_T];
+ int __align;
+} pthread_barrierattr_t;
+#endif
+
+#endif
diff --git a/sysdeps/nptl/bits/thread-shared-types.h b/sysdeps/nptl/bits/thread-shared-types.h
new file mode 100644
index 0000000000..1e2092a05d
--- /dev/null
+++ b/sysdeps/nptl/bits/thread-shared-types.h
@@ -0,0 +1,178 @@
+/* Common threading primitives definitions for both POSIX and C11.
+ Copyright (C) 2017-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 _THREAD_SHARED_TYPES_H
+#define _THREAD_SHARED_TYPES_H 1
+
+/* Arch-specific definitions. Each architecture must define the following
+ macros to define the expected sizes of pthread data types:
+
+ __SIZEOF_PTHREAD_ATTR_T - size of pthread_attr_t.
+ __SIZEOF_PTHREAD_MUTEX_T - size of pthread_mutex_t.
+ __SIZEOF_PTHREAD_MUTEXATTR_T - size of pthread_mutexattr_t.
+ __SIZEOF_PTHREAD_COND_T - size of pthread_cond_t.
+ __SIZEOF_PTHREAD_CONDATTR_T - size of pthread_condattr_t.
+ __SIZEOF_PTHREAD_RWLOCK_T - size of pthread_rwlock_t.
+ __SIZEOF_PTHREAD_RWLOCKATTR_T - size of pthread_rwlockattr_t.
+ __SIZEOF_PTHREAD_BARRIER_T - size of pthread_barrier_t.
+ __SIZEOF_PTHREAD_BARRIERATTR_T - size of pthread_barrierattr_t.
+
+ Also, the following macros must be define for internal pthread_mutex_t
+ struct definitions (struct __pthread_mutex_s):
+
+ __PTHREAD_COMPAT_PADDING_MID - any additional members after 'kind'
+ and before '__spin' (for 64 bits) or
+ '__nusers' (for 32 bits).
+ __PTHREAD_COMPAT_PADDING_END - any additional members at the end of
+ the internal structure.
+ __PTHREAD_MUTEX_LOCK_ELISION - 1 if the architecture supports lock
+ elision or 0 otherwise.
+ __PTHREAD_MUTEX_NUSERS_AFTER_KIND - control where to put __nusers. The
+ preferred value for new architectures
+ is 0.
+ __PTHREAD_MUTEX_USE_UNION - control whether internal __spins and
+ __list will be place inside a union for
+ linuxthreads compatibility.
+ The preferred value for new architectures
+ is 0.
+
+ For a new port the preferred values for the required defines are:
+
+ #define __PTHREAD_COMPAT_PADDING_MID
+ #define __PTHREAD_COMPAT_PADDING_END
+ #define __PTHREAD_MUTEX_LOCK_ELISION 0
+ #define __PTHREAD_MUTEX_NUSERS_AFTER_KIND 0
+ #define __PTHREAD_MUTEX_USE_UNION 0
+
+ __PTHREAD_MUTEX_LOCK_ELISION can be set to 1 if the hardware plans to
+ eventually support lock elision using transactional memory.
+
+ The additional macro defines any constraint for the lock alignment
+ inside the thread structures:
+
+ __LOCK_ALIGNMENT - for internal lock/futex usage.
+
+ Same idea but for the once locking primitive:
+
+ __ONCE_ALIGNMENT - for pthread_once_t/once_flag definition.
+
+ And finally the internal pthread_rwlock_t (struct __pthread_rwlock_arch_t)
+ must be defined.
+ */
+#include <bits/pthreadtypes-arch.h>
+
+/* Common definition of pthread_mutex_t. */
+
+#if !__PTHREAD_MUTEX_USE_UNION
+typedef struct __pthread_internal_list
+{
+ struct __pthread_internal_list *__prev;
+ struct __pthread_internal_list *__next;
+} __pthread_list_t;
+#else
+typedef struct __pthread_internal_slist
+{
+ struct __pthread_internal_slist *__next;
+} __pthread_slist_t;
+#endif
+
+/* Lock elision support. */
+#if __PTHREAD_MUTEX_LOCK_ELISION
+# if !__PTHREAD_MUTEX_USE_UNION
+# define __PTHREAD_SPINS_DATA \
+ short __spins; \
+ short __elision
+# define __PTHREAD_SPINS 0, 0
+# else
+# define __PTHREAD_SPINS_DATA \
+ struct \
+ { \
+ short __espins; \
+ short __eelision; \
+ } __elision_data
+# define __PTHREAD_SPINS { 0, 0 }
+# define __spins __elision_data.__espins
+# define __elision __elision_data.__eelision
+# endif
+#else
+# define __PTHREAD_SPINS_DATA int __spins
+/* Mutex __spins initializer used by PTHREAD_MUTEX_INITIALIZER. */
+# define __PTHREAD_SPINS 0
+#endif
+
+struct __pthread_mutex_s
+{
+ int __lock __LOCK_ALIGNMENT;
+ unsigned int __count;
+ int __owner;
+#if !__PTHREAD_MUTEX_NUSERS_AFTER_KIND
+ unsigned int __nusers;
+#endif
+ /* KIND must stay at this position in the structure to maintain
+ binary compatibility with static initializers. */
+ int __kind;
+ __PTHREAD_COMPAT_PADDING_MID
+#if __PTHREAD_MUTEX_NUSERS_AFTER_KIND
+ unsigned int __nusers;
+#endif
+#if !__PTHREAD_MUTEX_USE_UNION
+ __PTHREAD_SPINS_DATA;
+ __pthread_list_t __list;
+# define __PTHREAD_MUTEX_HAVE_PREV 1
+#else
+ __extension__ union
+ {
+ __PTHREAD_SPINS_DATA;
+ __pthread_slist_t __list;
+ };
+# define __PTHREAD_MUTEX_HAVE_PREV 0
+#endif
+ __PTHREAD_COMPAT_PADDING_END
+};
+
+
+/* Common definition of pthread_cond_t. */
+
+struct __pthread_cond_s
+{
+ __extension__ union
+ {
+ __extension__ unsigned long long int __wseq;
+ struct
+ {
+ unsigned int __low;
+ unsigned int __high;
+ } __wseq32;
+ };
+ __extension__ union
+ {
+ __extension__ unsigned long long int __g1_start;
+ struct
+ {
+ unsigned int __low;
+ unsigned int __high;
+ } __g1_start32;
+ };
+ unsigned int __g_refs[2] __LOCK_ALIGNMENT;
+ unsigned int __g_size[2];
+ unsigned int __g1_orig_size;
+ unsigned int __wrefs;
+ unsigned int __g_signals[2];
+};
+
+#endif /* _THREAD_SHARED_TYPES_H */
diff --git a/sysdeps/nptl/fork.c b/sysdeps/nptl/fork.c
index 27f8d52e30..ec56a827eb 100644
--- a/sysdeps/nptl/fork.c
+++ b/sysdeps/nptl/fork.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2002-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
@@ -31,7 +31,7 @@
#include <fork.h>
#include <arch-fork.h>
#include <futex-internal.h>
-
+#include <malloc/malloc-internal.h>
static void
fresetlockfiles (void)
@@ -48,100 +48,41 @@ pid_t
__libc_fork (void)
{
pid_t pid;
- struct used_handler
- {
- struct fork_handler *handler;
- struct used_handler *next;
- } *allp = NULL;
-
- /* Run all the registered preparation handlers. In reverse order.
- While doing this we build up a list of all the entries. */
- struct fork_handler *runp;
- while ((runp = __fork_handlers) != NULL)
- {
- /* Make sure we read from the current RUNP pointer. */
- atomic_full_barrier ();
-
- unsigned int oldval = runp->refcntr;
-
- if (oldval == 0)
- /* This means some other thread removed the list just after
- the pointer has been loaded. Try again. Either the list
- is empty or we can retry it. */
- continue;
-
- /* Bump the reference counter. */
- if (atomic_compare_and_exchange_bool_acq (&__fork_handlers->refcntr,
- oldval + 1, oldval))
- /* The value changed, try again. */
- continue;
-
- /* We bumped the reference counter for the first entry in the
- list. That means that none of the following entries will
- just go away. The unloading code works in the order of the
- list.
-
- While executing the registered handlers we are building a
- list of all the entries so that we can go backward later on. */
- while (1)
- {
- /* Execute the handler if there is one. */
- if (runp->prepare_handler != NULL)
- runp->prepare_handler ();
-
- /* Create a new element for the list. */
- struct used_handler *newp
- = (struct used_handler *) alloca (sizeof (*newp));
- newp->handler = runp;
- newp->next = allp;
- allp = newp;
-
- /* Advance to the next handler. */
- runp = runp->next;
- if (runp == NULL)
- break;
-
- /* Bump the reference counter for the next entry. */
- atomic_increment (&runp->refcntr);
- }
- /* We are done. */
- break;
- }
+ /* Determine if we are running multiple threads. We skip some fork
+ handlers in the single-thread case, to make fork safer to use in
+ signal handlers. POSIX requires that fork is async-signal-safe,
+ but our current fork implementation is not. */
+ bool multiple_threads = THREAD_GETMEM (THREAD_SELF, header.multiple_threads);
- _IO_list_lock ();
+ __run_fork_handlers (atfork_run_prepare);
-#ifndef NDEBUG
- pid_t ppid = THREAD_GETMEM (THREAD_SELF, tid);
-#endif
+ /* If we are not running multiple threads, we do not have to
+ preserve lock state. If fork runs from a signal handler, only
+ async-signal-safe functions can be used in the child. These data
+ structures are only used by unsafe functions, so their state does
+ not matter if fork was called from a signal handler. */
+ if (multiple_threads)
+ {
+ _IO_list_lock ();
- /* We need to prevent the getpid() code to update the PID field so
- that, if a signal arrives in the child very early and the signal
- handler uses getpid(), the value returned is correct. */
- pid_t parentpid = THREAD_GETMEM (THREAD_SELF, pid);
- THREAD_SETMEM (THREAD_SELF, pid, -parentpid);
-
-#ifdef ARCH_FORK
- pid = ARCH_FORK ();
-#else
-# error "ARCH_FORK must be defined so that the CLONE_SETTID flag is used"
- pid = INLINE_SYSCALL (fork, 0);
-#endif
+ /* Acquire malloc locks. This needs to come last because fork
+ handlers may use malloc, and the libio list lock has an
+ indirect malloc dependency as well (via the getdelim
+ function). */
+ call_function_static_weak (__malloc_fork_lock_parent);
+ }
+ pid = arch_fork (&THREAD_SELF->tid);
if (pid == 0)
{
struct pthread *self = THREAD_SELF;
- assert (THREAD_GETMEM (self, tid) != ppid);
-
/* See __pthread_once. */
if (__fork_generation_pointer != NULL)
*__fork_generation_pointer += __PTHREAD_ONCE_FORK_GEN_INCR;
- /* Adjust the PID field for the new process. */
- THREAD_SETMEM (self, pid, THREAD_GETMEM (self, tid));
-
#if HP_TIMING_AVAIL
/* The CPU clock of the thread and process have to be set to zero. */
hp_timing_t now;
@@ -151,12 +92,20 @@ __libc_fork (void)
#endif
#ifdef __NR_set_robust_list
- /* Initialize the robust mutex list which has been reset during
- the fork. We do not check for errors since if it fails here
- it failed at process start as well and noone could have used
- robust mutexes. We also do not have to set
- self->robust_head.futex_offset since we inherit the correct
- value from the parent. */
+ /* Initialize the robust mutex list setting in the kernel which has
+ been reset during the fork. We do not check for errors because if
+ it fails here, it must have failed at process startup as well and
+ nobody could have used robust mutexes.
+ Before we do that, we have to clear the list of robust mutexes
+ because we do not inherit ownership of mutexes from the parent.
+ We do not have to set self->robust_head.futex_offset since we do
+ inherit the correct value from the parent. We do not need to clear
+ the pending operation because it must have been zero when fork was
+ called. */
+# if __PTHREAD_MUTEX_HAVE_PREV
+ self->robust_prev = &self->robust_head;
+# endif
+ self->robust_head.list = &self->robust_head;
# ifdef SHARED
if (__builtin_expect (__libc_pthread_functions_init, 0))
PTHFCT_CALL (ptr_set_robust, (self));
@@ -168,62 +117,39 @@ __libc_fork (void)
# endif
#endif
- /* Reset the file list. These are recursive mutexes. */
- fresetlockfiles ();
+ /* Reset the lock state in the multi-threaded case. */
+ if (multiple_threads)
+ {
+ /* Release malloc locks. */
+ call_function_static_weak (__malloc_fork_unlock_child);
- /* Reset locks in the I/O code. */
- _IO_list_resetlock ();
+ /* Reset the file list. These are recursive mutexes. */
+ fresetlockfiles ();
+
+ /* Reset locks in the I/O code. */
+ _IO_list_resetlock ();
+ }
/* Reset the lock the dynamic loader uses to protect its data. */
__rtld_lock_initialize (GL(dl_load_lock));
/* Run the handlers registered for the child. */
- while (allp != NULL)
- {
- if (allp->handler->child_handler != NULL)
- allp->handler->child_handler ();
-
- /* Note that we do not have to wake any possible waiter.
- This is the only thread in the new process. The count
- may have been bumped up by other threads doing a fork.
- We reset it to 1, to avoid waiting for non-existing
- thread(s) to release the count. */
- allp->handler->refcntr = 1;
-
- /* XXX We could at this point look through the object pool
- and mark all objects not on the __fork_handlers list as
- unused. This is necessary in case the fork() happened
- while another thread called dlclose() and that call had
- to create a new list. */
-
- allp = allp->next;
- }
-
- /* Initialize the fork lock. */
- __fork_lock = LLL_LOCK_INITIALIZER;
+ __run_fork_handlers (atfork_run_child);
}
else
{
- assert (THREAD_GETMEM (THREAD_SELF, tid) == ppid);
-
- /* Restore the PID value. */
- THREAD_SETMEM (THREAD_SELF, pid, parentpid);
-
- /* We execute this even if the 'fork' call failed. */
- _IO_list_unlock ();
-
- /* Run the handlers registered for the parent. */
- while (allp != NULL)
+ /* Release acquired locks in the multi-threaded case. */
+ if (multiple_threads)
{
- if (allp->handler->parent_handler != NULL)
- allp->handler->parent_handler ();
+ /* Release malloc locks, parent process variant. */
+ call_function_static_weak (__malloc_fork_unlock_parent);
- if (atomic_decrement_and_test (&allp->handler->refcntr)
- && allp->handler->need_signal)
- futex_wake (&allp->handler->refcntr, 1, FUTEX_PRIVATE);
-
- allp = allp->next;
+ /* We execute this even if the 'fork' call failed. */
+ _IO_list_unlock ();
}
+
+ /* Run the handlers registered for the parent. */
+ __run_fork_handlers (atfork_run_parent);
}
return pid;
diff --git a/sysdeps/nptl/fork.h b/sysdeps/nptl/fork.h
index 76762d4b1e..6eab61c121 100644
--- a/sysdeps/nptl/fork.h
+++ b/sysdeps/nptl/fork.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2002-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
@@ -24,29 +24,37 @@ extern unsigned long int __fork_generation attribute_hidden;
/* Pointer to the fork generation counter in the thread library. */
extern unsigned long int *__fork_generation_pointer attribute_hidden;
-/* Lock to protect allocation and deallocation of fork handlers. */
-extern int __fork_lock attribute_hidden;
-
/* Elements of the fork handler lists. */
struct fork_handler
{
- struct fork_handler *next;
void (*prepare_handler) (void);
void (*parent_handler) (void);
void (*child_handler) (void);
void *dso_handle;
- unsigned int refcntr;
- int need_signal;
};
-/* The single linked list of all currently registered for handlers. */
-extern struct fork_handler *__fork_handlers attribute_hidden;
-
-
/* Function to call to unregister fork handlers. */
extern void __unregister_atfork (void *dso_handle) attribute_hidden;
#define UNREGISTER_ATFORK(dso_handle) __unregister_atfork (dso_handle)
+enum __run_fork_handler_type
+{
+ atfork_run_prepare,
+ atfork_run_child,
+ atfork_run_parent
+};
+
+/* Run the atfork handlers and lock/unlock the internal lock depending
+ of the WHO argument:
+
+ - atfork_run_prepare: run all the PREPARE_HANDLER in reverse order of
+ insertion and locks the internal lock.
+ - atfork_run_child: run all the CHILD_HANDLER and unlocks the internal
+ lock.
+ - atfork_run_parent: run all the PARENT_HANDLER and unlocks the internal
+ lock. */
+extern void __run_fork_handlers (enum __run_fork_handler_type who)
+ attribute_hidden;
/* C library side function to register new fork handlers. */
extern int __register_atfork (void (*__prepare) (void),
@@ -54,6 +62,3 @@ extern int __register_atfork (void (*__prepare) (void),
void (*__child) (void),
void *dso_handle);
libc_hidden_proto (__register_atfork)
-
-/* Add a new element to the fork list. */
-extern void __linkin_atfork (struct fork_handler *newp) attribute_hidden;
diff --git a/sysdeps/nptl/futex-internal.h b/sysdeps/nptl/futex-internal.h
index d798b69708..1a5624789d 100644
--- a/sysdeps/nptl/futex-internal.h
+++ b/sysdeps/nptl/futex-internal.h
@@ -1,6 +1,6 @@
/* futex operations for glibc-internal use. Stub version; do not include
this file directly.
- Copyright (C) 2014-2016 Free Software Foundation, Inc.
+ Copyright (C) 2014-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
@@ -23,7 +23,7 @@
#include <sys/time.h>
#include <stdio.h>
#include <stdbool.h>
-#include <libc-internal.h>
+#include <libc-diag.h>
/* This file defines futex operations used internally in glibc. A futex
consists of the so-called futex word in userspace, which is of type
diff --git a/sysdeps/nptl/gai_misc.h b/sysdeps/nptl/gai_misc.h
index c550cdd85e..815e6c0dc6 100644
--- a/sysdeps/nptl/gai_misc.h
+++ b/sysdeps/nptl/gai_misc.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2006-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2006-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
diff --git a/sysdeps/nptl/internaltypes.h b/sysdeps/nptl/internaltypes.h
index 203c548550..b78ad99a88 100644
--- a/sysdeps/nptl/internaltypes.h
+++ b/sysdeps/nptl/internaltypes.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2002-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
@@ -68,20 +68,13 @@ struct pthread_condattr
{
/* Combination of values:
- Bit 0 : flag whether conditional variable will be sharable between
- processes.
-
- Bit 1-7: clock ID. */
+ Bit 0 : flag whether conditional variable will be
+ sharable between processes.
+ Bit 1-COND_CLOCK_BITS: Clock ID. COND_CLOCK_BITS is the number of bits
+ needed to represent the ID of the clock. */
int value;
};
-
-
-/* The __NWAITERS field is used as a counter and to house the number
- of bits for other purposes. COND_CLOCK_BITS is the number
- of bits needed to represent the ID of the clock. COND_NWAITERS_SHIFT
- is the number of bits reserved for other purposes like the clock. */
-#define COND_CLOCK_BITS 1
-#define COND_NWAITERS_SHIFT 1
+#define COND_CLOCK_BITS 1
/* Read-write lock variable attribute data structure. */
@@ -147,7 +140,7 @@ struct pthread_key_struct
struct new_sem
{
#if __HAVE_64B_ATOMICS
- /* The data field holds both value (in the least-significant 32 bytes) and
+ /* The data field holds both value (in the least-significant 32 bits) and
nwaiters. */
# if __BYTE_ORDER == __LITTLE_ENDIAN
# define SEM_VALUE_OFFSET 0
diff --git a/sysdeps/nptl/jmp-unwind.c b/sysdeps/nptl/jmp-unwind.c
index ec227ada21..ea754df3ea 100644
--- a/sysdeps/nptl/jmp-unwind.c
+++ b/sysdeps/nptl/jmp-unwind.c
@@ -1,5 +1,5 @@
/* Clean up stack frames unwound by longjmp. Linux version.
- Copyright (C) 1995-2016 Free Software Foundation, Inc.
+ Copyright (C) 1995-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
diff --git a/sysdeps/nptl/libc-lock.h b/sysdeps/nptl/libc-lock.h
index db11456b38..801bcf7913 100644
--- a/sysdeps/nptl/libc-lock.h
+++ b/sysdeps/nptl/libc-lock.h
@@ -1,5 +1,5 @@
/* libc-internal interface for mutex locks. NPTL version.
- Copyright (C) 1996-2016 Free Software Foundation, Inc.
+ 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
diff --git a/sysdeps/nptl/libc-lockP.h b/sysdeps/nptl/libc-lockP.h
index 50b86d2225..989fefa370 100644
--- a/sysdeps/nptl/libc-lockP.h
+++ b/sysdeps/nptl/libc-lockP.h
@@ -1,5 +1,5 @@
/* Private libc-internal interface for mutex locks. NPTL version.
- Copyright (C) 1996-2016 Free Software Foundation, Inc.
+ 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
@@ -319,8 +319,6 @@ __libc_cleanup_routine (struct __pthread_cleanup_frame *f)
/* Register handlers to execute before and after `fork'. Note that the
last parameter is NULL. The handlers registered by the libc are
never removed so this is OK. */
-#define __libc_atfork(PREPARE, PARENT, CHILD) \
- __register_atfork (PREPARE, PARENT, CHILD, NULL)
extern int __register_atfork (void (*__prepare) (void),
void (*__parent) (void),
void (*__child) (void),
diff --git a/sysdeps/nptl/librt-cancellation.c b/sysdeps/nptl/librt-cancellation.c
index ce5a627b67..39c5991205 100644
--- a/sysdeps/nptl/librt-cancellation.c
+++ b/sysdeps/nptl/librt-cancellation.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2002-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
diff --git a/sysdeps/nptl/lowlevellock-futex.h b/sysdeps/nptl/lowlevellock-futex.h
index 9a976364f1..27b81b8347 100644
--- a/sysdeps/nptl/lowlevellock-futex.h
+++ b/sysdeps/nptl/lowlevellock-futex.h
@@ -1,5 +1,5 @@
/* Low-level locking access to futex facilities. Stub version.
- Copyright (C) 2014-2016 Free Software Foundation, Inc.
+ Copyright (C) 2014-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
diff --git a/sysdeps/nptl/lowlevellock.h b/sysdeps/nptl/lowlevellock.h
index 3890145402..bfbda99940 100644
--- a/sysdeps/nptl/lowlevellock.h
+++ b/sysdeps/nptl/lowlevellock.h
@@ -1,5 +1,5 @@
/* Low-level lock implementation. Generic futex-based version.
- Copyright (C) 2005-2016 Free Software Foundation, Inc.
+ Copyright (C) 2005-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
@@ -64,17 +64,16 @@
0. Otherwise leave lock unchanged and return non-zero to indicate that the
lock was not acquired. */
#define lll_trylock(lock) \
- atomic_compare_and_exchange_bool_acq (&(lock), 1, 0)
+ __glibc_unlikely (atomic_compare_and_exchange_bool_acq (&(lock), 1, 0))
/* If LOCK is 0 (not acquired), set to 2 (acquired, possibly with waiters) and
return 0. Otherwise leave lock unchanged and return non-zero to indicate
that the lock was not acquired. */
#define lll_cond_trylock(lock) \
- atomic_compare_and_exchange_bool_acq (&(lock), 2, 0)
+ __glibc_unlikely (atomic_compare_and_exchange_bool_acq (&(lock), 2, 0))
extern void __lll_lock_wait_private (int *futex) attribute_hidden;
extern void __lll_lock_wait (int *futex, int private) attribute_hidden;
-extern int __lll_robust_lock_wait (int *futex, int private) attribute_hidden;
/* This is an expression rather than a statement even though its value is
void, so that it can be used in a comma expression or as an expression
@@ -103,28 +102,6 @@ extern int __lll_robust_lock_wait (int *futex, int private) attribute_hidden;
__lll_lock (&(futex), private)
-/* If FUTEX is 0 (not acquired), set to ID (acquired with no waiters) and
- return 0. Otherwise, ensure that it is set to FUTEX | FUTEX_WAITERS
- (acquired, possibly with waiters) and block until we acquire the lock.
- FUTEX will now be ID | FUTEX_WAITERS and we return 0.
- If the previous owner of the lock dies before we acquire the lock then FUTEX
- will be the value of id as set by the previous owner, with FUTEX_OWNER_DIED
- set (FUTEX_WAITERS may or may not be set). We return this value to indicate
- that the lock is not acquired. */
-#define __lll_robust_lock(futex, id, private) \
- ({ \
- int *__futex = (futex); \
- int __val = 0; \
- \
- if (__glibc_unlikely \
- (atomic_compare_and_exchange_bool_acq (__futex, id, 0))) \
- __val = __lll_robust_lock_wait (__futex, private); \
- __val; \
- })
-#define lll_robust_lock(futex, id, private) \
- __lll_robust_lock (&(futex), id, private)
-
-
/* This is an expression rather than a statement even though its value is
void, so that it can be used in a comma expression or as an expression
that's cast to void. */
@@ -142,16 +119,8 @@ extern int __lll_robust_lock_wait (int *futex, int private) attribute_hidden;
#define lll_cond_lock(futex, private) __lll_cond_lock (&(futex), private)
-/* As __lll_robust_lock, but set to ID | FUTEX_WAITERS (acquired, possibly with
- waiters) if FUTEX is 0. */
-#define lll_robust_cond_lock(futex, id, private) \
- __lll_robust_lock (&(futex), (id) | FUTEX_WAITERS, private)
-
-
extern int __lll_timedlock_wait (int *futex, const struct timespec *,
int private) attribute_hidden;
-extern int __lll_robust_timedlock_wait (int *futex, const struct timespec *,
- int private) attribute_hidden;
/* As __lll_lock, but with a timeout. If the timeout occurs then return
@@ -170,22 +139,6 @@ extern int __lll_robust_timedlock_wait (int *futex, const struct timespec *,
__lll_timedlock (&(futex), abstime, private)
-/* As __lll_robust_lock, but with a timeout. If the timeout occurs then return
- ETIMEDOUT. If ABSTIME is invalid, return EINVAL. */
-#define __lll_robust_timedlock(futex, abstime, id, private) \
- ({ \
- int *__futex = (futex); \
- int __val = 0; \
- \
- if (__glibc_unlikely \
- (atomic_compare_and_exchange_bool_acq (__futex, id, 0))) \
- __val = __lll_robust_timedlock_wait (__futex, abstime, private); \
- __val; \
- })
-#define lll_robust_timedlock(futex, abstime, id, private) \
- __lll_robust_timedlock (&(futex), abstime, id, private)
-
-
/* This is an expression rather than a statement even though its value is
void, so that it can be used in a comma expression or as an expression
that's cast to void. */
@@ -211,27 +164,6 @@ extern int __lll_robust_timedlock_wait (int *futex, const struct timespec *,
__lll_unlock (&(futex), private)
-/* This is an expression rather than a statement even though its value is
- void, so that it can be used in a comma expression or as an expression
- that's cast to void. */
-/* Unconditionally set FUTEX to 0 (not acquired), releasing the lock. If FUTEX
- had FUTEX_WAITERS set then wake any waiters. The waiter that acquires the
- lock will set FUTEX_WAITERS.
- Evaluate PRIVATE before releasing the lock so that we do not violate the
- mutex destruction requirements (see __lll_unlock). */
-#define __lll_robust_unlock(futex, private) \
- ((void) \
- ({ \
- int *__futex = (futex); \
- int __private = (private); \
- int __oldval = atomic_exchange_rel (__futex, 0); \
- if (__glibc_unlikely (__oldval & FUTEX_WAITERS)) \
- lll_futex_wake (__futex, 1, __private); \
- }))
-#define lll_robust_unlock(futex, private) \
- __lll_robust_unlock (&(futex), private)
-
-
#define lll_islocked(futex) \
((futex) != LLL_LOCK_INITIALIZER)
@@ -249,11 +181,14 @@ extern int __lll_robust_timedlock_wait (int *futex, const struct timespec *,
thread ID while the clone is running and is reset to zero by the kernel
afterwards. The kernel up to version 3.16.3 does not use the private futex
operations for futex wake-up when the clone terminates. */
-#define lll_wait_tid(tid) \
- do { \
- __typeof (tid) __tid; \
- while ((__tid = (tid)) != 0) \
- lll_futex_wait (&(tid), __tid, LLL_SHARED);\
+#define lll_wait_tid(tid) \
+ do { \
+ __typeof (tid) __tid; \
+ /* We need acquire MO here so that we synchronize \
+ with the kernel's store to 0 when the clone \
+ terminates. (see above) */ \
+ while ((__tid = atomic_load_acquire (&(tid))) != 0) \
+ lll_futex_wait (&(tid), __tid, LLL_SHARED); \
} while (0)
extern int __lll_timedwait_tid (int *, const struct timespec *)
diff --git a/sysdeps/nptl/malloc-machine.h b/sysdeps/nptl/malloc-machine.h
index 5b276dfeb4..b038339054 100644
--- a/sysdeps/nptl/malloc-machine.h
+++ b/sysdeps/nptl/malloc-machine.h
@@ -1,6 +1,6 @@
/* Basic platform-independent macro definitions for mutexes,
thread-specific data and parameters for malloc.
- Copyright (C) 2003-2016 Free Software Foundation, Inc.
+ Copyright (C) 2003-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
@@ -20,43 +20,8 @@
#ifndef _MALLOC_MACHINE_H
#define _MALLOC_MACHINE_H
-#undef thread_atfork_static
-
#include <atomic.h>
#include <libc-lock.h>
-
-__libc_lock_define (typedef, mutex_t)
-
-#define mutex_init(m) __libc_lock_init (*(m))
-#define mutex_lock(m) __libc_lock_lock (*(m))
-#define mutex_trylock(m) __libc_lock_trylock (*(m))
-#define mutex_unlock(m) __libc_lock_unlock (*(m))
-
-/* This is defined by newer gcc version unique for each module. */
-extern void *__dso_handle __attribute__ ((__weak__));
-
-#include <fork.h>
-
-#define ATFORK_MEM static struct fork_handler atfork_mem
-
-#ifdef SHARED
-# define thread_atfork(prepare, parent, child) \
- atfork_mem.prepare_handler = prepare; \
- atfork_mem.parent_handler = parent; \
- atfork_mem.child_handler = child; \
- atfork_mem.dso_handle = __dso_handle; \
- atfork_mem.refcntr = 1; \
- __linkin_atfork (&atfork_mem)
-#else
-# define thread_atfork(prepare, parent, child) \
- atfork_mem.prepare_handler = prepare; \
- atfork_mem.parent_handler = parent; \
- atfork_mem.child_handler = child; \
- atfork_mem.dso_handle = &__dso_handle == NULL ? NULL : __dso_handle; \
- atfork_mem.refcntr = 1; \
- __linkin_atfork (&atfork_mem)
-#endif
-
#include <sysdeps/generic/malloc-machine.h>
#endif /* !defined(_MALLOC_MACHINE_H) */
diff --git a/sysdeps/nptl/nptl-signals.h b/sysdeps/nptl/nptl-signals.h
deleted file mode 100644
index 74e7df395c..0000000000
--- a/sysdeps/nptl/nptl-signals.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/* Special use of signals in NPTL internals. Stub version.
- Copyright (C) 2014-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/>. */
-
-/* This file can define the macros SIGCANCEL, SIGTIMER, and SIGSETXID to
- signal numbers reserved by libpthread for those internal purposes.
-
- Note that some code presumes SIGTIMER is the same as SIGCANCEL. */
diff --git a/sysdeps/nptl/pthread-functions.h b/sysdeps/nptl/pthread-functions.h
index 60f0ad566b..fa103695d9 100644
--- a/sysdeps/nptl/pthread-functions.h
+++ b/sysdeps/nptl/pthread-functions.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2003-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
@@ -74,7 +74,6 @@ struct pthread_functions
const pthread_mutexattr_t *);
int (*ptr_pthread_mutex_lock) (pthread_mutex_t *);
int (*ptr_pthread_mutex_unlock) (pthread_mutex_t *);
- pthread_t (*ptr_pthread_self) (void);
int (*ptr___pthread_setcancelstate) (int, int *);
int (*ptr_pthread_setcanceltype) (int, int *);
void (*ptr___pthread_cleanup_upto) (__jmp_buf, char *);
@@ -95,7 +94,6 @@ struct pthread_functions
__attribute ((noreturn)) __cleanup_fct_attribute;
void (*ptr__nptl_deallocate_tsd) (void);
int (*ptr__nptl_setxid) (struct xid_command *);
- void (*ptr_freeres) (void);
void (*ptr_set_robust) (struct pthread *);
};
diff --git a/sysdeps/nptl/pthread.h b/sysdeps/nptl/pthread.h
index fd0894efd2..df049abf74 100644
--- a/sysdeps/nptl/pthread.h
+++ b/sysdeps/nptl/pthread.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2002-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
@@ -26,6 +26,7 @@
#include <bits/pthreadtypes.h>
#include <bits/setjmp.h>
#include <bits/wordsize.h>
+#include <bits/types/struct_timespec.h>
/* Detach state. */
@@ -82,7 +83,7 @@ enum
#endif
-#ifdef __PTHREAD_MUTEX_HAVE_PREV
+#if __PTHREAD_MUTEX_HAVE_PREV
# define PTHREAD_MUTEX_INITIALIZER \
{ { 0, 0, 0, 0, 0, __PTHREAD_SPINS, { 0, 0 } } }
# ifdef __USE_GNU
@@ -183,7 +184,7 @@ enum
/* Conditional variable handling. */
-#define PTHREAD_COND_INITIALIZER { { 0, 0, 0, 0, 0, (void *) 0, 0, 0 } }
+#define PTHREAD_COND_INITIALIZER { { {0}, {0}, {0, 0}, {0, 0}, 0, 0, {0, 0} } }
/* Cleanup buffers */
diff --git a/sysdeps/nptl/setxid.h b/sysdeps/nptl/setxid.h
index 916ec43709..de39efc723 100644
--- a/sysdeps/nptl/setxid.h
+++ b/sysdeps/nptl/setxid.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2004-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2004-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
diff --git a/sysdeps/nptl/shm-directory.h b/sysdeps/nptl/shm-directory.h
index dfe5925b42..7452191626 100644
--- a/sysdeps/nptl/shm-directory.h
+++ b/sysdeps/nptl/shm-directory.h
@@ -1,5 +1,5 @@
/* Header for directory for shm/sem files. NPTL version.
- Copyright (C) 2014-2016 Free Software Foundation, Inc.
+ Copyright (C) 2014-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
diff --git a/sysdeps/nptl/sigfillset.c b/sysdeps/nptl/sigfillset.c
deleted file mode 100644
index 1c29fa445e..0000000000
--- a/sysdeps/nptl/sigfillset.c
+++ /dev/null
@@ -1,20 +0,0 @@
-/* Copyright (C) 2003-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/>. */
-
-#include <nptl/pthreadP.h>
-
-#include <signal/sigfillset.c>
diff --git a/sysdeps/nptl/stdio-lock.h b/sysdeps/nptl/stdio-lock.h
index d3a9092459..5b9782452f 100644
--- a/sysdeps/nptl/stdio-lock.h
+++ b/sysdeps/nptl/stdio-lock.h
@@ -1,5 +1,5 @@
/* Thread package specific definitions of stream lock type. NPTL version.
- Copyright (C) 2000-2016 Free Software Foundation, Inc.
+ Copyright (C) 2000-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
@@ -27,6 +27,7 @@
#define _IO_lock_inexpensive 1
typedef struct { int lock; int cnt; void *owner; } _IO_lock_t;
+#define _IO_lock_t_defined 1
#define _IO_lock_initializer { LLL_LOCK_INITIALIZER, 0, NULL }
@@ -89,13 +90,13 @@ typedef struct { int lock; int cnt; void *owner; } _IO_lock_t;
# ifdef __EXCEPTIONS
# define _IO_acquire_lock(_fp) \
do { \
- _IO_FILE *_IO_acquire_lock_file \
+ FILE *_IO_acquire_lock_file \
__attribute__((cleanup (_IO_acquire_lock_fct))) \
= (_fp); \
_IO_flockfile (_IO_acquire_lock_file);
# define _IO_acquire_lock_clear_flags2(_fp) \
do { \
- _IO_FILE *_IO_acquire_lock_file \
+ FILE *_IO_acquire_lock_file \
__attribute__((cleanup (_IO_acquire_lock_clear_flags2_fct))) \
= (_fp); \
_IO_flockfile (_IO_acquire_lock_file);
diff --git a/sysdeps/nptl/sys/procfs.h b/sysdeps/nptl/sys/procfs.h
index 66cc2c9b9e..d8c9383696 100644
--- a/sysdeps/nptl/sys/procfs.h
+++ b/sysdeps/nptl/sys/procfs.h
@@ -1,5 +1,5 @@
/* Types used by thread_db callback interface. Stub version.
- Copyright (C) 2015-2016 Free Software Foundation, Inc.
+ Copyright (C) 2015-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
diff --git a/sysdeps/nptl/threads.h b/sysdeps/nptl/threads.h
new file mode 100644
index 0000000000..9800f93aa7
--- /dev/null
+++ b/sysdeps/nptl/threads.h
@@ -0,0 +1,207 @@
+/* ISO C11 Standard: 7.26 - Thread support library <threads.h>.
+ Copyright (C) 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 _THREADS_H
+#define _THREADS_H 1
+
+#include <features.h>
+#include <time.h>
+
+__BEGIN_DECLS
+
+#include <bits/pthreadtypes-arch.h>
+#include <bits/types/struct_timespec.h>
+
+#ifndef __cplusplus
+# define thread_local _Thread_local
+#endif
+
+#define TSS_DTOR_ITERATIONS 4
+typedef unsigned int tss_t;
+typedef void (*tss_dtor_t) (void*);
+
+typedef unsigned long int thrd_t;
+typedef int (*thrd_start_t) (void*);
+
+/* Exit and error codes. */
+enum
+{
+ thrd_success = 0,
+ thrd_busy = 1,
+ thrd_error = 2,
+ thrd_nomem = 3,
+ thrd_timedout = 4
+};
+
+/* Mutex types. */
+enum
+{
+ mtx_plain = 0,
+ mtx_recursive = 1,
+ mtx_timed = 2
+};
+
+typedef struct
+{
+ int __data __ONCE_ALIGNMENT;
+} once_flag;
+#define ONCE_FLAG_INIT { 0 }
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_MUTEX_T];
+ long int __align __LOCK_ALIGNMENT;
+} mtx_t;
+
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_COND_T];
+ __extension__ long long int __align __LOCK_ALIGNMENT;
+} cnd_t;
+
+/* Threads functions. */
+
+/* Create a new thread executing the function __FUNC. Arguments for __FUNC
+ are passed through __ARG. If succesful, __THR is set to new thread
+ identifier. */
+extern int thrd_create (thrd_t *__thr, thrd_start_t __func, void *__arg);
+
+/* Check if __LHS and __RHS point to the same thread. */
+extern int thrd_equal (thrd_t __lhs, thrd_t __rhs);
+
+/* Return current thread identifier. */
+extern thrd_t thrd_current (void);
+
+/* Block current thread execution for at least the time pointed by
+ __TIME_POINT. The current thread may resume if receives a signal. In
+ that case, if __REMAINING is not NULL, the remaining time is stored in
+ the object pointed by it. */
+extern int thrd_sleep (const struct timespec *__time_point,
+ struct timespec *__remaining);
+
+/* Terminate current thread execution, cleaning up any thread local
+ storage and freeing resources. Returns the value specified in __RES. */
+extern void thrd_exit (int __res) __attribute__ ((__noreturn__));
+
+/* Detach the thread identified by __THR from the current environment
+ (it does not allow join or wait for it). */
+extern int thrd_detach (thrd_t __thr);
+
+/* Block current thread until execution of __THR is complete. In case that
+ __RES is not NULL, will store the return value of __THR when exiting. */
+extern int thrd_join (thrd_t __thr, int *__res);
+
+/* Stop current thread execution and call the scheduler to decide which
+ thread should execute next. The current thread may be selected by the
+ scheduler to keep running. */
+extern void thrd_yield (void);
+
+#ifdef __USE_EXTERN_INLINES
+/* Optimizations. */
+__extern_inline int
+thrd_equal (thrd_t __thread1, thrd_t __thread2)
+{
+ return __thread1 == __thread2;
+}
+#endif
+
+
+/* Mutex functions. */
+
+/* Creates a new mutex object with type __TYPE. If successful the new
+ object is pointed by __MUTEX. */
+extern int mtx_init (mtx_t *__mutex, int __type);
+
+/* Block the current thread until the mutex pointed to by __MUTEX is
+ unlocked. In that case current thread will not be blocked. */
+extern int mtx_lock (mtx_t *__mutex);
+
+/* Block the current thread until the mutex pointed by __MUTEX is unlocked
+ or time pointed by __TIME_POINT is reached. In case the mutex is unlock,
+ the current thread will not be blocked. */
+extern int mtx_timedlock (mtx_t *__restrict __mutex,
+ const struct timespec *__restrict __time_point);
+
+/* Try to lock the mutex pointed by __MUTEX without blocking. If the mutex
+ is free the current threads takes control of it, otherwise it returns
+ immediately. */
+extern int mtx_trylock (mtx_t *__mutex);
+
+/* Unlock the mutex pointed by __MUTEX. It may potentially awake other
+ threads waiting on this mutex. */
+extern int mtx_unlock (mtx_t *__mutex);
+
+/* Destroy the mutex object pointed by __MUTEX. */
+extern void mtx_destroy (mtx_t *__mutex);
+
+
+/* Call function __FUNC exactly once, even if invoked from several threads.
+ All calls must be made with the same __FLAGS object. */
+extern void call_once (once_flag *__flag, void (*__func)(void));
+
+
+/* Condition variable functions. */
+
+/* Initialize new condition variable pointed by __COND. */
+extern int cnd_init (cnd_t *__cond);
+
+/* Unblock one thread that currently waits on condition variable pointed
+ by __COND. */
+extern int cnd_signal (cnd_t *__cond);
+
+/* Unblock all threads currently waiting on condition variable pointed by
+ __COND. */
+extern int cnd_broadcast (cnd_t *__cond);
+
+/* Block current thread on the condition variable pointed by __COND. */
+extern int cnd_wait (cnd_t *__cond, mtx_t *__mutex);
+
+/* Block current thread on the condition variable until condition variable
+ pointed by __COND is signaled or time pointed by __TIME_POINT is
+ reached. */
+extern int cnd_timedwait (cnd_t *__restrict __cond,
+ mtx_t *__restrict __mutex,
+ const struct timespec *__restrict __time_point);
+
+/* Destroy condition variable pointed by __cond and free all of its
+ resources. */
+extern void cnd_destroy (cnd_t *__COND);
+
+
+/* Thread specific storage functions. */
+
+/* Create new thread-specific storage key and stores it in the object pointed
+ by __TSS_ID. If __DESTRUCTOR is not NULL, the function will be called when
+ the thread terminates. */
+extern int tss_create (tss_t *__tss_id, tss_dtor_t __destructor);
+
+/* Return the value held in thread-specific storage for the current thread
+ identified by __TSS_ID. */
+extern void *tss_get (tss_t __tss_id);
+
+/* Sets the value of the thread-specific storage identified by __TSS_ID for
+ the current thread to __VAL. */
+extern int tss_set (tss_t __tss_id, void *__val);
+
+/* Destroys the thread-specific storage identified by __TSS_ID. The
+ destructor is not called until thrd_exit is called. */
+extern void tss_delete (tss_t __tss_id);
+
+__END_DECLS
+
+#endif /* _THREADS_H */
diff --git a/sysdeps/nptl/timer_routines.h b/sysdeps/nptl/timer_routines.h
new file mode 100644
index 0000000000..9931015684
--- /dev/null
+++ b/sysdeps/nptl/timer_routines.h
@@ -0,0 +1,51 @@
+/* Helper code for POSIX timer implementation on NPTL.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Kaz Kylheku <kaz@ashi.footprints.net>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _TIMER_ROUTINES_H
+#define _TIMER_ROUTINES_H 1
+
+#include <internaltypes.h>
+#include <string.h>
+
+/* Compare two pthread_attr_t thread attributes for exact equality.
+ Returns 1 if they are equal, otherwise zero if they are not equal
+ or contain illegal values. This version is NPTL-specific for
+ performance reason. One could use the access functions to get the
+ values of all the fields of the attribute structure. */
+static inline int
+thread_attr_compare (const pthread_attr_t *left, const pthread_attr_t *right)
+{
+ struct pthread_attr *ileft = (struct pthread_attr *) left;
+ struct pthread_attr *iright = (struct pthread_attr *) right;
+
+ return (ileft->flags == iright->flags
+ && ileft->schedpolicy == iright->schedpolicy
+ && (ileft->schedparam.sched_priority
+ == iright->schedparam.sched_priority)
+ && ileft->guardsize == iright->guardsize
+ && ileft->stackaddr == iright->stackaddr
+ && ileft->stacksize == iright->stacksize
+ && ((ileft->cpuset == NULL && iright->cpuset == NULL)
+ || (ileft->cpuset != NULL && iright->cpuset != NULL
+ && ileft->cpusetsize == iright->cpusetsize
+ && memcmp (ileft->cpuset, iright->cpuset,
+ ileft->cpusetsize) == 0)));
+}
+
+#endif /* timer_routines.h */
diff --git a/sysdeps/nptl/unwind-forcedunwind.c b/sysdeps/nptl/unwind-forcedunwind.c
index ca757c48ce..5902fa4be7 100644
--- a/sysdeps/nptl/unwind-forcedunwind.c
+++ b/sysdeps/nptl/unwind-forcedunwind.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003-2016 Free Software Foundation, Inc.
+/* Copyright (C) 2003-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Jakub Jelinek <jakub@redhat.com>.
@@ -49,6 +49,7 @@ pthread_cancel_init (void)
return;
}
+ /* See include/dlfcn.h. Use of __libc_dlopen requires RTLD_NOW. */
handle = __libc_dlopen (LIBGCC_S_SO);
if (handle == NULL
@@ -78,9 +79,9 @@ pthread_cancel_init (void)
libgcc_s_handle = handle;
}
+/* Register for cleanup in libpthread.so. */
void
-__libc_freeres_fn_section
-__unwind_freeres (void)
+__nptl_unwind_freeres (void)
{
void *handle = libgcc_s_handle;
if (handle != NULL)