This is the mail archive of the
glibc-cvs@sourceware.org
mailing list for the glibc project.
GNU C Library master sources branch siddhesh/default_attr_api created. glibc-2.17-440-gb856f77
- From: "Siddhesh Poyarekar" <siddhesh at sourceware dot org>
- To: glibc-cvs at sourceware dot org
- Date: Tue, 19 Mar 2013 15:44:23 +0000
- Subject: GNU C Library master sources branch siddhesh/default_attr_api created. glibc-2.17-440-gb856f77
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, siddhesh/default_attr_api has been created
at b856f77bbe1cdab825f94b464d72c383f990c24b (commit)
- Log -----------------------------------------------------------------
http://sources.redhat.com/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=b856f77bbe1cdab825f94b464d72c383f990c24b
commit b856f77bbe1cdab825f94b464d72c383f990c24b
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
Date: Tue Mar 19 20:58:55 2013 +0530
New API to set default thread attributes
Second draft.
diff --git a/Versions.def b/Versions.def
index 7c7d1f8..8210a75 100644
--- a/Versions.def
+++ b/Versions.def
@@ -101,6 +101,7 @@ libpthread {
GLIBC_2.6
GLIBC_2.11
GLIBC_2.12
+ GLIBC_2.18
GLIBC_PRIVATE
}
libresolv {
diff --git a/nptl/Makefile b/nptl/Makefile
index 6af4b37..e7e226a 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -125,7 +125,8 @@ libpthread-routines = nptl-init vars events version \
pthread_mutexattr_setprioceiling tpp \
pthread_mutex_getprioceiling \
pthread_mutex_setprioceiling \
- pthread_setname pthread_getname
+ pthread_setname pthread_getname \
+ pthread_attr_set_default_np pthread_attr_get_default_np
# pthread_setuid pthread_seteuid pthread_setreuid \
# pthread_setresuid \
# pthread_setgid pthread_setegid pthread_setregid \
@@ -201,7 +202,7 @@ CFLAGS-pt-system.c = -fexceptions
tests = tst-typesizes \
- tst-attr1 tst-attr2 tst-attr3 \
+ tst-attr1 tst-attr2 tst-attr3 tst-default-attr \
tst-mutex1 tst-mutex2 tst-mutex3 tst-mutex4 tst-mutex5 tst-mutex6 \
tst-mutex7 tst-mutex8 tst-mutex9 tst-mutex5a tst-mutex7a \
tst-mutexpi1 tst-mutexpi2 tst-mutexpi3 tst-mutexpi4 tst-mutexpi5 \
diff --git a/nptl/Versions b/nptl/Versions
index 6a10375..69092e4 100644
--- a/nptl/Versions
+++ b/nptl/Versions
@@ -252,6 +252,11 @@ libpthread {
pthread_setname_np; pthread_getname_np;
};
+ GLIBC_2.18 {
+ pthread_attr_get_default_np;
+ pthread_attr_set_default_np;
+ }
+
GLIBC_PRIVATE {
__pthread_initialize_minimal;
__pthread_clock_gettime; __pthread_clock_settime;
diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
index 56bf257..714f315 100644
--- a/nptl/allocatestack.c
+++ b/nptl/allocatestack.c
@@ -357,8 +357,19 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
assert (TCB_ALIGNMENT >= STACK_ALIGN);
/* Get the stack size from the attribute if it is set. Otherwise we
- use the default we determined at start time. */
- size = attr->stacksize ?: __default_pthread_attr.stacksize;
+ use the default we determined at start time. Our lock attempt here will
+ never trip with the lock in pthread_create because the stacksize in
+ __default_pthread_attr_lock will never be zero. So if we deadlock on
+ ourselves here, it is because a bug led to
+ __default_pthread_attr.stacksize being zero. */
+ if (attr->stacksize)
+ size = attr->stacksize;
+ else
+ {
+ lll_lock (__default_pthread_attr_lock, LLL_PRIVATE);
+ size = __default_pthread_attr.stacksize;
+ lll_unlock (__default_pthread_attr_lock, LLL_PRIVATE);
+ }
/* Get memory for the stack. */
if (__builtin_expect (attr->flags & ATTR_FLAG_STACKADDR, 0))
@@ -921,6 +932,12 @@ __reclaim_stacks (void)
/* Initialize the lock. */
stack_cache_lock = LLL_LOCK_INITIALIZER;
+
+ /* Reset the default thread attributes to their defaults. */
+ memset (&__default_pthread_attr, 0, sizeof (__default_pthread_attr));
+ __default_pthread_attr.stacksize = __initial_stacksize;
+ __default_pthread_attr.guardsize = GLRO (dl_pagesize);
+ __default_pthread_attr_lock = LLL_LOCK_INITIALIZER;
}
diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c
index 63fb729..deb6c06 100644
--- a/nptl/nptl-init.c
+++ b/nptl/nptl-init.c
@@ -423,8 +423,11 @@ __pthread_initialize_minimal_internal (void)
/* Round the resource limit up to page size. */
limit.rlim_cur = (limit.rlim_cur + pagesz - 1) & -pagesz;
+ __initial_stacksize = limit.rlim_cur;
+ lll_lock (__default_pthread_attr_lock, LLL_PRIVATE);
__default_pthread_attr.stacksize = limit.rlim_cur;
__default_pthread_attr.guardsize = GLRO (dl_pagesize);
+ lll_unlock (__default_pthread_attr_lock, LLL_PRIVATE);
#ifdef SHARED
/* Transfer the old value from the dynamic linker's internal location. */
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index 6ca7124..91bbf20 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -149,6 +149,8 @@ enum
/* Default pthread attributes. */
extern struct pthread_attr __default_pthread_attr attribute_hidden;
+extern int __default_pthread_attr_lock attribute_hidden;
+extern size_t __initial_stacksize attribute_hidden;
/* Size and alignment of static TLS block. */
extern size_t __static_tls_size attribute_hidden;
diff --git a/nptl/pthread_attr_getstacksize.c b/nptl/pthread_attr_get_default_np.c
similarity index 55%
copy from nptl/pthread_attr_getstacksize.c
copy to nptl/pthread_attr_get_default_np.c
index 42d3f8f..ef52df7 100644
--- a/nptl/pthread_attr_getstacksize.c
+++ b/nptl/pthread_attr_get_default_np.c
@@ -1,6 +1,6 @@
-/* Copyright (C) 2002-2013 Free Software Foundation, Inc.
+/* Get the default attributes used by pthread_create in the process.
+ Copyright (C) 2013 Free Software Foundation, Inc.
This file is part of the GNU C Library.
- Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -16,24 +16,22 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+#include <errno.h>
+#include <stdlib.h>
+#include <pthreadP.h>
#include <assert.h>
-#include "pthreadP.h"
-
int
-__pthread_attr_getstacksize (attr, stacksize)
- const pthread_attr_t *attr;
- size_t *stacksize;
+pthread_attr_get_default_np (pthread_attr_t *out)
{
- struct pthread_attr *iattr;
+ struct pthread_attr *real_out;
- assert (sizeof (*attr) >= sizeof (struct pthread_attr));
- iattr = (struct pthread_attr *) attr;
+ assert (sizeof (*out) >= sizeof (struct pthread_attr));
+ real_out = (struct pthread_attr *) out;
- /* If the user has not set a stack size we return what the system
- will use as the default. */
- *stacksize = iattr->stacksize ?: __default_pthread_attr.stacksize;
+ lll_lock (__default_pthread_attr_lock, LLL_PRIVATE);
+ *real_out = __default_pthread_attr;
+ lll_unlock (__default_pthread_attr_lock, LLL_PRIVATE);
return 0;
}
-strong_alias (__pthread_attr_getstacksize, pthread_attr_getstacksize)
diff --git a/nptl/pthread_attr_getstacksize.c b/nptl/pthread_attr_getstacksize.c
index 42d3f8f..bf0070d 100644
--- a/nptl/pthread_attr_getstacksize.c
+++ b/nptl/pthread_attr_getstacksize.c
@@ -32,7 +32,14 @@ __pthread_attr_getstacksize (attr, stacksize)
/* If the user has not set a stack size we return what the system
will use as the default. */
- *stacksize = iattr->stacksize ?: __default_pthread_attr.stacksize;
+ if (iattr->stacksize)
+ *stacksize = iattr->stacksize;
+ else
+ {
+ lll_lock (__default_pthread_attr_lock, LLL_PRIVATE);
+ *stacksize = __default_pthread_attr.stacksize;
+ lll_unlock (__default_pthread_attr_lock, LLL_PRIVATE);
+ }
return 0;
}
diff --git a/nptl/pthread_attr_set_default_np.c b/nptl/pthread_attr_set_default_np.c
new file mode 100644
index 0000000..055d09b
--- /dev/null
+++ b/nptl/pthread_attr_set_default_np.c
@@ -0,0 +1,100 @@
+/* Set the default attributes to be used by pthread_create in the process.
+ Copyright (C) 2013 Free Software Foundation, Inc.
+ This file is part of the 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 <errno.h>
+#include <stdlib.h>
+#include <pthreadP.h>
+#include <assert.h>
+
+int
+pthread_attr_set_default_np (const pthread_attr_t *in)
+{
+ struct pthread_attr *real_in, attrs;
+ int ret;
+
+ assert (sizeof (*in) >= sizeof (struct pthread_attr));
+ real_in = (struct pthread_attr *) in;
+
+ /* Catch invalid values. */
+ int policy = real_in->schedpolicy;
+
+ if ((ret = check_sched_policy_attr (policy)) != 0)
+ return ret;
+
+ struct sched_param *param = &real_in->schedparam;
+
+ if (param->sched_priority > 0
+ && (ret = check_sched_priority_attr (param->sched_priority,
+ policy)) != 0)
+ return ret;
+
+ if ((ret = check_cpuset_attr (real_in->cpuset, real_in->cpusetsize)) != 0)
+ return ret;
+
+ /* stacksize == 0 is fine. It means that we don't change the current
+ value. */
+ if (real_in->stacksize != 0
+ && (ret = check_stacksize_attr (real_in->stacksize)) != 0)
+ return ret;
+
+ /* Having a default stack address is wrong. */
+ if (real_in->flags & ATTR_FLAG_STACKADDR)
+ return EINVAL;
+
+ attrs = *real_in;
+
+ /* Mantain stacksize as a non-zero value. This is a computed fallback that
+ we get on library initialization, so we don't want to overwrite it unless
+ there is a valid value to replace it. */
+ if (real_in->stacksize > 0)
+ attrs.stacksize = real_in->stacksize;
+
+ /* Now take the lock because we start writing into
+ __default_pthread_attr. */
+ lll_lock (__default_pthread_attr_lock, LLL_PRIVATE);
+
+ /* Free the cpuset if the input is 0. Otherwise copy in the cpuset
+ contents. */
+ if (attrs.cpuset == NULL || attrs.cpusetsize == 0)
+ free (__default_pthread_attr.cpuset);
+ else if (attrs.cpusetsize != __default_pthread_attr.cpusetsize)
+ {
+ /* This may look wrong at first sight, but it isn't. We're freeing
+ __default_pthread_attr.cpuset and allocating to attrs.cpuset because
+ we'll copy over all of attr to __default_pthread_attr later. */
+ void *newp = (cpu_set_t *) realloc (__default_pthread_attr.cpuset,
+ attrs.cpusetsize);
+
+ if (newp == NULL)
+ {
+ ret = ENOMEM;
+ goto out;
+ }
+
+ attrs.cpuset = newp;
+ }
+ else
+ attrs.cpuset = __default_pthread_attr.cpuset;
+
+ memcpy (attrs.cpuset, real_in->cpuset, real_in->cpusetsize);
+ __default_pthread_attr = attrs;
+
+ out:
+ lll_unlock (__default_pthread_attr_lock, LLL_PRIVATE);
+ return ret;
+}
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index fb8df2d..1cbb4a3 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -446,17 +446,25 @@ __pthread_create_2_1 (newthread, attr, start_routine, arg)
const struct pthread_attr *iattr = (struct pthread_attr *) attr;
if (iattr == NULL)
- /* Is this the best idea? On NUMA machines this could mean
- accessing far-away memory. */
- iattr = &__default_pthread_attr;
+ {
+ /* Is this the best idea? On NUMA machines this could mean
+ accessing far-away memory. */
+ iattr = &__default_pthread_attr;
+ lll_lock (__default_pthread_attr_lock, LLL_PRIVATE);
+ }
struct pthread *pd = NULL;
int err = ALLOCATE_STACK (iattr, &pd);
+ int retval = 0;
+
if (__builtin_expect (err != 0, 0))
/* Something went wrong. Maybe a parameter of the attributes is
invalid or we could not allocate memory. Note we have to
translate error codes. */
- return err == ENOMEM ? EAGAIN : err;
+ {
+ retval = err == ENOMEM ? EAGAIN : err;
+ goto out;
+ }
/* Initialize the TCB. All initializations with zero should be
@@ -507,8 +515,7 @@ __pthread_create_2_1 (newthread, attr, start_routine, arg)
#endif
/* Determine scheduling parameters for the thread. */
- if (attr != NULL
- && __builtin_expect ((iattr->flags & ATTR_FLAG_NOTINHERITSCHED) != 0, 0)
+ if (__builtin_expect ((iattr->flags & ATTR_FLAG_NOTINHERITSCHED) != 0, 0)
&& (iattr->flags & (ATTR_FLAG_SCHED_SET | ATTR_FLAG_POLICY_SET)) != 0)
{
INTERNAL_SYSCALL_DECL (scerr);
@@ -543,7 +550,8 @@ __pthread_create_2_1 (newthread, attr, start_routine, arg)
__deallocate_stack (pd);
- return EINVAL;
+ retval = EINVAL;
+ goto out;
}
}
@@ -553,7 +561,13 @@ __pthread_create_2_1 (newthread, attr, start_routine, arg)
LIBC_PROBE (pthread_create, 4, newthread, attr, start_routine, arg);
/* Start the thread. */
- return create_thread (pd, iattr, STACK_VARIABLES_ARGS);
+ retval = create_thread (pd, iattr, STACK_VARIABLES_ARGS);
+
+ out:
+ if (attr == NULL)
+ lll_unlock (__default_pthread_attr_lock, LLL_PRIVATE);
+
+ return retval;
}
versioned_symbol (libpthread, __pthread_create_2_1, pthread_create, GLIBC_2_1);
diff --git a/nptl/sysdeps/pthread/pthread.h b/nptl/sysdeps/pthread/pthread.h
index 10bcb80..93a8b11 100644
--- a/nptl/sysdeps/pthread/pthread.h
+++ b/nptl/sysdeps/pthread/pthread.h
@@ -404,6 +404,14 @@ extern int pthread_attr_getaffinity_np (const pthread_attr_t *__attr,
cpu_set_t *__cpuset)
__THROW __nonnull ((1, 3));
+/* Get the default attributes used by pthread_create in this process. */
+extern int pthread_attr_get_default_np (pthread_attr_t *__attr)
+ __THROW __nonnull ((1));
+
+/* Set the default attributes to be used by pthread_create in this
+ process. */
+extern int pthread_attr_set_default_np (const pthread_attr_t *__attr)
+ __THROW __nonnull ((1));
/* Initialize thread attribute *ATTR with attributes corresponding to the
already running thread TH. It shall be called on uninitialized ATTR
diff --git a/nptl/tst-default-attr.c b/nptl/tst-default-attr.c
new file mode 100644
index 0000000..867e91e
--- /dev/null
+++ b/nptl/tst-default-attr.c
@@ -0,0 +1,161 @@
+/* Verify that pthread_attr_[gs]et_default work correctly.
+
+ Copyright (C) 2013 Free Software Foundation, Inc.
+ This file is part of the 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 <pthread.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+static size_t stacksize = 1024 * 1024;
+
+void *
+verify_result (pthread_attr_t *attr)
+{
+ int ret;
+ size_t stack;
+
+ if ((ret = pthread_attr_getstacksize (attr, &stack)) != 0)
+ {
+ printf ("pthread_attr_getstacksize failed: %s\n", strerror (ret));
+ return (void *) (uintptr_t) 1;
+ }
+
+ if (stacksize != stack)
+ {
+ printf ("pthread_attr_set_default failed for stacksize (%zu, %zu)\n",
+ stacksize, stack);
+ return (void *) (uintptr_t) 1;
+ }
+
+ return NULL;
+}
+
+void *
+thr (void *unused)
+{
+ pthread_attr_t attr;
+ int ret;
+
+ /* To verify that the set_default_np worked. */
+ puts ("verifying pthread_attr_get_default_np");
+ if ((ret = pthread_attr_get_default_np (&attr)) != 0)
+ {
+ printf ("pthread_attr_get_default_np failed: %s\n", strerror (ret));
+ return (void *) (uintptr_t) 1;
+ }
+
+ if (verify_result (&attr))
+ return (void *) (uintptr_t) 1;
+
+ /* To verify that the attributes actually got applied. */
+ puts ("verifying pthread_getattr_np");
+ if ((ret = pthread_getattr_np (pthread_self (), &attr)) != 0)
+ {
+ printf ("pthread_getattr_np failed: %s\n", strerror (ret));
+ return (void *) (uintptr_t) 1;
+ }
+
+ return verify_result (&attr);
+}
+
+int
+run_threads (void)
+{
+ pthread_t t;
+ pthread_attr_t attr;
+ int ret, i;
+ void *tret;
+
+ if ((ret = pthread_attr_init (&attr)) != 0)
+ {
+ printf ("pthread_attr_init failed: %s\n", strerror (ret));
+ return 1;
+ }
+
+ if ((ret = pthread_attr_setstacksize (&attr, stacksize)) != 0)
+ {
+ printf ("pthread_attr_setstacksize failed: %s\n", strerror (ret));
+ return 1;
+ }
+
+ if ((ret = pthread_attr_set_default_np (&attr)) != 0)
+ {
+ printf ("pthread_attr_set_default_np failed: %s\n", strerror (ret));
+ return 1;
+ }
+
+ /* Run twice to ensure that the attributes do not get overwritten in the
+ first run somehow. */
+ for (i = 0; i < 2; i++)
+ {
+ if ((ret = pthread_create (&t, NULL, thr, NULL)) != 0)
+ {
+ printf ("pthread_create failed: %s\n", strerror (ret));
+ return 1;
+ }
+
+ if ((ret = pthread_join (t, &tret)) != 0)
+ {
+ printf ("pthread_join failed: %s\n", strerror (ret));
+ return 1;
+ }
+
+ if (tret != NULL)
+ {
+ puts ("Thread failed\n");
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+int
+do_test (void)
+{
+ long pagesize = sysconf (_SC_PAGESIZE);
+
+ if (pagesize < 0)
+ {
+ printf ("sysconf failed: %s\n", strerror (errno));
+ return 1;
+ }
+
+ /* Perturb the size by a page so that we're not aligned on the 64K boundary.
+ pthread_create does this perturbation on x86 to avoid causing the 64k
+ aliasing conflict. We want to prevent pthread_create from doing that
+ since it is not consistent for all architectures. */
+ stacksize += pagesize;
+
+ /* Run twice to ensure that we don't give a false positive. */
+ puts ("First iteration");
+ int ret = run_threads ();
+
+ if (ret)
+ return 1;
+
+ puts ("Second iteration");
+ stacksize *= 2;
+ return run_threads ();
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/nptl/vars.c b/nptl/vars.c
index 45ca486..5cc16af 100644
--- a/nptl/vars.c
+++ b/nptl/vars.c
@@ -24,6 +24,12 @@
provide any. */
struct pthread_attr __default_pthread_attr attribute_hidden;
+/* Mutex protecting __default_pthread_attr. */
+int __default_pthread_attr_lock = LLL_LOCK_INITIALIZER;
+
+/*Initial stack size. Written only once during initialization. */
+size_t __initial_stacksize attribute_hidden;
+
/* Flag whether the machine is SMP or not. */
int __is_smp attribute_hidden;
diff --git a/ports/sysdeps/unix/sysv/linux/aarch64/nptl/libpthread.abilist b/ports/sysdeps/unix/sysv/linux/aarch64/nptl/libpthread.abilist
index 696158a..f24e2e8 100644
--- a/ports/sysdeps/unix/sysv/linux/aarch64/nptl/libpthread.abilist
+++ b/ports/sysdeps/unix/sysv/linux/aarch64/nptl/libpthread.abilist
@@ -222,3 +222,7 @@ GLIBC_2.17
wait F
waitpid F
write F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
diff --git a/ports/sysdeps/unix/sysv/linux/alpha/nptl/libpthread.abilist b/ports/sysdeps/unix/sysv/linux/alpha/nptl/libpthread.abilist
index 9626730..191c00d 100644
--- a/ports/sysdeps/unix/sysv/linux/alpha/nptl/libpthread.abilist
+++ b/ports/sysdeps/unix/sysv/linux/alpha/nptl/libpthread.abilist
@@ -174,6 +174,10 @@ GLIBC_2.12
pthread_mutexattr_getrobust F
pthread_mutexattr_setrobust F
pthread_setname_np F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
GLIBC_2.2
GLIBC_2.2 A
__open64 F
diff --git a/ports/sysdeps/unix/sysv/linux/arm/nptl/libpthread.abilist b/ports/sysdeps/unix/sysv/linux/arm/nptl/libpthread.abilist
index de8095a..d7abe69 100644
--- a/ports/sysdeps/unix/sysv/linux/arm/nptl/libpthread.abilist
+++ b/ports/sysdeps/unix/sysv/linux/arm/nptl/libpthread.abilist
@@ -8,6 +8,10 @@ GLIBC_2.12
pthread_mutexattr_getrobust F
pthread_mutexattr_setrobust F
pthread_setname_np F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
GLIBC_2.4
GLIBC_2.4 A
_IO_flockfile F
diff --git a/ports/sysdeps/unix/sysv/linux/ia64/nptl/libpthread.abilist b/ports/sysdeps/unix/sysv/linux/ia64/nptl/libpthread.abilist
index b7749e2..43df60b 100644
--- a/ports/sysdeps/unix/sysv/linux/ia64/nptl/libpthread.abilist
+++ b/ports/sysdeps/unix/sysv/linux/ia64/nptl/libpthread.abilist
@@ -8,6 +8,10 @@ GLIBC_2.12
pthread_mutexattr_getrobust F
pthread_mutexattr_setrobust F
pthread_setname_np F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
GLIBC_2.2
GLIBC_2.2 A
_IO_flockfile F
diff --git a/ports/sysdeps/unix/sysv/linux/m68k/coldfire/nptl/libpthread.abilist b/ports/sysdeps/unix/sysv/linux/m68k/coldfire/nptl/libpthread.abilist
index de8095a..d7abe69 100644
--- a/ports/sysdeps/unix/sysv/linux/m68k/coldfire/nptl/libpthread.abilist
+++ b/ports/sysdeps/unix/sysv/linux/m68k/coldfire/nptl/libpthread.abilist
@@ -8,6 +8,10 @@ GLIBC_2.12
pthread_mutexattr_getrobust F
pthread_mutexattr_setrobust F
pthread_setname_np F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
GLIBC_2.4
GLIBC_2.4 A
_IO_flockfile F
diff --git a/ports/sysdeps/unix/sysv/linux/m68k/m680x0/nptl/libpthread.abilist b/ports/sysdeps/unix/sysv/linux/m68k/m680x0/nptl/libpthread.abilist
index 827114f..ece7edf 100644
--- a/ports/sysdeps/unix/sysv/linux/m68k/m680x0/nptl/libpthread.abilist
+++ b/ports/sysdeps/unix/sysv/linux/m68k/m680x0/nptl/libpthread.abilist
@@ -174,6 +174,10 @@ GLIBC_2.12
pthread_mutexattr_getrobust F
pthread_mutexattr_setrobust F
pthread_setname_np F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
GLIBC_2.2
GLIBC_2.2 A
__open64 F
diff --git a/ports/sysdeps/unix/sysv/linux/mips/mips32/nptl/libpthread.abilist b/ports/sysdeps/unix/sysv/linux/mips/mips32/nptl/libpthread.abilist
index c3ba9d4..05cfb3d 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/mips32/nptl/libpthread.abilist
+++ b/ports/sysdeps/unix/sysv/linux/mips/mips32/nptl/libpthread.abilist
@@ -130,6 +130,10 @@ GLIBC_2.12
pthread_mutexattr_getrobust F
pthread_mutexattr_setrobust F
pthread_setname_np F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
GLIBC_2.2
GLIBC_2.2 A
__libc_allocate_rtsig F
diff --git a/ports/sysdeps/unix/sysv/linux/mips/mips64/n32/nptl/libpthread.abilist b/ports/sysdeps/unix/sysv/linux/mips/mips64/n32/nptl/libpthread.abilist
index 4e0b07f..71634eb 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/mips64/n32/nptl/libpthread.abilist
+++ b/ports/sysdeps/unix/sysv/linux/mips/mips64/n32/nptl/libpthread.abilist
@@ -130,6 +130,10 @@ GLIBC_2.12
pthread_mutexattr_getrobust F
pthread_mutexattr_setrobust F
pthread_setname_np F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
GLIBC_2.2
GLIBC_2.2 A
__libc_allocate_rtsig F
diff --git a/ports/sysdeps/unix/sysv/linux/mips/mips64/n64/nptl/libpthread.abilist b/ports/sysdeps/unix/sysv/linux/mips/mips64/n64/nptl/libpthread.abilist
index 4e0b07f..71634eb 100644
--- a/ports/sysdeps/unix/sysv/linux/mips/mips64/n64/nptl/libpthread.abilist
+++ b/ports/sysdeps/unix/sysv/linux/mips/mips64/n64/nptl/libpthread.abilist
@@ -130,6 +130,10 @@ GLIBC_2.12
pthread_mutexattr_getrobust F
pthread_mutexattr_setrobust F
pthread_setname_np F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
GLIBC_2.2
GLIBC_2.2 A
__libc_allocate_rtsig F
diff --git a/ports/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/nptl/libpthread.abilist b/ports/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/nptl/libpthread.abilist
index 7719099..18d24ed 100644
--- a/ports/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/nptl/libpthread.abilist
+++ b/ports/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/nptl/libpthread.abilist
@@ -174,6 +174,10 @@ GLIBC_2.12
pthread_mutexattr_getrobust F
pthread_mutexattr_setrobust F
pthread_setname_np F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
GLIBC_2.2
GLIBC_2.2 A
__open64 F
diff --git a/ports/sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/nptl/libpthread.abilist b/ports/sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/nptl/libpthread.abilist
index 658c4bf..de4f231 100644
--- a/ports/sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/nptl/libpthread.abilist
+++ b/ports/sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/nptl/libpthread.abilist
@@ -222,3 +222,7 @@ GLIBC_2.12
wait F
waitpid F
write F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
diff --git a/ports/sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/nptl/libpthread.abilist b/ports/sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/nptl/libpthread.abilist
index 658c4bf..de4f231 100644
--- a/ports/sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/nptl/libpthread.abilist
+++ b/ports/sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/nptl/libpthread.abilist
@@ -222,3 +222,7 @@ GLIBC_2.12
wait F
waitpid F
write F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
diff --git a/ports/sysdeps/unix/sysv/linux/tile/tilepro/nptl/libpthread.abilist b/ports/sysdeps/unix/sysv/linux/tile/tilepro/nptl/libpthread.abilist
index 658c4bf..de4f231 100644
--- a/ports/sysdeps/unix/sysv/linux/tile/tilepro/nptl/libpthread.abilist
+++ b/ports/sysdeps/unix/sysv/linux/tile/tilepro/nptl/libpthread.abilist
@@ -222,3 +222,7 @@ GLIBC_2.12
wait F
waitpid F
write F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
diff --git a/sysdeps/unix/sysv/linux/i386/nptl/libpthread.abilist b/sysdeps/unix/sysv/linux/i386/nptl/libpthread.abilist
index 827114f..ece7edf 100644
--- a/sysdeps/unix/sysv/linux/i386/nptl/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/i386/nptl/libpthread.abilist
@@ -174,6 +174,10 @@ GLIBC_2.12
pthread_mutexattr_getrobust F
pthread_mutexattr_setrobust F
pthread_setname_np F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
GLIBC_2.2
GLIBC_2.2 A
__open64 F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/nptl/libpthread.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/nptl/libpthread.abilist
index 7719099..18d24ed 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/nptl/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/nptl/libpthread.abilist
@@ -174,6 +174,10 @@ GLIBC_2.12
pthread_mutexattr_getrobust F
pthread_mutexattr_setrobust F
pthread_setname_np F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
GLIBC_2.2
GLIBC_2.2 A
__open64 F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/nptl/libpthread.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/nptl/libpthread.abilist
index 7930c75..1ccc2e7 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/nptl/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/nptl/libpthread.abilist
@@ -8,6 +8,10 @@ GLIBC_2.12
pthread_mutexattr_getrobust F
pthread_mutexattr_setrobust F
pthread_setname_np F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
GLIBC_2.3
GLIBC_2.3 A
_IO_flockfile F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/nptl/libpthread.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/nptl/libpthread.abilist
index 827114f..ece7edf 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/nptl/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/nptl/libpthread.abilist
@@ -174,6 +174,10 @@ GLIBC_2.12
pthread_mutexattr_getrobust F
pthread_mutexattr_setrobust F
pthread_setname_np F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
GLIBC_2.2
GLIBC_2.2 A
__open64 F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/nptl/libpthread.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/nptl/libpthread.abilist
index 596fdd3..ef9786b 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-64/nptl/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/nptl/libpthread.abilist
@@ -8,6 +8,10 @@ GLIBC_2.12
pthread_mutexattr_getrobust F
pthread_mutexattr_setrobust F
pthread_setname_np F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
GLIBC_2.2
GLIBC_2.2 A
_IO_flockfile F
diff --git a/sysdeps/unix/sysv/linux/sh/nptl/libpthread.abilist b/sysdeps/unix/sysv/linux/sh/nptl/libpthread.abilist
index 596fdd3..ef9786b 100644
--- a/sysdeps/unix/sysv/linux/sh/nptl/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/sh/nptl/libpthread.abilist
@@ -8,6 +8,10 @@ GLIBC_2.12
pthread_mutexattr_getrobust F
pthread_mutexattr_setrobust F
pthread_setname_np F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
GLIBC_2.2
GLIBC_2.2 A
_IO_flockfile F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/nptl/libpthread.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/nptl/libpthread.abilist
index 9626730..191c00d 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/nptl/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/nptl/libpthread.abilist
@@ -174,6 +174,10 @@ GLIBC_2.12
pthread_mutexattr_getrobust F
pthread_mutexattr_setrobust F
pthread_setname_np F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
GLIBC_2.2
GLIBC_2.2 A
__open64 F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/nptl/libpthread.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/nptl/libpthread.abilist
index b7749e2..43df60b 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/nptl/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/nptl/libpthread.abilist
@@ -8,6 +8,10 @@ GLIBC_2.12
pthread_mutexattr_getrobust F
pthread_mutexattr_setrobust F
pthread_setname_np F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
GLIBC_2.2
GLIBC_2.2 A
_IO_flockfile F
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/nptl/libpthread.abilist b/sysdeps/unix/sysv/linux/x86_64/64/nptl/libpthread.abilist
index 7c33f35..8d3c68e 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/nptl/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/64/nptl/libpthread.abilist
@@ -8,6 +8,10 @@ GLIBC_2.12
pthread_mutexattr_getrobust F
pthread_mutexattr_setrobust F
pthread_setname_np F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
GLIBC_2.2.5
GLIBC_2.2.5 A
_IO_flockfile F
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/nptl/libpthread.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/nptl/libpthread.abilist
index b07d16f..fe53c17 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/nptl/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/nptl/libpthread.abilist
@@ -222,3 +222,7 @@ GLIBC_2.16
wait F
waitpid F
write F
+GLIBC_2.18
+ GLIBC_2.18 A
+ pthread_attr_get_default_np F
+ pthread_attr_set_default_np F
http://sources.redhat.com/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=b53cecd89b9521ecfc3a15d019d8cacb533efcc6
commit b53cecd89b9521ecfc3a15d019d8cacb533efcc6
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
Date: Tue Mar 19 21:13:51 2013 +0530
Consolidate pthread_attr value validation
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index 954b54a..6ca7124 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -589,4 +589,68 @@ extern void __wait_lookup_done (void) attribute_hidden;
# define USE_REQUEUE_PI(mut) 0
#endif
+#include <errno.h>
+
+/* Returns 0 if POL is a valid scheduling policy. */
+static inline int __attribute__((always_inline))
+check_sched_policy_attr (int pol)
+{
+ if (pol == SCHED_OTHER || pol == SCHED_FIFO || pol == SCHED_RR)
+ return 0;
+
+ return EINVAL;
+}
+
+/* Returns 0 if PR is within the accepted range of priority values for
+ the scheduling policy POL or EINVAL otherwise. */
+static inline int __attribute__((always_inline))
+check_sched_priority_attr (int pr, int pol)
+{
+ int min = sched_get_priority_min (pol);
+ int max = sched_get_priority_max (pol);
+
+ if (min >= 0 && max >= 0 && pr >= min && pr <= max)
+ return 0;
+
+ return EINVAL;
+}
+
+/* Returns 0 if ST is a valid stack size for a thread stack and EINVAL
+ otherwise. */
+static inline int __attribute__((always_inline))
+check_stacksize_attr (size_t st)
+{
+ if (st >= PTHREAD_STACK_MIN)
+ return 0;
+
+ return EINVAL;
+}
+
+/* Defined in pthread_setaffinity.c. */
+extern size_t __kernel_cpumask_size attribute_hidden;
+extern int __determine_cpumask_size (pid_t tid);
+
+/* Returns 0 if CS and SZ are valid values for the cpuset and cpuset size
+ respectively. Otherwise it returns an error number. */
+static inline int __attribute__ ((always_inline))
+check_cpuset_attr (const cpu_set_t *cs, const size_t sz)
+{
+ if (__kernel_cpumask_size == 0)
+ {
+ int res = __determine_cpumask_size (THREAD_SELF->tid);
+ if (res != 0)
+ return res;
+ }
+
+ /* Check whether the new bitmask has any bit set beyond the
+ last one the kernel accepts. */
+ for (size_t cnt = __kernel_cpumask_size; cnt < sz; ++cnt)
+ if (((char *) cs)[cnt] != '\0')
+ /* Found a nonzero byte. This means the user request cannot be
+ fulfilled. */
+ return EINVAL;
+
+ return 0;
+}
+
#endif /* pthreadP.h */
diff --git a/nptl/pthread_attr_setschedparam.c b/nptl/pthread_attr_setschedparam.c
index ec1a8bd..6a135e5 100644
--- a/nptl/pthread_attr_setschedparam.c
+++ b/nptl/pthread_attr_setschedparam.c
@@ -30,11 +30,10 @@ __pthread_attr_setschedparam (attr, param)
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
struct pthread_attr *iattr = (struct pthread_attr *) attr;
- int min = sched_get_priority_min (iattr->schedpolicy);
- int max = sched_get_priority_max (iattr->schedpolicy);
- if (min == -1 || max == -1
- || param->sched_priority > max || param->sched_priority < min)
- return EINVAL;
+ int ret;
+ if ((ret = check_sched_priority_attr (param->sched_priority,
+ iattr->schedpolicy)) != 0)
+ return ret;
/* Copy the new values. */
memcpy (&iattr->schedparam, param, sizeof (struct sched_param));
diff --git a/nptl/pthread_attr_setschedpolicy.c b/nptl/pthread_attr_setschedpolicy.c
index 2fa6921..187b42c 100644
--- a/nptl/pthread_attr_setschedpolicy.c
+++ b/nptl/pthread_attr_setschedpolicy.c
@@ -32,8 +32,9 @@ __pthread_attr_setschedpolicy (attr, policy)
iattr = (struct pthread_attr *) attr;
/* Catch invalid values. */
- if (policy != SCHED_OTHER && policy != SCHED_FIFO && policy != SCHED_RR)
- return EINVAL;
+ int ret;
+ if ((ret = check_sched_policy_attr (policy)) != 0)
+ return ret;
/* Store the new values. */
iattr->schedpolicy = policy;
diff --git a/nptl/pthread_attr_setstack.c b/nptl/pthread_attr_setstack.c
index 783cffe..a7b4442 100644
--- a/nptl/pthread_attr_setstack.c
+++ b/nptl/pthread_attr_setstack.c
@@ -39,8 +39,9 @@ __pthread_attr_setstack (attr, stackaddr, stacksize)
iattr = (struct pthread_attr *) attr;
/* Catch invalid sizes. */
- if (stacksize < PTHREAD_STACK_MIN)
- return EINVAL;
+ int ret;
+ if ((ret = check_stacksize_attr (stacksize)) != 0)
+ return ret;
#ifdef EXTRA_PARAM_CHECKS
EXTRA_PARAM_CHECKS;
diff --git a/nptl/pthread_attr_setstacksize.c b/nptl/pthread_attr_setstacksize.c
index b7f2919..80898c8 100644
--- a/nptl/pthread_attr_setstacksize.c
+++ b/nptl/pthread_attr_setstacksize.c
@@ -37,8 +37,9 @@ __pthread_attr_setstacksize (attr, stacksize)
iattr = (struct pthread_attr *) attr;
/* Catch invalid sizes. */
- if (stacksize < PTHREAD_STACK_MIN)
- return EINVAL;
+ int ret;
+ if ((ret = check_stacksize_attr (stacksize)) != 0)
+ return ret;
iattr->stacksize = stacksize;
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index c18278c..fb8df2d 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -532,12 +532,8 @@ __pthread_create_2_1 (newthread, attr, start_routine, arg)
}
/* Check for valid priorities. */
- int minprio = INTERNAL_SYSCALL (sched_get_priority_min, scerr, 1,
- iattr->schedpolicy);
- int maxprio = INTERNAL_SYSCALL (sched_get_priority_max, scerr, 1,
- iattr->schedpolicy);
- if (pd->schedparam.sched_priority < minprio
- || pd->schedparam.sched_priority > maxprio)
+ if (check_sched_priority_attr (pd->schedparam.sched_priority,
+ iattr->schedpolicy))
{
/* Perhaps a thread wants to change the IDs and if waiting
for this stillborn thread. */
diff --git a/nptl/sysdeps/unix/sysv/linux/pthread_attr_setaffinity.c b/nptl/sysdeps/unix/sysv/linux/pthread_attr_setaffinity.c
index 8b7a499..880e1d5 100644
--- a/nptl/sysdeps/unix/sysv/linux/pthread_attr_setaffinity.c
+++ b/nptl/sysdeps/unix/sysv/linux/pthread_attr_setaffinity.c
@@ -25,9 +25,6 @@
#include <shlib-compat.h>
-/* Defined in pthread_setaffinity.c. */
-extern size_t __kernel_cpumask_size attribute_hidden;
-extern int __determine_cpumask_size (pid_t tid);
int
@@ -47,21 +44,10 @@ __pthread_attr_setaffinity_new (pthread_attr_t *attr, size_t cpusetsize,
}
else
{
- if (__kernel_cpumask_size == 0)
- {
- int res = __determine_cpumask_size (THREAD_SELF->tid);
- if (res != 0)
- /* Some serious problem. */
- return res;
- }
+ int ret;
- /* Check whether the new bitmask has any bit set beyond the
- last one the kernel accepts. */
- for (size_t cnt = __kernel_cpumask_size; cnt < cpusetsize; ++cnt)
- if (((char *) cpuset)[cnt] != '\0')
- /* Found a nonzero byte. This means the user request cannot be
- fulfilled. */
- return EINVAL;
+ if ((ret = check_cpuset_attr (cpuset, cpusetsize)) != 0)
+ return ret;
if (iattr->cpusetsize != cpusetsize)
{
-----------------------------------------------------------------------
hooks/post-receive
--
GNU C Library master sources